Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java TestNG在多个浏览器上并行执行始终只考虑单个浏览器_Java_Selenium Webdriver_Testng - Fatal编程技术网

Java TestNG在多个浏览器上并行执行始终只考虑单个浏览器

Java TestNG在多个浏览器上并行执行始终只考虑单个浏览器,java,selenium-webdriver,testng,Java,Selenium Webdriver,Testng,我正在尝试使用TestNG在多个浏览器中并行执行测试 但它总是只考虑第二个提到的浏览器 TestNG.xml <?xml version="1.0" encoding="UTF-8"?> <suite name="Parallel Tests" verbose="1" thread-count="10" parallel="tests"> <tests> <test name="Test1"> &l

我正在尝试使用TestNG在多个浏览器中并行执行测试

但它总是只考虑第二个提到的浏览器

TestNG.xml

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Parallel Tests" verbose="1" thread-count="10" parallel="tests">
    <tests> 
        <test name="Test1">
            <parameters>
                <parameter name="platform" value="Windows" />
                <parameter name="browser" value="chrome" />
                <parameter name="version" value="8" />
            </parameters>
            <classes>
                <class name="com.tribune.uiautomation.testscripts.TestEngine"/>
            </classes>
        </test> <!-- Test -->

        <test name="Test2">
            <parameters>
                <parameter name="platform" value="Windows" />
                <parameter name="browser" value="firefox" />
                <parameter name="version" value="8" />
            </parameters>
            <classes>
                <class name="com.tribune.uiautomation.testscripts.TestEngine"/>
            </classes>
        </test> <!-- Test -->

    </tests>    
</suite> <!-- Suite -->
控制台输出类似于:

log4j:WARN [] should be System.out or System.err.
log4j:WARN Using previously set target, System.out by default.
[TestNG] Running:
  D:\Selenium_Projects\WorkSpace_Personal\TribuneWebScriptLess\TestNG.xml

BrowserName got from XML is chrome
BrowserName got from XML is firefox

//from here onwards it is considering only firefox browser only (i.e. both the tests mentioned in TestNG.xml are running in firefox only)

提前感谢。

我理解这个问题,browserName变量是静态的。由于静态变量在线程之间共享,因此每次线程设置browserName值时,它都会覆盖现有值

因此,我通过将browserName变量定义为Threadlocal变量来解决这个问题。但是,通过将大量变量定义为ThreadLocal的方法,这会有问题吗?

如果我删除TestNG.xml中的(parallel=“tests”)属性,测试工作正常。问题只出现在并行属性上。
log4j:WARN [] should be System.out or System.err.
log4j:WARN Using previously set target, System.out by default.
[TestNG] Running:
  D:\Selenium_Projects\WorkSpace_Personal\TribuneWebScriptLess\TestNG.xml

BrowserName got from XML is chrome
BrowserName got from XML is firefox

//from here onwards it is considering only firefox browser only (i.e. both the tests mentioned in TestNG.xml are running in firefox only)