You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Selenium TestNG的XML中添加什么属性可实现单测试用例多会话并发执行

TestNG 单测试用例10并发会话XML配置说明

要实现单个测试用例同时在10个会话中并发执行,你需要在TestNG XML配置文件的<suite>标签下添加两个核心属性:

  • parallel:指定并发执行的维度,单测试用例(单@Test注解方法)并发的场景取值设为methods即可,如果是按测试实例维度并发可设为instances
  • thread-count:指定并发线程数,需要10个会话就将值设为10

配置示例

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="ParallelTestSuite" parallel="methods" thread-count="10">
    <test name="SingleTestCaseTest">
        <classes>
            <class name="com.yourproject.YourTestClass"/>
        </classes>
    </test>
</suite>

注意:需要保证Selenium的WebDriver实例是线程安全的,建议用ThreadLocal存储WebDriver对象,避免多线程操作同一个驱动实例导致会话冲突。

内容的提问来源于stack exchange,提问作者Travel Tales Karthik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 16:39:05