gpt4 book ai didi

java - 运行 SoapUI 后,无法启动 selenium

转载 作者:太空宇宙 更新时间:2023-11-04 12:16:01 25 4
gpt4 key购买 nike

我遇到了问题。我通过 Java 自动化代码运行 SoapUI Web 服务测试。但在那之后。 Selenium 不起作用。看来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();

}

任何人都知道为什么会发生这种情况。我在谷歌上搜索过。但似乎没有人在相同的情况下遇到相同的错误。非常感谢。

最佳答案

如果问题仅在执行 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();
}

关于java - 运行 SoapUI 后,无法启动 selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39403993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com