简体   繁体   中英

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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM