Selenium UnachableBrowserException - SoapUI Groovy TestStep 中的“无法启动新会话”

2022-09-04 08:15:38

我在Win7 x32上使用SoapUI Pro 5.1.2,并尝试在Groovy TestStep中连接到Selenium Webdriver。

为此,我在文件夹中添加了v2.45.0。selenium-standalone-server.jar$SOAP_HOME$\bin\ext

我的 Groovy TestStep 代码:

import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver

System.setProperty('webdriver.chrome.driver', 'C:\\\\Windows\\system32\\chromedriver.exe')
log.info(System.getProperty('webdriver.chrome.driver')) //got 'C:\\Windows\system32\chromedriver.exe'

WebDriver driver = new ChromeDriver() // this line causes error

driver.get('http://google.com')
driver.quit()

当我尝试运行此步骤时,SoapUI 返回消息:

org.openqa.selenium.remote.UnreachableBrowserException: 
Could not start a new session. 
Possible causes are invalid address of the remote server or browser start-up failure. 
Build info: 
    version: '2.45.0', 
    revision: '5017cb8', 
    time: '2015-02-26 23:59:50' 
System info: 
    host: 'SmithPC', 
    ip: '10.0.2.15', 
    os.name: 'Windows 7', 
    os.arch: 'x86', 
    os.version: '6.1', 
    java.version: '1.8.0_45' 
Driver info: 
    driver.version: ChromeDriver 
error at line: 7

在将相同的包添加到空的java项目之后,我试图通过Netbeans IDE运行这段代码。而且它已经完成了没有问题!selenium-standalone-server.jar

这是 soapUI 的错误日志:

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'SmithPC', ip: '10.0.2.15', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_45'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:139)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:171)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:160)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:117)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:186)
    at Script3.run(Script3.groovy:7)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
    at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:79)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:138)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at org.apache.http.impl.conn.SystemDefaultRoutePlanner.determineProxy(SystemDefaultRoutePlanner.java:79)
    at org.apache.http.impl.conn.DefaultRoutePlanner.determineRoute(DefaultRoutePlanner.java:77)
    at org.apache.http.impl.client.InternalHttpClient.determineRoute(InternalHttpClient.java:124)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:183)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:126)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:72)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:133)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:66)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
    ... 23 more

我也尝试使用而不是 ,并得到了同样的错误。FirefoxDriver()ChromeDriver()


答案 1

我遇到了同样的错误,它说:

org.openqa.selenium.remote.UnreachableBrowserException: 无法启动新会话。可能的原因是远程服务器的地址无效或浏览器启动失败。

但开始很好。我可以在任务管理器中看到它。chromedriver.exe

我的环境如下:

  • 视窗 7,终极,64 位系统
  • 硒-服务器-独立-2.47.1
  • 铬驱动程序 2.19
  • 谷歌浏览器: 45.0

在Google结果中建议多次尝试后,我的最终解决方案是添加到.127.0.0.1 localhostC:\Windows\System32\drivers\etc\hosts

希望对您有所帮助!


答案 2

从 seleniumhq.org 下载最新的驱动程序(chrome或IE),并使用以下代码

    System.setProperty("webdriver.chrome.driver","<YourPath>chromedriver.exe");
    WebDriver driver=new ChromeDriver();
    driver.get("http://www.yahoo.com");

这对我有用。


推荐