SoapUI项目执行后的WebDriver异常

时间:2015-03-03 03:07:14

标签: java selenium soap soapui

请帮助解决以下问题。

我正在使用Eclipse.My主类调用下面的类/ java文件。

1)Invoke_SoapUI_Project.java(这会执行SOAP UI项目) 2)Run_Selenium_Script.java(这会打开Firefox中的一个URL)。

我的main函数调用上面的Invoke_SoapUI_Project.java并触发“SOAP UI XML Project”的执行,运行良好。

然后我的第二个函数“Run_Selenium_Script.java”调用并尝试打开网页。但在我定义webdriver对象的行处得到以下错误。即driver= new firefoxDriver();

但是,如果我评论Invoke_SoapUI_Project.java,那么我将不会得到异常,firefox对象正确创建并打开我的URL。

我得到以下异常:

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.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
System info: host: 'BDC8-L-HP26ZR1', ip: '127.0.0.1', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_31'
Driver info: driver.version: FirefoxDriver
    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.firefox.FirefoxDriver.<init>(FirefoxDriver.java:191)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:99)
    at Services.CommonFunctions.setUp(CommonFunctions.java:1481)
    at Services.CommonFunctions.obj_run(CommonFunctions.java:1631)
    at Services.CSS_Validation_a.print(CSS_Validation_a.java:283)
    at Services.CSS_main.main(CSS_main.java:67)
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:76)
    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:72)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
    at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:215)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
    at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
    ... 10 more

3 个答案:

答案 0 :(得分:2)

我们偶然发现了同样的问题(花了我们很长时间),但我们设法解决了这个问题:

问题似乎是SoapUI将默认的proxyselector设置为null,而Apache httpclient并不期望这样。

重现问题:

WsdlProject wsdlProject = new WsdlProject("");
WebDriver driver = new FirefoxDriver();

解决方法:

ProxySelector proxy = ProxySelector.getDefault();
WsdlProject wsdlProject = new WsdlProject("");
ProxySelector.setDefault(proxy);
WebDriver driver = new FirefoxDriver();
两天前,peidong-hu发送了一个独立补丁(从那里拿出解决方案): https://github.com/Ardesco/selenium-standalone-server-plugin/issues/23

我已经为selenium提交了错误报告,会使用以下详细信息对其进行更新:https://github.com/SeleniumHQ/selenium/issues/388

我也要为SoapUI提交一份报告。

答案 1 :(得分:0)

根据link

您需要设置firefox驱动程序并将其作为系统属性提供。 例如: System.setProperty("webdriver.firefox.driver", "c:/webdriver/firefoxdriverpath");

答案 2 :(得分:0)

我在使用SoapUI 5时也发现了这个问题。我检查了源代码。 在课程ProxyUtils中,如果您未设置代理或将代理设置为自动,则setGlobalProxy()方法会将proxySelector设置为空。

 public static void setGlobalProxy( Settings settings )
    {
    ProxySelector proxySelector = null;
    ProxySettingsAuthenticator authenticator = null;
    if( proxyEnabled )
    {
        if( autoProxy )
        {
        proxySelector = new ProxyVoleUtil().createAutoProxySearch().getProxySelector();
        }
        else
        {
            proxySelector = getManualProxySelector( settings );
        }
        if( proxySelector != null )
        {
            // Don't register any proxies for other schemes
            proxySelector = filterHttpHttpsProxy( proxySelector );
        }
        authenticator = new ProxySettingsAuthenticator();
    }
    *ProxySelector.setDefault( proxySelector );*
    Authenticator.setDefault( authenticator );
    HttpClientSupport.setProxySelector( proxySelector );
    HttpClientSupport.getHttpClient().setCredentialsProvider( getProxyCredentials( settings ) );
    }

在Windows操作系统中,proxySelector = new ProxyVoleUtil().createAutoProxySearch().getProxySelector();也将为空。

 if (PlatformUtil.getCurrentPlattform() != PlatformUtil.Platform.WIN) {
            proxySearch.addStrategy(ProxySearch.Strategy.BROWSER);
            // For Windows both BROWSER and OS_DEFAULT will end up with an IEProxySearchStrategy.
            // The call in createPacSelector to winHttpDetectAutoProxyConfigUrl is quite slow and we don't want to do it twice.
        }

我的解决方案是修改ProxyUtils类。将ProxySelector.setDefault( proxySelector );更改为

    if(proxySelector != null){
        ProxySelector.setDefault(proxySelector);
    }
    else{
        proxySelector = ProxySelector.getDefault();
    }

然后我使用自己的ProxyUtils.class,通过WinRAR或7Z更新ProxyUtils.classsoapui-xxx.jar)中的SOAPUI_HOME\bin\。现在我的SoapUI工作得非常好。