我的代碼開始硒如下:異常與Firefox網頁司機
startServer();
Integer port = 4545;
String browserString= "*firefox";
selenium = new DefaultSelenium("localhost",port,browserString, url) {
public void open(String url) { commandProcessor.doCommand("open", new String[] {url,"true"});};
};
logger.info("Start Selenium ");
selenium.start(); // <------ SeleniumException here
logger.info("Selenium started");
,我得到的是堆棧跟蹤:
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:109)
at com.example.test.infrastruttura.util.SeleniumHolder.initAll(SeleniumHolder.java:55)
at com.example.test.infrastruttura.util.SeleniumHolder.<init>(SeleniumHolder.java:23)
at com.example.test.infrastruttura.util.SeleniumHolder.createInstance(SeleniumHolder.java:43)
at com.example.test.infrastruttura.util.SeleniumHolder.getInstance(SeleniumHolder.java:28)
at com.example.test.infrastruttura.util.SgateSeleneseTestCase.setUp(SgateSeleneseTestCase.java:38)
at com.example.sgate.test.selenium.GenericLogin.executeNavigation(GenericLogin.java:18)
at com.example.test.infrastruttura.checks.CheckObject.executeSelenium(CheckObject.java:424)
at com.example.test.infrastruttura.MainTestCase.executeNode(MainTestCase.java:312)
at com.example.test.infrastruttura.MainTestCase.execute(MainTestCase.java:244)
at com.example.test.infrastruttura.MainTestCase.execute(MainTestCase.java:157)
at com.example.sgate.test.functional.verificaEsitiAnagrafici.VerificaEsitiAnagrafici019AltroUtenteStessoComune.testComune(VerificaEsitiAnagrafici019AltroUtenteStessoComune.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:96)
at org.apache.maven.surefire.junit.JUnit3Provider.executeTestSet(JUnit3Provider.java:117)
at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: com.thoughtworks.selenium.SeleniumException: Failed to start new browser session: Error while launching browser
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:109)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:103)
at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:272)
at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:234)
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:100)
... 39 more
我用硒的Java-2.40.0和Firefox 26 。
但是,下面的代碼工作:
WebDriver driver = new FirefoxDriver();
driver.get("http://myhostname:myport/myapplicationname");
WebElement userId = driver.findElement(By.name("userId"));
userId.sendKeys("coolusername");
WebElement password = driver.findElement(By.name("password"));
password.sendKeys("ultrasecretpassword");
password.submit();
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
所以這不是Selenium版本與Firefox兼容的問題。
硒試圖在這個網址找到一些的servlet:
http://localhost:4545/selenium-server/driver/
但收到一個404錯誤。
Ca你幫我嗎?
這個解釋可能是在stacktrace的「由...引起」鏈中......你沒有向我們顯示。 –
@StephenC我加了一個更完整的堆棧跟蹤 –