【问题标题】:Parallel execution is not working for attribute tests in testng.xml并行执行不适用于 testng.xml 中的属性测试
【发布时间】:2018-03-21 17:23:24
【问题描述】:

并行执行不适用于suite.xml 中的属性"tests"。即使我设置了parallel ="tests",它仍然只是按顺序执行。

请在下面找到我的suite.xml 和测试脚本

suite.xml:

<suite name="testsuite1" parallel="tests" thread-count="2">
    <test name="gmailloginchrome">
        <parameter name="platform" value="windows"></parameter>
        <parameter name="browser" value="chrome"></parameter>
        <classes>
            <class name="sample.LoginChrome"></class>
        </classes>
    </test>
    <test name="gmailloginie">
        <parameter name="platform" value="windows"></parameter>
        <parameter name="browser" value="ie"></parameter>
        <classes>
            <class name="sample.LoginChrome"></class>
        </classes>
    </test>
</suite>

我的测试脚本:

package sample;

public class LoginChrome {

    WebDriver driver;
    Logger log = Logger.getLogger(LoginChrome.class);
    /**
     * tests the login of Gmail for given credentials in Chrome
     * @throws Exception
     */
    @Test
    public void loginTest() throws Exception {
        System.out.println("Inside the test method");
        log.info("started the test method");
        log.info("entering credentials");
        driver.findElement(By.id("identifierId")).clear();
        driver.findElement(By.id("identifierId")).sendKeys("xyz@gmail.com");
        driver.findElement(By.id("identifierNext")).click();
        driver.findElement(By.name("password")).sendKeys("abc@2016");
        Thread.sleep(3000);
        driver.findElement(By.cssSelector("div#passwordNext")).click();
        Thread.sleep(6000);
        log.info("checking whether login successful or not");
        String title = driver.getTitle();
        log.info("Title is " + title);
        Thread.sleep(3000);
        Assert.assertEquals(title, "Inbox (7,258) - xyz@gmail.com - Gmail");
        log.info("completed the test method");
    }
    /**
     * sets the driver executable and opens the browser
     * @param platform
     * @param browser
     * @return nothing
     */
    @Parameters({ "platform", "browser" })
    @BeforeMethod
    public void beforeMethod(String platform, String browser) {
        if(browser.contains("chrome")) {
        System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/drivers/chromedriver.exe");
        driver = new ChromeDriver();
        }
        else if(browser.contains("ie")) {
        System.setProperty("webdriver.ie.driver", System.getProperty("user.dir") + "/drivers/IEDriverServer.exe");
        driver = new InternetExplorerDriver();
        }
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://www.gmail.com");
    }
    /**
     * quits the driver & closes the browser
     * @return nothing
     */
    @AfterMethod
    public void afterMethod() {
        driver.quit();
    }

}

【问题讨论】:

    标签: selenium parallel-processing testng


    【解决方案1】:

    我遇到了问题。这是因为 TestNG 版本。如果我使用 TestNG -6.9.10,相同的代码可以正常工作。代码没有错。

    【讨论】:

      猜你喜欢
      • 2021-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-04
      • 2014-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多