2

I got a problem. I run a SoapUI web service test through my Java automation code. But After that. Selenium doesn't work. It seems soapUI part not actually done. But I'm not sure.

public static void main(String[] args) throws Exception {
    SoapUIRun srun = new SoapUIRun();
    srun.runTestCase("CPIHS", "CPIHS");
    new MainPage().LoginCad();
}

The exception msg is :

Exception in thread "main" 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.52.0', revision: '4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11 11:22:43'
System info: host: 'GFG-GROUP153', ip: '10.100.1.7', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_102'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:170)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:159)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
    at screens.MainPage.LoginCad(MainPage.java:28)
    at screens.MainPage.main(MainPage.java:87)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

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:144)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:90)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
    ... 13 more

However is I comment out SoapUI part. It will work again. Like:

public static void main(String[] args) throws Exception {
    //SoapUIRun srun = new SoapUIRun();
    //srun.runTestCase("CPIHS", "CPIHS");
    new MainPage().LoginCad();
}

Here is my SoapUI method:

public void runTestCase(String tarSuite, String tarCase) throws Exception {

    String reportStr = "";

    TestRunner runner;

    SoapUI.setSoapUICore(new StandaloneSoapUICore(true));

    WsdlProject project = new WsdlProject("C:\\Users\\tshi\\Documents\\Maven Projects\\ASORT\\WebServiceResource\\Suncorp_Issuing-soapui-project.xml");

    List<TestSuite> suiteList = project.getTestSuiteList();

    for (TestSuite aSuiteList : suiteList) {

        String suiteName = aSuiteList.getName();

        List<TestCase> caseList = aSuiteList.getTestCaseList();
        //System.out.println("Test Suite: " + suiteName);

        if (suiteName.equals(tarSuite)) {

            for (TestCase aCaseList : caseList) {

                String caseName = aCaseList.getName();
                //System.out.println("Test Case: " + caseName);

                if (caseName.equals(tarCase)) {

                    long startTime = System.currentTimeMillis();

                    runner = project.getTestSuiteByName(suiteName).getTestCaseByName(caseName).run(new PropertiesMap(), false);

                    long duration = System.currentTimeMillis() - startTime;

                    reportStr = reportStr + "\n\tTestCase: " + aCaseList.getName() + "\tStatus: " + runner.getStatus() + "\tReason: " + runner.getReason() + "\tDuration: " + duration;

                    System.out.print(reportStr);

                }

            }

        }

    }

}

Here is Selenium related method:

