java - Selenium InternetExplorerDriver throws SessionNotFoundException on getScreenshotAs method -
i'm using iedriverserver (win-32 version) 2.40.0 (taken directly selenium downloads page), , seems work except taking screenshots - code intended taking screenshots on test failure, follows:
public statement apply(final statement statement, final description arg1) { return new statement() { @override public void evaluate() throws throwable { try { statement.evaluate(); } catch (throwable t) { capturescreenshot(arg1.tostring()); throw t; // rethrow allow failure reported junit } } public void capturescreenshot(string method) { try { driver = webdrivermanager.getdriverinstance(); new file(screenshotsbase).mkdirs(); // insure directory there date = new date(); string fn = screenshotsbase + method + now.gettime() + ".png"; file source = ((takesscreenshot)driver).getscreenshotas(outputtype.file); fileutils.copyfile(source, new file(fn)); } catch (exception e) { // no need crash tests if screenshot fails system.out.println(e); } } }; }
it works fine firefox driver, fails ie driver (throws exception , doesn't take screenshot). code instantiating iedriver is:
private static webdriver startiedriver() { file file = new file("c:\\workspace\\iedriver32\\iedriverserver.exe"); system.setproperty("webdriver.ie.driver", file.getabsolutepath()); desiredcapabilities capabilities = desiredcapabilities.internetexplorer(); // capabilities.setcapability(internetexplorerdriver.introduce_flakiness_by_ignoring_security_domains, true); capabilities.setcapability(capabilitytype.accept_ssl_certs,true); d = new internetexplorerdriver(capabilities); return d; }
i've removed "introduce_flakiness_by_ignoring_security_domains" code, following advice in http://jimevansmusic.blogspot.co.il/2012/08/youre-doing-it-wrong-protected-mode-and.html, , set "enable protected mode" true zones.
the error thrown is:
org.openqa.selenium.remote.sessionnotfoundexception: session 7018d7ae-e03a-4eb6-96a5-7bdf31eb4004 not exist command duration or timeout: 3 milliseconds build info: version: '2.39.0', revision: '14fa800511cc5d66d426e08b0b2ab926c7ed7398', time: '2013-12-16 13:18:38' system info: host: 'ayelet-pc', ip: '192.168.1.23', os.name: 'windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51' session id: 7018d7ae-e03a-4eb6-96a5-7bdf31eb4004 driver info: org.openqa.selenium.ie.internetexplorerdriver capabilities [{platform=windows, javascriptenabled=true, elementscrollbehavior=0, ignorezoomsetting=false, enablepersistenthover=true, ie.ensurecleansession=false, browsername=internet explorer, enableelementcachecleanup=true, unexpectedalertbehaviour=dismiss, version=11, ie.useperprocessproxy=false, cssselectorsenabled=true, ignoreprotectedmodesettings=false, requirewindowfocus=false, handlesalerts=true, initialbrowserurl=http://localhost:25063/, ie.forcecreateprocessapi=false, nativeevents=true, browserattachtimeout=0, ie.browsercommandlineswitches=, takesscreenshot=true}]
i've tried using syntax below, following advice on selenium page on remotewebdriver screenshots @ http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp-
webdriver augmenteddriver = new augmenter().augment(driver); file source = ((takesscreenshot)augmenteddriver).getscreenshotas(outputtype.file);
but fails exception
net.sf.cglib.core.codegenerationexception: java.lang.illegalaccessexception-->class org.openqa.selenium.remote.augmenter$compoundhandler can not access member of class org.openqa.selenium.ie.internetexplorerdriver modifiers "protected"
and seems "augmenter" not meant work iedriver.
any clues on how selenium iedriver take screenshots or might causing problem welcome.
i've found problem, , may expected, not within iedriver. don't know why worked seamlessly firefoxdriver, made me suspect driver, anyway.
some more debugging revealed driver instance getting "close" event before screenshot test rule called, naturally makes lose session.
it seems because had driver start/stop @ "@before" , "@after" annotations, work correctly screenshot test rule (the code in question) - defined
@rule public screenshottestrule screenshottestrule = new screenshottestrule();
i should have instead place starting , stopping of driver @ @beforeclass , @afterclass annotations.
thanks everyone, , hope helps whoever finds in future.
Comments
Post a Comment