Navsony
Navsony

Reputation: 21

Parallel execution is not working for attribute tests in testng.xml

Parallel execution is not working for attribute "tests" in suite.xml. Even though I have set parallel ="tests", it is still executing in sequential order only.

Please find below my suite.xml and the test script

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>

My Test Script :

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("[email protected]");
        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) - [email protected] - 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();
    }

}

Upvotes: 0

Views: 801

Answers (1)

Navsony
Navsony

Reputation: 21

I got the issue. It's because of TestNG version. If I use TestNG -6.9.10, same code is working fine. There is nothing wrong in the code.

Upvotes: 1

Related Questions