简体   繁体   English

如何在同一台机器上运行多个selenium测试套件

[英]how to run more then one selenium testing suite on the same machine

I am using Java/Selenium webdriver with testng to run my test automation, i have many automated project, each project is using a testing suite.xml, how can i run two suites or more at the same time on the same machine, here is my code for the creation of the driverInstance object: 我使用带有testng的Java / Selenium webdriver来运行我的测试自动化,我有很多自动化项目,每个项目都使用测试suite.xml,如何在同一台机器上同时运行两个或更多套件,这里是我创建driverInstance对象的代码:

public WebDriver getDriverInstance(
                                    String Url,
                                    String browser ) throws MalformedURLException {

    WebDriver driver = null;
    URL url = new URL( Url );
    if( browser.equals( "firefox" ) ) {
        DesiredCapabilities capability = DesiredCapabilities.firefox();
        driver = new RemoteWebDriver( url, capability );
    } else if( browser.equals( "chrome" ) ) {
        DesiredCapabilities capability = DesiredCapabilities.chrome();
        driver = new RemoteWebDriver( url, capability );
    } else if( browser.equals( "IE" ) ) {
        DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
        driver = new RemoteWebDriver( url, capability );
    }
    return driver;
}

You need set attribute as parallel="tests" in your testng xml 您需要在testng xml中将set属性设置为parallel =“tests”

<suite name="Parallel test runs" parallel="tests" thread-count="2">

There is the “parallel” parameter. 有“并行”参数。 Set to “tests” because we want to run tests parallel. 设置为“tests”因为我们想要并行运行测试。 The other parameter is the “thread-count”. 另一个参数是“线程计数”。 If it is set to 2, than two browsers will be opened and the first two tests will run from the list. 如果设置为2,则将打开两个浏览器,并且将从列表中运行前两个测试。 If the thread-count is 5 than five browsers will be opened and all the five tests will executed parallel! 如果线程数为5,则将打开五个以上的浏览器,并且所有五个测试将并行执行!

For tests your testng.xml structure should be like below:- 对于测试,您的testng.xml结构应如下所示: -

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

<test name="T_01">
    <classes>
        <class name="testNG.Parallel.Test01" ></class>
    </classes>
</test>

<test name="T_02">
    <classes>
        <class name="testNG.Parallel.Test02" ></class>
    </classes>
</test>

<test name="T_03">
    <classes>
        <class name="testNG.Parallel.Test03" ></class>
    </classes>
</test>

<test name="T_04">
    <classes>
        <class name="testNG.Parallel.Test04" ></class>
    </classes>
</test>

<test name="T_05">
    <classes>
        <class name="testNG.Parallel.Test05" ></class>
    </classes>
</test>

</suite>

If you want to run 2 classes parallelly 如果你想并行运行2个类

<suite name="Parallel test suite" parallel="classes" thread-count="2">

For classes your testng.xml structure should be like below:- 对于类,您的testng.xml结构应如下所示: -

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel test suite" parallel="classes" thread-count="2">
  <test name="Test 1">
    <classes>
      <class name="com.parallel.TestParallelClassOne"/>
      <class name="com.parallel.TestParallelClassTwo"/>
    </classes>
  </test>
</suite>

Now the thing is you need to add both project classes in different packages in a same project and use my 1 example testng structure and add the attribute as above. 现在你需要在同一个项目中的不同包中添加两个项目类,并使用我的1个示例testng结构并添加上面的属性。

How to run two suites:- 如何经营两间套房: -

<suite name="allSuites">
  <suite-files>
    <suite-file path="suite1.xml" />
    <suite-file path="suite2.xml" />
    ...
  </suite-files>
</suite>

Hope it will help you :) 希望它能帮到你:)

Get back to me if still facing any issue :) 如果仍然面临任何问题,请回复我:)

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

相关问题 如何在3个不同的浏览器中在同一台PC上并行运行selenium html套件? - how to run selenium html suite parallely on same pc in 3 different browsers? 如何在同一台机器上运行2个(或更多)Wildfly实例? - How to run 2 (or more) Wildfly instances on the same machine? JBoss 7:独立或域:在一台机器上作为一个(相同)应用程序运行 - JBoss 7: Standalone or domain: Run more as one (same) application on one machine 多次运行同一个Selenium测试套件 - Run the same Selenium test suite multiple times 如果同一测试多次运行,如何区分junit测试运行于哪个测试套件? - How distinguish from which test suite was junit test run in case the same tests are run more times? 如何使用Selenium Java在同一台机器上并行运行方法或类 - how to run methods or classes parallely on same machine using selenium java 在同一台机器上运行 selenium 网格集线器和节点 - Run selenium grid hub and node the same machine 如何并行运行测试套件XML文件? - How may I run testing suite XML files in parallel? 如何在不同的URL上使用Selenium和JUnit 5运行整个测试套件 - How to run an entire test suite with Selenium & JUnit 5 on different URLs 如何在testng的单个套件中多次运行测试类 - How to run a test class more than once in a single suite in testng
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM