以编程方式使用testNG启动硒测试时,该过程冻结。所有测试都成功,但是该过程不会结束,并且不会返回任何退出代码。
示例
Main.java
package com.example;
import org.testng.TestNG;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
TestNG testNG = new TestNG();
List<XmlSuite> xmlSuites = new ArrayList<>();
XmlSuite xmlSuite = new XmlSuite();
List<XmlTest> xmlTestList = new ArrayList<>();
XmlTest xmlTest = new XmlTest(xmlSuite);
List<XmlClass> xmlClassList = new ArrayList<>();
xmlClassList.add(new XmlClass(TestOne.class));
xmlTest.setXmlClasses(xmlClassList);
xmlTestList.add(xmlTest);
xmlSuite.setTests(xmlTestList);
xmlSuites.add(xmlSuite);
testNG.setXmlSuites(xmlSuites);
testNG.run();
}
}
TestOne.java
package com.example;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class TestOne {
private WebDriver webDriver;
@BeforeSuite
public void prepare() {
WebDriverManager.chromedriver().setup();
this.webDriver = new ChromeDriver();
}
@Test
public void testOne() {
webDriver.get("http://google.com/");
}
@AfterSuite
public void shutdown() {
if (webDriver != null) {
webDriver.close();
}
}
}
启动时
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987@{#882}) on port 27439
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Apr 09, 2020 10:12:50 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
===============================================
Default Suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================
但是过程并没有结束
Debug和Streis并没有太大帮助。发现AsyncHttpTimer挂起,它将检查localhost上的端口
答案 0 :(得分:0)