How to implement PhantomJS with Selenium WebDriver using java -
i'm going mad, really. have code:
public class creazione extends testcase { private phantomjsdriver driver; private string baseurl; private boolean acceptnextalert = true; private stringbuffer verificationerrors = new stringbuffer(); @before public void setup() throws exception { file file = new file("c:/program files/phantomjs-1.9.7-windows/phantomjs.exe"); system.setproperty("phantomjs.binary.path", file.getabsolutepath()); driver = new phantomjsdriver(); baseurl = "http://www.gts.fiorentina.test/"; driver.manage().timeouts().implicitlywait(30, timeunit.seconds); driver.get(baseurl + "/account/login.aspx?returnurl=%2f"); finddynamicelement(by.id("tbusername_i"), 2000); driver.findelement(by.id("tbusername_i")).clear(); driver.findelement(by.id("tbusername_i")).sendkeys("rogai"); driver.findelement(by.id("tbpassword_i")).clear(); driver.findelement(by.id("tbpassword_i")).sendkeys("fiorentina2014!"); driver.findelement(by.id("btnlogin_cd")).click(); driver.manage().timeouts().implicitlywait(30, timeunit.seconds); } @test public void testcreazione() throws exception { driver.get(baseurl + "/segreteriasportiva/calciatori.aspx"); finddynamicelement(by.cssselector("#aspxbutton1_cd > span"), 2000); driver.findelement(by.cssselector("#aspxbutton1_cd > span")).click(); finddynamicelement(by.id("frmedit_ts_tipopersonaid_fk_b-1"), 2000); driver.findelement(by.id("frmedit_ts_tipopersonaid_fk_b-1")).click(); driver.findelement(by.id("frmedit_ts_tipopersonaid_fk_ddd_l_lbi2t0")).click(); driver.findelement(by.id("frmedit_nome_i")).clear(); driver.findelement(by.id("frmedit_nome_i")).sendkeys("prova"); driver.findelement(by.id("frmedit_cognome_i")).clear(); driver.findelement(by.id("frmedit_cognome_i")).sendkeys("calciatore"); driver.findelement(by.id("frmedit_ts_ruoloid_fk_b-1")).click(); driver.findelement(by.id("frmedit_ts_ruoloid_fk_ddd_l_lbi3t0")).click(); driver.findelement(by.id("frmedit_datanascita_i")).clear(); driver.findelement(by.id("frmedit_datanascita_i")).sendkeys("01/01/2014"); driver.findelement(by.id("frmedit_cittadinanza_i")).clear(); driver.findelement(by.id("frmedit_cittadinanza_i")).sendkeys("italiana"); driver.findelement(by.id("frmedit_luogonascita_i")).clear(); driver.findelement(by.id("frmedit_luogonascita_i")).sendkeys("roma"); driver.findelement(by.cssselector("#btn_edit_cd > span")).click(); driver.findelement(by.id("grid_dxfreditorcol3_i")).click(); driver.findelement(by.id("grid_dxfreditorcol3_i")).sendkeys("prova"); assertequals("prova",driver.findelement(by.xpath("//tr[@id='grid_dxdatarow0']/td[3]")).gettext()); } }
after execution these errors during runtime, following trace ---
org.openqa.selenium.invalidelementstateexception: {"errormessage":"element not interactable , may not manipulated","request":{"headers":{"accept-encoding":"gzip,deflate","connection":"keep-alive","content-length":"27","content-type":"application/json; charset=utf-8","host":"localhost:20497","user-agent":"apache-httpclient/4.3.2 (java 1.5)"},"httpversion":"1.1","method":"post","post":"{\"id\":\":wdc:1402393987914\"}","url":"/clear","urlparsed":{"anchor":"","query":"","file":"clear","directory":"/","path":"/clear","relative":"/clear","port":"","host":"","password":"","user":"","userinfo":"","authority":"","protocol":"","source":"/clear","querykey":{},"chunks":["clear"]},"urloriginal":"/session/e4b71580-f084-11e3-959e-273aa801dd81/element/%3awdc%3a1402393987914/clear"}} command duration or timeout: 215 milliseconds build info: version: '2.42.1', revision: '68b415a', time: '2014-05-29 16:17:18' system info: host: 'silvio-acer', ip: '10.10.1.122', os.name: 'windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_55' session id: e4b71580-f084-11e3-959e-273aa801dd81 driver info: org.openqa.selenium.phantomjs.phantomjsdriver capabilities [{platform=xp, acceptsslcerts=false, javascriptenabled=true, browsername=phantomjs, rotatable=false, driverversion=1.1.0, locationcontextenabled=false, version=1.9.7, cssselectorsenabled=true, databaseenabled=false, handlesalerts=false, browserconnectionenabled=false, webstorageenabled=false, nativeevents=true, proxy={proxytype=direct}, applicationcacheenabled=false, drivername=ghostdriver, takesscreenshot=true}] @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ org.openqa.selenium.remote.errorhandler.createthrowable(errorhandler.java:204) @ org.openqa.selenium.remote.errorhandler.throwifresponsefailed(errorhandler.java:156) @ org.openqa.selenium.remote.remotewebdriver.execute(remotewebdriver.java:600) @ org.openqa.selenium.remote.remotewebelement.execute(remotewebelement.java:268) @ org.openqa.selenium.remote.remotewebelement.clear(remotewebelement.java:113) @ com.example.tests.creazione.testcreazione(creazione.java:59) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ junit.framework.testcase.runtest(testcase.java:176) @ junit.framework.testcase.runbare(testcase.java:141) @ junit.framework.testresult$1.protect(testresult.java:122) @ junit.framework.testresult.runprotected(testresult.java:142) @ junit.framework.testresult.run(testresult.java:125) @ junit.framework.testcase.run(testcase.java:129) @ junit.framework.testsuite.runtest(testsuite.java:255) @ junit.framework.testsuite.run(testsuite.java:250) @ org.junit.internal.runners.junit38classrunner.run(junit38classrunner.java:84) @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:50) @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:467) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:683) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:390) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:197) caused by: org.openqa.selenium.remote.screenshotexception: screen shot has been taken build info: version: '2.42.1', revision: '68b415a', time: '2014-05-29 16:17:18' system info: host: 'silvio-acer', ip: '10.10.1.122', os.name: 'windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_55' driver info: driver.version: remotewebdriver @ org.openqa.selenium.remote.errorhandler.throwifresponsefailed(errorhandler.java:136) ... 23 more caused by: org.openqa.selenium.remote.errorhandler$unknownserverexception: {"errormessage":"element not interactable , may not manipulated","request":{"headers":{"accept-encoding":"gzip,deflate","connection":"keep-alive","content-length":"27","content-type":"application/json; charset=utf-8","host":"localhost:20497","user-agent":"apache-httpclient/4.3.2 (java 1.5)"},"httpversion":"1n.1","method":"post","post":"{\"id\":\":wdc:1402393987914\"}","url":"/clear","urlparsed":{"anchor":"","query":"","file":"clear","directory":"/","path":"/clear","relative":"/clear","port":"","host":"","password":"","user":"","userinfo":"","authority":"","protocol":"","source":"/clear","querykey":{},"chunks":["clear"]},"urloriginal":"/session/e4b71580-f084-11e3-959e-273aa801dd81/element/%3awdc%3a1402393987914/clear"}} build info: version: '2.42.1', revision: '68b415a', time: '2014-05-29 16:17:18' system info: host: 'silvio-acer', ip: '10.10.1.122', os.name: 'windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_55' driver info: driver.version: unknow
i have added phantomjs.exe windows path, added external library ghostdriver.jar, nothing...
it's 2 days i'm trying make work...
try this, worked me
desiredcapabilities caps = new desiredcapabilities(); caps.setjavascriptenabled(true); caps.setcapability("takesscreenshot", true); caps.setcapability( phantomjsdriverservice.phantomjs_executable_path_property, "your custom path\\phantomjs.exe" ); webdriver driver = new phantomjsdriver(caps);
then rest of them similar..and pls kindly comment observation ,have great day :)
Comments
Post a Comment