![](/img/trans.png)
[英]Selenium UnreachableBrowserException - "Could not start a new session" in SoapUI Groovy TestStep
[英]After run a SoapUI, could not start selenium
我有问题。 我通过 Java 自动化代码运行 SoapUI Web 服务测试。 但在那之后。 硒不起作用。 似乎soapUI 部分实际上没有完成。 但我不确定。
public static void main(String[] args) throws Exception {
SoapUIRun srun = new SoapUIRun();
srun.runTestCase("CPIHS", "CPIHS");
new MainPage().LoginCad();
}
异常消息是:
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
但是,我注释掉了 SoapUI 部分。 它会再次起作用。 喜欢:
public static void main(String[] args) throws Exception {
//SoapUIRun srun = new SoapUIRun();
//srun.runTestCase("CPIHS", "CPIHS");
new MainPage().LoginCad();
}
这是我的 SoapUI 方法:
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);
}
}
}
}
}
这是与硒相关的方法:
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();
}
任何人都知道为什么会发生这种情况。 我在谷歌上搜索过。 但似乎没有人在同样的情况下犯同样的错误。 非常感谢。
如果问题仅在SOAPUI执行后出现在selenium 上,那么可能是某些SOAPUI配置导致了该问题。 该问题可能是由于SOAPUI将默认代理设置为null
,然后当selenium尝试获取代理以检查配置时收到NullPointerExcetpion
。
根据您的错误跟踪:
Caused by: java.lang.NullPointerException
at org.apache.http.impl.conn.SystemDefaultRoutePlanner.determineProxy(SystemDefaultRoutePlanner.java:79)
如果你看一下org.apache.http.impl.conn.SystemDefaultRoutePlanner
类的源代码:
(注意我保留行号以与您的错误跟踪相关联)
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);
所以一个可能的解决方案是自己处理ProxySelect
。 然后您可以尝试使用以下解决方法:
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 提供的解决方法,但对我来说没有帮助。 我终于创建了新的代理:
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..");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.