如何在同一台机器上运行多个硒测试套件 [英] how to run more then one selenium testing suite on the same machine

查看:71
本文介绍了如何在同一台机器上运行多个硒测试套件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Java/Selenium Webdriver与testng一起使用来运行我的测试自动化,我有很多自动化项目,每个项目都使用一个test suite.xml,我如何才能在同一台机器上同时运行两个或多个套件, 这是我用于创建driverInstance对象的代码:

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

推荐答案

您需要在testng xml中将set属性设置为parallel ="tests"

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

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

有一个平行"参数.设置为测试"是因为我们要并行运行测试.另一个参数是线程数".如果将其设置为2,则将打开两个浏览器,并且将从列表中运行前两个测试.如果线程数为5,则将打开五个浏览器,所有五个测试将并行执行!

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!

对于测试,您的testng.xml结构应如下所示:-

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>

如果要并行运行2个类

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

对于类,您的testng.xml结构应如下所示:-

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>

现在,您需要将两个项目类添加到同一项目的不同包中,并使用我的1个示例testng结构并添加上述属性.

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.

如何运行两个套件:-

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

这篇关于如何在同一台机器上运行多个硒测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