我遇到了问题。我通过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);
}
}
}
}
}
这是Selenium相关方法:
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();
}
任何人都知道为什么会这样。我在谷歌搜索。但似乎没有人在同样的情况下得到同样的错误。非常感谢你。
答案 0 :(得分:0)
如果问题只发生在 SOAPUI 执行后的selenium,那么可能是某些 SOAPUI 配置导致了问题。问题可能是因为 SOAPUI 将默认代理设置为null
,然后当 selenium 尝试获取代理以检查配置时收到{{1 }}
基于您的错误跟踪:
NullPointerExcetpion
如果您查看org.apache.http.impl.conn.SystemDefaultRoutePlanner
类的源代码:
(注意我保持行号与您的错误跟踪相关)
Caused by: java.lang.NullPointerException
at org.apache.http.impl.conn.SystemDefaultRoutePlanner.determineProxy(SystemDefaultRoutePlanner.java:79)
所以可能的解决方案是自己照顾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
答案 1 :(得分:0)
感谢@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..");
}