2014-03-19 15 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"; 

而且解决了这个问题。