I use SoapUI Pro 5.1.2 on Win7 x32, and try to connect to Selenium Webdriver in Groovy TestStep.
For this purpose I added selenium-standalone-server.jar
In selenium this error message:
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.
Could have a lot of causes. However looking at the stacktrace in this case is due to a 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 NullPointerException
is thrown.
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 ProxySelector
an set it as default before WebDriver
is executed:
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 ProxySelector
abstract class in a groovy way, to set at least one direct proxy. If its necessary it's also possible to use the Proxy
class to configure a no direct proxy and set it in the list, but with this code I'm trying to avoid the NPE
due to SOAPUI ProxySelector.setDefault(null)
.