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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30397043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 09:32:55  来源:igfitidea点击:

Selenium UnreachableBrowserException - "Could not start a new session" in SoapUI Groovy TestStep

javaseleniumgroovywebdriversoapui

提问by Maxim Romanyuk

I use SoapUI Pro 5.1.2 on Win7 x32, and try to connect to Selenium Webdriver in Groovy TestStep.

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

For this purpose I added selenium-standalone-server.jarv2.45.0 in $SOAP_HOME$\bin\extfolder.

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

My Groovy TestStep code:

我的 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()

When I try to run this step, SoapUI returns message:

当我尝试运行此步骤时,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

I tried to run this piece of code through the Netbeans IDE, after adding the same selenium-standalone-server.jarpackage to empty java project. And it has completed without problems!

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

This is error-log of soapUI:

这是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.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

I also tried use FirefoxDriver()instead of ChromeDriver(), and got the same error.

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

回答by Ivan Litskevich

It already told you what happened:

它已经告诉你发生了什么:

//got 'C:**\**Windows\system32\chromedriver.exe'

Try to define path using one of the next ways:

尝试使用以下方法之一定义路径:

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

OR

或者

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

Also, I would not recommend you to store chromedriver.exe in system32 folder, especially if you don't have admin rights on the workstation. Use smt like C:/WebDrivers/hromedriver.exe

另外,我不建议您将 chromedriver.exe 存储在 system32 文件夹中,特别是如果您没有工作站的管理员权限。像 C:/WebDrivers/hromedriver.exe 一样使用 smt

回答by Yash Jagdale

Download latest driver(chrome or IE) from seleniumhq.org, and use below code

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

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

This worked for me.

这对我有用。

回答by xjfengck

I have encountered the same error, which said:

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

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.

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

but chromedriver.exestarted fine. I can see it in task manager.

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

My environment is as following,

我的环境如下,

  • windows 7, ultimate, 64 bit system
  • selenium-server-standalone-2.47.1
  • chromedriver 2.19
  • google chrome: 45.0
  • Windows 7,终极版,64 位系统
  • selenium-server-standalone-2.47.1
  • 铬驱动程序 2.19
  • 谷歌浏览器:45.0

After many tries suggested in google results, my final solution is to add 127.0.0.1 localhostto C:\Windows\System32\drivers\etc\hosts.

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

Hope to help you!

希望能帮到你!

回答by albciff

In selenium this error message:

在 selenium 中,此错误消息:

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.

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

Could have a lot of causes. However looking at the stacktrace in this case is due to a NullPointerException:

可能有很多原因。但是,在这种情况下查看堆栈跟踪是由于NullPointerException

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)

The problem is that you're using selenium inside SOAPUI. SOAPUI seems to set the default proxy to null(ProxySelector.setDefault(null)). So when selenium gets the default proxy an invoke a method on it, a NullPointerExceptionis thrown.

问题是您在 SOAPUI 中使用了 selenium。SOAPUI 似乎将默认代理设置为null( ProxySelector.setDefault(null))。因此,当 selenium 获得默认代理并在其上调用一个方法时,NullPointerException会抛出 a。

The problem is that you executes your code inside SOAPUI so you can not get the default proxy before SOAPUI set it to null... then a possible workaround is in your Groovy testStep try to create a ProxySelectoran set it as default before WebDriveris executed:

问题是您在 SOAPUI 中执行您的代码,因此您无法在 SOAPUI 将其设置为 null 之前获得默认代理......然后可能的解决方法是在您的 Groovy testStep 中尝试创建一个ProxySelector设置为默认值,然后WebDriver执行:

import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import java.net.Proxy
import java.net.ProxySelector

def selectDirectProxy(URI uri) {
  final List<Proxy> proxy = new ArrayList<Proxy>()
  proxy.add(Proxy.NO_PROXY)
  return proxy
}

// create a ProxySelector
ProxySelector proxySelector = [ select : { uri->selectDirectProxy(uri) } ] as ProxySelector
// set as default to avoid null pointer
ProxySelector.setDefault(proxySelector);

// now it's safe to invoke WebDriver...
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()

In this example I extend the ProxySelectorabstract class in a groovy way, to set at least one direct proxy. If its necessary it's also possible to use the Proxyclass to configure a no direct proxy and set it in the list, but with this code I'm trying to avoid the NPEdue to SOAPUI ProxySelector.setDefault(null).

在这个例子中,我ProxySelector以一种常规的方式扩展了抽象类,以设置至少一个直接代理。如果有必要,也可以使用Proxy该类来配置无直接代理并将其设置在列表中,但使用此代码,我试图避免NPE由于 SOAPUI 引起的ProxySelector.setDefault(null)

回答by Santosh Pillai

This could be a compatibility issue between the 'selenium', 'chrome browser version' and 'chrome driver' version that you are using.

这可能是您使用的“selenium”、“chrome 浏览器版本”和“chrome 驱动程序”版本之间的兼容性问题。

It you are using Selenium 2.53 (like me), then using chrome driver 2.25 should work for you.

如果您使用的是 Selenium 2.53(像我一样),那么使用 chrome 驱动程序 2.25 应该适合您。

You can download it from here - https://chromedriver.storage.googleapis.com/index.html?path=2.25/

您可以从这里下载 - https://chromedriver.storage.googleapis.com/index.html?path=2.25/

回答by Dulith De Costa

I encountered the same issue and upgrading to the latest chrome driver fixed my issue.

我遇到了同样的问题,升级到最新的 chrome 驱动程序解决了我的问题。

You can download the latest chrome driver from following URL.

您可以从以下 URL 下载最新的 chrome 驱动程序。

http://chromedriver.storage.googleapis.com/index.html

http://chromedriver.storage.googleapis.com/index.html

It is best to use always the latest version. After downloading, set the path of chrome driver in System.setProperty("webdriver.chrome.driver","{Your path Chrome Driver}");

最好始终使用最新版本。下载后,在 System.setProperty("webdriver.chrome.driver","{你的路径 Chrome Driver}"); 中设置 chrome 驱动程序的路径;

    System.out.println("Creating Chrome Driver");
 // Set Chrome Driver
    System.setProperty("webdriver.chrome.driver", "D:\chromedriver.exe");

    WebDriver driver = new ChromeDriver();
    driver.get("{Your URL}");

回答by dos4dev

If someone encountered a similar problem on Ubuntu, please check if you install Chromiumweb browser enter image description here

如果有人在 Ubuntu 上遇到过类似的问题,请检查您是否安装了 Chrom ium网络浏览器在此处输入图片说明

Not enough to have only chrome browser.

只有 chrome 浏览器是不够的。

More details

更多细节