public void LoginCad(){
    System.setProperty("webdriver.chrome.bin", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
    System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");

    String bank = Integer.toString(48);
    String emp = Integer.toString(200003);
    String pwd = "Cadencie1";
    String baseUrl = "http://172.16.1.133:8090/AppName/servlet/app";

    driver = new ChromeDriver();

    driver.get(baseUrl);

    try {

        Thread.sleep(1000);

    } catch(InterruptedException e){

        // TO DO Auto-generated catch block
        e.printStackTrace();

    }

    Utilities.switchToWindow("AppName - User Logon [LOGON]", driver);

    try{

        Thread.sleep(2000);

    } catch(InterruptedException e){

        // TO DO Auto-generated catch block
        e.printStackTrace();

    }

    driver.findElement(By.id("idBANK")).clear();
    driver.findElement(By.id("idBANK")).sendKeys(bank);

    driver.findElement(By.id("idEMPLOYEE")).clear();
    driver.findElement(By.id("idEMPLOYEE")).sendKeys(emp);

    driver.findElement(By.id("idPASSWORD")).clear();
    driver.findElement(By.id("idPASSWORD")).sendKeys(pwd);

    driver.findElement(By.id("maintLOGON")).click();

    driver.findElement(By.id("idPASSWORD")).clear();
    driver.findElement(By.id("idPASSWORD")).sendKeys(pwd);

    driver.findElement(By.id("maint")).click();

}

Anyone has any idea why this happen. I searched on google. But it seems nobody gets same error in the same situation. Thank you very much.

Shi Tim
  • 423
  • 2
  • 5
  • 18
  • Please see if [this](http://stackoverflow.com/questions/30397043/selenium-unreachablebrowserexception-could-not-start-a-new-session-in-soapui) thread helps. – Rao Sep 09 '16 at 05:04
  • Thanks for your reply. Unfortunately, they are not working. – Shi Tim Sep 09 '16 at 05:24
  • Have you tried to turn it off and on again? Reinstall all off those involved programs and see if that will solve this issue. – Krzysztof Cichocki Sep 09 '16 at 05:30

2 Answers2

1

If the problem only happens with selenium after SOAPUI execution then probably some SOAPUI configuration is causing the issue. The issue is probably due because SOAPUI is setting the default proxy to null, then when selenium try to gets the proxy to check the configuration receive the NullPointerExcetpion.

Based on you error trace:

Caused by: java.lang.NullPointerException 
at org.apache.http.impl.conn.SystemDefaultRoutePlanner.determineProxy(SystemDefaultRoutePlanner.java:79) 

If you take a look at the source code of org.apache.http.impl.conn.SystemDefaultRoutePlanner class:

(Note I keep the line number to correlates with your error trace)

53 public class More ...SystemDefaultRoutePlanner extends DefaultRoutePlanner {
54 
55     private final ProxySelector proxySelector;
56 
57     public More ...SystemDefaultRoutePlanner(
58             final SchemePortResolver schemePortResolver,
59             final ProxySelector proxySelector) {
60         super(schemePortResolver);
         /*
           proxySelector ARE NULL AND ProxySelector.getDefault(); 
           RETURNS ALSO NULL DUE THAT SOAPUI PROBABLY MAKE BEFORE
           ProxySelect.setDefault(null);
         */
61         this.proxySelector = proxySelector != null ? proxySelector : ProxySelector.getDefault();
62     }
63 
64     public More ...SystemDefaultRoutePlanner(final ProxySelector proxySelector) {
65         this(null, proxySelector);
66     }
67 
68     @Override
69     protected HttpHost More ...determineProxy(
70             final HttpHost    target,
71             final HttpRequest request,
72             final HttpContext context) throws HttpException {
73         final URI targetURI;
74         try {
75             targetURI = new URI(target.toURI());
76         } catch (final URISyntaxException ex) {
77             throw new HttpException("Cannot convert host to URI: " + target, ex);
78         }
           /* HERE IS THE NULLPOINTER */
79         final List<Proxy> proxies = this.proxySelector.select(targetURI);

Workaround

So a possible solution is to take care of the ProxySelect yourself. Then you can try with the follow workaround:

import java.net.ProxySelector;
...

public static void main(String[] args) throws Exception {

    // get default proxy before soapui will set it to null
    ProxySelector proxy = ProxySelector.getDefault();

    SoapUIRun srun = new SoapUIRun();
    srun.runTestCase("CPIHS", "CPIHS");

    // set it again to avoid NPE on selenium
    ProxySelector.setDefault(proxy);

    new MainPage().LoginCad();
}
albciff
  • 18,112
  • 4
  • 64
  • 89
0

Thank you @albciff for your workaround, but it didnt help in my case. I have finally created new Proxy:

report.step("Verify 'proxySelector' not NULL");
ProxySelector proxy = ProxySelector.getDefault();
if (proxy == null) {
    //Creating new Proxy
    ProxySelector proxySelector = new ProxySelector() {
        @Override
        public List<Proxy> select(URI uri) {
            return new ArrayList<Proxy>(){{
                add(Proxy.NO_PROXY);
            }};
        }

        @Override
        public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
        }
    };

    report.report("Set new proxySelector (Proxy.NO_PROXY)", Reporter.WARNING);
    ProxySelector.setDefault(proxySelector);

}else{
    report.report("Proxy is not NULL continue..");
}
nby
  • 89
  • 5