Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><sub>Note.- This answer could be outdated. The answer is based on Selenium 2.15</sub></p> <p>Using <a href="http://kentbeck.github.com/junit/javadoc/latest/index.html?org/junit/rules/TestWatcher.html">TestWatcher</a> does the trick (the unit test must extend following <code>BaseTest</code>):</p> <pre class="lang-java prettyprint-override"><code>public abstract class BaseTest { // ... protected WebDriver driver; @Rule public TestRule testWatcher = new TestWatcher() { @Override public void starting(Description desc) { LOG.info("Launching browser..."); driver = Utils.getFirefoxDriver(); } @Override public void finished(Description desc) { LOG.info("Quitting driver..."); driver.quit(); } @Override public void failed(Throwable e, Description d) { LOG.debug("Creating screenshot..."); File scrFile = ((TakesScreenshot) driver).getScreenshotAs( OutputType.FILE); String scrFilename = "Screenshot.png"; File outputFile = new File(SCREEN_SHOTS_RESULTS_PATH, scrFilename); LOG.info(scrFilename + " screenshot created."); try { org.​apache.​commons.​io.FileUtils.copyFile(scrFile, outputFile); } catch (IOException ioe) { LOG.error("Error copying screenshot after exception.", ioe); } } }; } </code></pre> <hr> <h3>Note</h3> <p><code>Utils.getFirefoxDriver()</code> returns a customized <code>WebDriver</code>. Something like:</p> <pre class="lang-java prettyprint-override"><code>import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxBinary; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; public class Utils { // ... public static WebDriver getFirefoxDriver() { FirefoxProfile firefoxProfile = new FirefoxProfile(); // Profile customization. For example: // firefoxProfile.addExtension("firebug-1.8.4-fx.xpi"); // firefoxProfile.setPreference("extensions.firebug.currentVersion","1.8.4"); FirefoxBinary firefox = new FirefoxBinary(); // Firefox customization. For example: // firefox.setEnvironmentProperty("DISPLAY", display); WebDriver driver = new FirefoxDriver(firefox, firefoxProfile); // WebDriver customizations. For example: // driver.manage().timeouts().implicitlyWait(SHORT_TIMEOUT_S, TimeUnit.SECONDS); return driver; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload