Selenium网格实现问题-无法运行并行浏览器

时间:2018-12-07 05:00:51

标签: selenium selenium-grid

这是我下面测试的XML文件代码:请查看此testNG文件

  <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
   <suite name="parallel tests" parallel="tests">
    <test name="IETest1">
        <parameter name="platform" value="Windows" />
        <parameter name="browser" value="InternetExplorer" />
        <parameter name="runmode" value="Local" />
        <classes>
            <class name="in.zest.MiTest.MiCreditTests"></class>
        </classes>
    </test>

    <test name="ChromeTest1">
        <parameter name="platform" value="Windows" />
        <parameter name="browser" value="chrome" />
        <parameter name="runmode" value="Local" />

        <classes>
            <class name="in.zest.MiTest.MiCreditTests" />
        </classes>
       </test>
 </suite> <!-- Suite -->

测试:

@Parameters({ "platform","browser", "runmode" })
@BeforeMethod
public void beforeMethod(String platform, String browser, String runmode) `enter code here`throws MalformedURLException {
    report = Common.getExtentReport();
    test = report.startTest("MICreditTests");
    //driver = BrowserFactory.getBrowser(runmode, browser);
    RestAssured.baseURI = "https://zestmoney2.sandbox.mambu.com";

    DesiredCapabilities caps=new DesiredCapabilities();
    caps.setPlatform(Platform.WINDOWS);

    if(browser.equalsIgnoreCase("InternetExplorer"))
    {
        caps=DesiredCapabilities.internetExplorer();
        String hubURL="http://192.168.0.3:4447/wd/hub";
         driver=new RemoteWebDriver(new URL(hubURL),caps);
    }
    if(browser.equalsIgnoreCase("chrome"))
    {

        caps.setBrowserName(browser);
        //ChromeOptions defined
        ChromeOptions options=new ChromeOptions();
        options.merge(caps);
        String hubURL="http://192.168.0.3:4458/wd/hub";
         driver=new RemoteWebDriver(new URL(hubURL), options);

    }

     driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
     driver.manage().window().maximize();
}

这是设置脚本:我在其中注册了两个节点       Internet Explorer的Hub.one节点,Chrome浏览器的Hub.one节点。当我       试图执行。首先,它在完成执行       IE然后Chrome浏览器正在启动。请帮我找出我的什么代码       需要更新以并行运行两个浏览器。

2 个答案:

答案 0 :(得分:2)

问题在您的xml文件中。添加并行测试结构线程数以运行并行测试。下面的XML对我来说很好。注意:由于驱动程序加载时间,时间间隔很小。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Login Related Tests" parallel="tests" thread-count="4">
    <test name="Chrome login Test"  parallel="tests" preserve-order="true" group-by-instances="false" >
        <parameter name="browser" value="Chrome" />
        <parameter name="URL" value="AdminURL"/>
        <parameter name="Env" value="QA"/>
        <classes>
            <class name="tests.Login"/>
        </classes>
    </test>
    <test name="Firefox Login Test" parallel="tests" preserve-order="true" group-by-instances="false" >
        <parameter name="browser" value="Firefox" />
        <parameter name="URL" value="AdminURL"/>
        <parameter name="Env" value="QA"/>
        <classes>
            <class name="tests.Login"/>
        </classes>
    </test>
</suite>

答案 1 :(得分:0)

您的testng.xml缺少'thread-count'参数。如下更改

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