2014-03-19 17 views
0

我的代碼開始硒如下:異常與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你幫我嗎?

+0

這個解釋可能是在stacktrace的「由...引起」鏈中......你沒有向我們顯示。 –

+0

@StephenC我加了一個更完整的堆棧跟蹤 –

回答

1

確保Firefox安裝在默認位置。可選的,你可以給的絕對路徑瀏覽器:

String browserString = "c:\\program files\\mozilla firefox\\firefox.exe"; 

Check the source and documentation以獲取更多信息。

但是,如果您不想提供Selenium RC,我建議使用驅動程序(如在工作示例中)。

0

望着source code of the DefaultSelenium class,你可以注意到alloweb瀏覽器字符串是:

  • *webdriver
  • *firefox-wd
  • *iexplore-wd

所以我寫了:

String browserString= "*firefox-wd"; 

而且解決了這個問題。