Re: [webdriver] how do I take a screenshot when doing parallel test with web driver ?

137 views
Skip to first unread message

Krishnan Mahadevan

unread,
Nov 12, 2012, 6:12:42 AM11/12/12
to webd...@googlegroups.com
This should help you out : http://darrellgrainger.blogspot.ca/2011/02/generating-screen-capture-on-exception.html

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/


On Thu, Nov 8, 2012 at 4:15 AM, Apha <amogh...@gmail.com> wrote:
How do i take a screenshot of parallel running web drivers tests ? I can't define webdriver as static when I'm running parallel. Every test will have it's own instance how will I know which test failed? any suggestions 

my code goes like this 

public class WebDriverTest {

public WebDriver webDriver;

public void setUpProperties(String seleniumHostAddress, int seleniumPort,

String browser, String appHost, String dbDriver,

String url, String userName, String password, String busDbUrl, String busUserName,

String busPassword)

throws Exception {


DesiredCapabilities desiredCapabilities = null;

if (browser.equalsIgnoreCase("*firefox")) {

desiredCapabilities = DesiredCapabilities.firefox();

}


else if (browser.equalsIgnoreCase("*chrome")) {

desiredCapabilities = DesiredCapabilities.chrome();

}


else if (browser.equalsIgnoreCase("*iexplore")) {

desiredCapabilities = DesiredCapabilities.internetExplorer();

}

stdout.print("http://" + seleniumHostAddress + ":" + seleniumPort + "/srm");

webDriver = new RemoteWebDriver(new URL("http://" + seleniumHostAddress + ":" + seleniumPort + "/wd/hub"), desiredCapabilities);

webDriver.get(appHost);

webDriver.manage().timeouts().implicitlyWait(500, TimeUnit.MILLISECONDS);

}

}


Thanks

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/CbNZfkuPXa0J.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

darrell

unread,
Nov 12, 2012, 9:44:26 AM11/12/12
to webd...@googlegroups.com
After you look at the post Krishnan has suggested you will see it shows you have to create ONE WebDriver which has an event listener. If you want to create multiple WebDrivers then you need to create multiple EventFiringWebDrivers. If you have a loop which creates multiple WebDriver instances then change it to a loop which creates multiple EventFiringWebDriver instances PLUS have a static counter. After each new EventFiringWebDriver, increment the counter. From within the WebDriverEventListener, store the current counter. This way you end up with each event listener having a different counter. You can then use the counter variable as part of the snapshot name. So if the snapshot is name "foo-inst1.jpg" you know that WebDriver number one caused the snapshot.

Darrell

Apha

unread,
Nov 12, 2012, 11:04:38 AM11/12/12
to webd...@googlegroups.com
Thanks I implemented using ThreadLocal so that I have seperate instances of webdriver and take a screenshot

Mark Collin

unread,
Nov 13, 2012, 6:29:13 PM11/13/12
to webd...@googlegroups.com

I updated my Selenium maven template today to use TestNG (as it seems to be what all the cool kids are using) and added in a screenshot listener that will take a screenshot if the test fails.

 

It’s also on its way to being configured to use multiple threading at method level:

 

https://github.com/Ardesco/Selenium-Maven-Template

 

enjoy J

--

Reply all
Reply to author
Forward
0 new messages