简体   繁体   中英

Unable to run parallel tests via testNG

Using a POM model approach here. When trying to run tests in parallel, although 3 instances of chrome are launched the test is carried out in only one. The rest don't run at all with URL shown as data; . Can anyone help me out here?

**Test Code**
    
public class Tests {
    private WebDriver driver = null;
    private static String OptionalProductQuantity = "6";
    private static String ChatMessage = "Hi";
    ChromeOptions options = new ChromeOptions().setBinary("C:\\Program Files\\Google\\Chrome Beta\\Application\\chrome.exe");



    @BeforeTest
    public void oneTimeSetUp() {
        
        System.setProperty("webdriver.chrome.driver", ".\\Drivers\\chromedriver.exe");


    }

    @BeforeMethod
    public void setUp() {
        driver = new ChromeDriver(options);
        

    }

    @Test(description = "Adding product to the cart")
    public void AddtoCart() {


        Commons common = new Commons(driver);
        common.navigateTo(Constants.TRUCKX_URL);
        common.clickElement(AddtoCart.Checkout);
        
    }
    @Test(description = "Validating the homepage's UI is fine ")
    public void ValidateHomepageUI() {

        Commons common = new Commons(driver);
        common.navigateTo(Constants.TRUCKX_URL);
         
    }  
    @AfterMethod
    public void exitBrowser() {
        driver.quit();
    }    
}

TestNG XMML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="methods" >
    <test name="Test" >
        <classes>
            <class name="Tests_UI.Tests" />
        </classes>
    </test>
</suite>

You are using the same Driver object for all your 3 cases. Even though there are 3 threads which would be spawned by TestNG, the driver object is not per thread, leading to the behavior you see. You need to use ThreadLocal objects in your beforeMethod or listeners to provide one instance of webdriver per TestNG thread.

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