java - 并行测试时 TeamCity 中的构建日志令人困惑

标签 java multithreading selenium teamcity selenium-grid2

我正在本地主机上使用 Java、Gradle、TestNG、Selenium Hub 和 Node,并尝试并行运行 5 个测试,以下是示例代码。

这是基类:

package tests.temp;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

public class TestBase
{

protected ThreadLocal<RemoteWebDriver> threadDriver = null;

@BeforeMethod
public void setUp() throws MalformedURLException {

    threadDriver = new ThreadLocal<RemoteWebDriver>();
    DesiredCapabilities dc = new DesiredCapabilities();
    FirefoxProfile fp = new FirefoxProfile();
    dc.setCapability(FirefoxDriver.PROFILE, fp);
    dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
    threadDriver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc));
}

public WebDriver getDriver() {
    return threadDriver.get();
}

@AfterMethod
public void closeBrowser() {
    getDriver().quit();

}

}

这是 1 个测试的示例。除了名称和数字之外,其他测试都是相同的:

package tests.temp;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

public class Test01 extends TestBase
{

@Test
public void testLink()throws Exception
{

    getDriver().get("http://www.yandex.ru");
    WebElement textBox = getDriver().findElement(By.name("text"));
    textBox.sendKeys("First test");
    System.out.println("First test thread-count=\"1\"");

}

}

带有 Suite 的 XML 文件,包含所有这 5 个测试:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel test runs" parallel="tests" thread-count="1">

<test name="Test_01">
    <classes>
        <class name="tests.temp.Test01" ></class>
    </classes>
</test>

 ...

<test name="Test_05">
    <classes>
        <class name="tests.temp.Test05" ></class>
    </classes>
</test>

</suite>

最后一个 - 带有 Suite 运行程序的 XML 文件:

<suite name="Parallel Test Suite">
<suite-files>
    <suite-file path="./testRunner.xml" />
</suite-files>
</suite>

问题是:如果我在 TeamCity 中使用 thread-count="1"构建日志看起来不错,但测试当然是按顺序运行的。 TeamCity thread = 1

如果 thread-count="2"或任何其他值 - 构建日志看起来令人困惑,并且测试计数器值不正确。但在 IDEA 中 - 一切都很酷而且正确! TeamCity thread = 2

有谁知道如何解决这个问题吗?

最佳答案

如果您报告并行运行的测试,则应该将它们分配给 flowId以便 TeamCity 了解哪个消息属于哪个测试。没有flowId不仅构建日志,而且测试统计也会不正确。如果没有 flowId,TeamCity 也可能会错误地将测试标记为失败,即使其他测试报告了此失败。 至于在构建日志中正确显示并行测试,请参阅 TeamCity 跟踪器中的请求:https://youtrack.jetbrains.com/issue/TW-8249 。请投票。

关于java - 并行测试时 TeamCity 中的构建日志令人困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37873925/

相关文章:

Java 整数金字塔

c++ - 多线程访问 unordered_map 时出现运行时错误

java - selenium 格式化程序修改(导出到 webdriver 支持的 java)

python - chrome 无法使用 python selenium chromedriver 加载

java - 如何重命名jtree中的节点

java - 将被调用的 Jersey get 方法

java - org.apache.activemq.transport.InactivityIOException : Cannot send, channel 已经失败

c - 如何计算正在运行的线程数 (pthreads)?

c++ - 使用 MinGW gcc 4.4.0 boost thread_interrupted 异常终止(),3.4.5 OK

java - 如何检查 URL 中的视频加载情况?