gpt4 book ai didi

java - 程序启动 testNG selenium 测试卡住

转载 作者:行者123 更新时间:2023-12-01 17:30:37 26 4
gpt4 key购买 nike

当使用 testNG 以编程方式启动 Selenium 测试时,进程会卡住。所有测试均成功,但进程并未结束且不返回任何退出代码。

示例

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上的端口

最佳答案

问题出在 selenium 的 alpha 版本

github上有问题https://github.com/SeleniumHQ/selenium/issues/8159

过渡到3个稳定版本解决了问题

关于java - 程序启动 testNG selenium 测试卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61128780/

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