简体   繁体   中英

TestNG parameter- how to run mulitple test cases concurrently

i am trying to run two same test cases concurrently using chrome broswer, how do i achieve it?

the code below i tried, it opens two browsers and one of test case did not start. any help? thanks

<suite name="Suite">

    <test name="ToolsQA1">

 <parameter name="sUsername" value="testuser_1"/>

 <parameter name="sPassword" value="Test@123"/>

 <classes>

     <class name="automationFramework.TestngParameters" />

 </classes>

    </test>
 <test name="ToolsQA2">

 <parameter name="sUsername" value="testuser_2"/>

 <parameter name="sPassword" value="Test@999"/>

 <classes>

     <class name="automationFramework.TestngParameters" />

 </classes>

    </test>

</suite>

My TestngParameters class this is my class package, i have added

package automationFramework;

public class TestngParameters{

    WebDriver driver = new ChromeDriver(); 

    @Beforesuite
    public void testng() throws InterruptedException
    {   
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\Desktop\\chromedriver.exe");

        driver.get("https://www.testing.com"); 
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Beforetest
    @Parameters({"sUsername","sPassword"})
    public void declareaccount(String sUsername, String sPassword) throws InterruptedException 
    {   
        WebElement sname = driver.findElement(By.name("FullName"));
        sname.clear();
        sname.sendKeys(sUsername);
        WebElement passwordname = driver.findElement(By.name("password"));
        spassword.clear();
        spassword.sendKeys(sPassword);
    }

}

Add one attribute in XML file on suite level

<suite name=”  “ parallel=”tests” thread-count =”2”>

the attribute parallel="tests" - it will run the tests

the attribute thread-count="2" - how many test you want to run

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