0

I have a Test method which launches the browser and enters some text and performs remaining operations. Now I want to run the same Test method in multiple instances of the browser(both chrome or can be chrome, Mozilla). For this, I am passing the browser name and text to be entered in each browser in DataProvider.

I have tried parallel=true for the dataprovider but it's not working as expected. It opens multiple browsers but both the data from dataprovider gets entered only in 1 browser while other remains idle.

public class test1 {

    String communityURL = "https://example.com";

    @DataProvider(name = "data", parallel = true)
    public Object[][] data() {
        return new Object[][] { new Object[] { "Chrome", "data1" }, new Object[] { "Chrome", "data2" }

        };
    }

    @Test(dataProvider = "data")
    public void runTest(String browser, String data) throws IOException, InterruptedException {
        WebDriver driver;
        Properties prop = new Properties();
        FileInputStream fis = new FileInputStream(System.getProperty("user.dir") + "\\locators.properties");
        prop.load(fis);
        System.setProperty("webdriver.chrome.driver",
                "C:\\Users\\xxxx\\Downloads\\chromedriver_win32\\chromedriver.exe");
        driver = new ChromeDriver();

        driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
        driver.get(communityURL);
        driver.findElement(By.xpath(prop.getProperty("xxx"))).sendKeys(data);
        Thread.sleep(5000);
        driver.findElement(By.xpath(prop.getProperty("xxx"))).sendKeys(data);
        driver.findElement(By.xpath(prop.getProperty("xxxx"))).click();
        driver.findElement(By.xpath(prop.getProperty("xxx"))).click();
        Thread.sleep(3000);
    }
}

I need to open multiple session of browsers and each browser to take each value from dataprovider ex: Session1: Chrome- data1 & Session2: Chrome- data2

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
  • There is nothing in your code, that would stand out as a problem. Are you sure you dont have any other `WebDriver driver` declared at the class level? Just to be absolutely sure, do you see any compilation errors when you comment out `WebDriver driver;` in your `@Test` annotated `runTest()` method? – Krishnan Mahadevan Jun 09 '19 at 03:19
  • 2
    Hi, I have resolved the issue by adding paramenters to my Test method (dataProvider="data",threadPoolSize=2,invocationCount=1,timeOut=300000), and Yes there is no other instance of driver declared apart from the one mentioned in the code above. Will close the question.Thanks – Varsha Rai Jun 10 '19 at 05:23

0 Answers0