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

耗尽温柔 提交于 2020-01-03 21:06:32

问题


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:

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;
}

回答1:


You need set attribute as parallel="tests" in your testng xml

<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. 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. If the thread-count is 5 than five browsers will be opened and all the five tests will executed parallel!

For tests your testng.xml structure should be like below:-

<!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

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

For classes your testng.xml structure should be like below:-

<!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.

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 :)



来源:https://stackoverflow.com/questions/32578758/how-to-run-more-then-one-selenium-testing-suite-on-the-same-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!