简体   繁体   English

如何在 selenium 中并行运行多个类

[英]How to run multiple classes in parallel in selenium

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" thread-count="4" parallel="tests"  preserve-order="true">
    <test name="Login - firefox">
        <parameter name="browserName" value="firefox"></parameter>
        <classes>
            <class name="com.qa.logintests.LoginTest" />
            <class name="com.qa.logouttest.LogoutTest" />
        </classes>
    </test>

    <test name="Login - chrome">
        <parameter name="browserName" value="chrome"></parameter>
        <classes>
            <class name="com.qa.logintests.LoginTest" />
            <class name="com.qa.logouttest.LogoutTest" />
        </classes>
    </test>
</suite> 
  1. Need to run multiple classes in parallel, if I run with only 1 browser with parallel = none then the code works fine.需要并行运行多个类,如果我只使用 1 个并行 = none 的浏览器运行,那么代码可以正常工作。
  2. But If I use parallel = tests and try to run, then for second class named as "LogoutTest", I am facing null pointer exception.但是如果我使用并行 = 测试并尝试运行,那么对于名为“LogoutTest”的第二个 class,我将面临 null 指针异常。
  3. Can anyone suggest me how to resolve this issue?谁能建议我如何解决这个问题?

As we want classes to be executed in parallel, we have to add parallel="classes" in the attribute of suite tag.由于我们希望类并行执行,我们必须在套件标签的属性中添加parallel="classes"

Replace parallel="tests" with parallel="classes"parallel="tests"替换为parallel="classes"

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" thread-count="4" parallel="classes">
    <test name="Login - firefox">
        <parameter name="browserName" value="firefox"></parameter>
        <classes>
            <class name="com.qa.logintests.LoginTest" />
            <class name="com.qa.logouttest.LogoutTest" />
        </classes>
    </test>

    <test name="Login - chrome">
        <parameter name="browserName" value="chrome"></parameter>
        <classes>
            <class name="com.qa.logintests.LoginTest" />
            <class name="com.qa.logouttest.LogoutTest" />
        </classes>
    </test>
</suite> 

Note: If one class is dependent to other for example, logout is dependent to login, then it obvious that it will throw null pointer exception.注意:如果一个class依赖于另一个,例如logout依赖于login,那么很明显会抛出null指针异常。 And it wouldn't be wise to run dependent things in parallel.并行运行相关的事情是不明智的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何运行一个可以运行多个Selenium类的类? - How to run a class which runs multiple Selenium classes? 如何使用多线程并行运行两个类? - How to run two classes in parallel using multithreading? 如何通过使用 TestNG 和 Selenium 的方法并行运行测试 - How to run tests in parallel by methods with TestNG and Selenium 如何使用TestNG并行运行Selenium? - How to run Selenium in parallel using TestNG? 如何使用@BeforeSuite批注使用Selenium + TestNG运行多个浏览器会话(并行执行) - How to run multiple browser sessions (parallel execution) with Selenium + TestNG using @BeforeSuite annotation 如何在多台服务器上的IE中并行运行TestNG / Selenium测试套件? - How can I run a TestNG/Selenium test suite in IE on multiple servers in parallel? 使用Java并行运行时如何将多个Selenium WebDriver会话日志写入不同的文件 - How to write multiple Selenium WebDriver session logs into different files when they run parallel using java 在并行testng中运行类 - Run classes in parallel testng 如何按顺序运行 2.java 类? (带有 Eclipse 的硒) - How to run 2 .java classes in order? (Selenium with Eclipse) 如何在TestNG中运行多个并行套件 - How to run multiple parallel suites in TestNG
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM