sebarmeli
unread,Jun 15, 2011, 11:15:27 PM6/15/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to testng-users
Hi there,
I'm using Selenium 2 in my test cases and I've got a TestBase class
with an init method like this;
protected WebDriver webDriver;
protected Page page;
@BeforeClass
public void init()
{
webDriver = ... //get the WebDriver
page= PageFactory.initElements(webDriver, Page.class);
}
and few test classes extending this base class.
All god, I just want to taking screenshots in case that test methods
fails.
I've got the ScreenshotOnFailureListener that implements
IInvokedMethodListener and I registered it in testng.xml file. This is
the content of the class:
@Override
public void afterInvocation(IInvokedMethod method, ITestResult
result)
{
if (!result.isSuccess()) {
File f = ((TakesScreenshot)
webDriver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(f, new File("target/surefire-
reports/UIIntegrationTests/screenshots/" +
method.getTestMethod().getMethodName()));
}
catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void beforeInvocation(IInvokedMethod arg0, ITestResult
arg1)
{
// TODO Auto-generated method stub
}
The class doesn't compile because "WebDriver" doesn't exist in this
context, I tried to set the variable as static but it doesn't seem
right (and debugging I get a null value in the listener).
Any help on that? Is there any better approach?
Cheers