【问题标题】:@AfterMethod tearDowns for running the entire class using - selenium 4@AfterMethod tearDowns 用于使用 - selenium 4 运行整个课程
【发布时间】:2022-07-08 21:25:31
【问题描述】:

在运行包含许多方法的整个类时,我面临着拆除问题(org.openqa.selenium.SessionNotCreatedException)。测试在 saucelabs 上进行。

当运行单个方法时,它工作得非常好,但在运行整个类或套件时,它就不起作用了。 此外,很少有方法通过,而其他方法正在拆除。 有什么可能?

配置: 测试NG - 7.4.0 Maven - 3.8.4 硒 - 4.1.3

代码: 代码多种多样,但我们在下面将其用于所有方法(它在多个浏览器上运行)

     private ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
    public WebDriver getWebDriver() {
            // Starts the ThreadLocal<Boolean> for checking the evidon banner as false
            hasEvidonBeenChecked.set(false);
            if (!BaseTest.isLocal) {
                return webDriver.get();
            } else {
                return localWebDriver;
            }
        }
 @org.testng.annotations.Test(dataProvider = "remoteBrowsers", priority = 1)
public void TestPractive(String browser, String version, String os, String platformversion,
        String devicename, Method method) throws InterruptedException, OfferNotFoundException, IOException,
        NullPointerException, IndexOutOfBoundsException, ArrayIndexOutOfBoundsException {
    this.createDriver(browser, version, os, platformversion, devicename, method.getName());
    WebDriver driver = this.getWebDriver();
    this.setupImplicitWait(driver, 20);

错误 默认套件 总测试运行:9,通过:3,失败:3,跳过:3 配置失败:3,跳过:3

[AsyncHttpClient-1-8] 错误 org.asynchttpclient.netty.request.NettyRequestSender - 无法写入请求 [AsyncHttpClient-1-10] 错误 org.asynchttpclient.netty.request.NettyRequestSender - 无法写入请求 [AsyncHttpClient-1-9] 错误 org.asynchttpclient.netty.request.NettyRequestSender - 无法写入请求 java.io.IOException: 流关闭

配置失败:@AfterMethod 拆解 java.lang.NullPointerException:无法调用“org.openqa.selenium.JavascriptExecutor.executeScript(String, Object[])”,因为“java.lang.ThreadLocal.get()”的返回值为null

org.openqa.selenium.SessionNotCreatedException:无法启动新会话。可能的原因是远程服务器地址无效或浏览器启动失败。 构建信息:版本:'4.1.0',修订:'87802e897b' 系统信息:主机:'W105482ZY2',ip:'192.168.29.171',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',java.version:'17.0.1 ' 驱动程序信息:org.openqa.selenium.remote.RemoteWebDriver 命令:[null,newSession {capabilities=[Capabilities {browserName:MicrosoftEdge,browserVersion:latest-1,调味汁:选项:,desiredCapabilities=Capabilities {browserName:MicrosoftEdge,browserVersion:latest-1,调味汁:options:,平台名称:Windows 10 , 分辨率: 1920x1080}, seleniumVersion: 4.1.0}}] 功能{}

TestNG XML testng xml

【问题讨论】:

  • @titusfortner - 请帮忙。 :)
  • 能不能加一些代表失败的代码?
  • 在@AlexeyR 上方添加。
  • 嗯。那是……很奇怪。您收到的错误意味着 Sauce Labs 无法启动会话,这通常是由于功能不正确而发生的……但是 Sauce 不在乎您是在运行单个方法还是整个类。事实上,我们甚至都不知道。它是否针对某个失败的浏览器进行测试?能否分享一下createDriver的实现,有没有并行化?
  • @Dylan Lacey - 是的,它实际上与酱实验室有关。把原因贴在下面。谢谢:)

标签: testng saucelabs selenium4


【解决方案1】:

saucelab url 存在问题,在几次会话后正在关闭踏板。

实际: // 启动远程浏览器并将其设置为当前线程 webDriver.set(新的 RemoteWebDriver( 新 URL("https://" + 用户名 + ":" + accesskey + "@ondemand.saucelabs.com:443/wd/hub"),,capabilities));

预期: 新 URL("https://" + 用户名 + ":" + accesskey + "@ondemand.us-west-1.saucelabs.com:443/wd/hub"),capabilities));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-26
    • 2016-10-25
    • 2016-05-24
    • 1970-01-01
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多