I am currently capturing screenshots on failure and success in TestNG by way of overriding the TestListenerAdapter methods onTestFailure, and onTestSuccess respectively. In order to do this you need to specify which driver you want to take a screenshot of.
My question: Is there a good way to capture screenshots when running tests in parallel on the method level?
In order to run tests in parallel, each individual test needs a unique driver instance. So, at any given instance you have x number of driver instances running. When it comes time to capture a screenshot, how do you determine which driver to use?
This question is also posted on stackoverflow here, http://stackoverflow.com/questions/12481972/capture-webdriver-screenshots-when-running-parallel-tests-with-testng
Code snippets:
public class OnFailureListener extends TestListenerAdapter { @Override public void onTestFailure(ITestResult tr) { Screenshots.captureScreenshot(tr); super.onTestFailure(tr); }--public static void captureScreenshot(ITestResult tr) { WebDriver driver = TestClass.driver; if (driver instanceof TakesScreenshot) { String filename = "path/to/screenshot/file"; try { File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File(filename)); } catch (IOException e) { e.printStackTrace(); } }
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/okk2NYruNqsJ.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Hi Herik,Have you got it working?Are you gracious enough to share the code please?Thanks