When we use dataprovider with parallel tests then in the second browser it is not opening up the URL

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

When we use dataprovider with parallel tests then in the second browser it is not opening up the URL

prasanth kotagiri-2
Hi All,

Below is my code

ublic class SampleTest1 {

public WebDriver driver;

@DataProvider(name = "Authentication", parallel=true)

public static Object[][] credentials() {

return new Object[][] { { "[hidden email]", "Medscape@123" },{ "[hidden email]", "Medscape@123" } };

}

/*@BeforeMethod
public void openBrowser() throws InterruptedException {
System.out.println("Creating Chrome object");
System.setProperty("webdriver.chrome.driver", "D:/Library/chromedriver_win32/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get("https://authoring.qa00.medscape.com/");
Thread.sleep(20000);
}*/

@Test(dataProvider = "Authentication",threadPoolSize = 3,invocationCount = 1)
public void sampletset1(String username, String password) throws InterruptedException {
System.out.println("Creating Chrome object");
System.setProperty("webdriver.chrome.driver", "D:/Library/chromedriver_win32/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.get("https://authoring.qa00.medscape.com/");
Long id = Thread.currentThread().getId();
System.out.println("Test method executing on thread with id: " + id);
driver.findElement(By.xpath("//*[@id='edit-name']")).sendKeys(username);
driver.findElement(By.xpath("//*[@id='edit-pass']")).sendKeys(password);

}
}

In the above code it is opening 2 chrome browsers parallel at a time.

But in the first browser it is not opening up the URL
But in the second browser it is opening the URL and entering the 2 credentials in the same username box and password box.

My Expectation: It should open 2 browsers and in one browser it should login with first user and in second browser it should login with second user.

Actual Result: It is not opening the url in first browser and in the second browser it is doing all the remaining thing as i mentioned above.

Please help me ASAP

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/49c486fb-f668-4f48-a917-4d7fb8094170%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: When we use dataprovider with parallel tests then in the second browser it is not opening up the URL

Jonathan Herbaut
That's because your webDriver object is common in your parallel class. The first parallel run, you instanciate your webdriver that brings you a session to link your browser to the webdriver. During this time, your parallel code is executing. And he is trying to instanciate another webdriver in the same class in your code. And this instance erase your previous one. You lost the session Id and all your code is executing with the last session Id you get (so the last browser).
If you are working with Grid, you will see in the console that some of your sessions are used but never closed. Once you will correct your problem, you will fix another one : RAM consumption (you open and never close the first chrome for the moment) ! :)

2018-05-22 16:40 GMT+02:00 prasanth kotagiri <[hidden email]>:
Hi All,

Below is my code

ublic class SampleTest1 {

public WebDriver driver;

@DataProvider(name = "Authentication", parallel=true)

public static Object[][] credentials() {

return new Object[][] { { "[hidden email]", "Medscape@123" },{ "[hidden email]", "Medscape@123" } };

}

/*@BeforeMethod
public void openBrowser() throws InterruptedException {
System.out.println("Creating Chrome object");
System.setProperty("webdriver.chrome.driver", "D:/Library/chromedriver_win32/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();

Thread.sleep(20000);
}*/

@Test(dataProvider = "Authentication",threadPoolSize = 3,invocationCount = 1)
public void sampletset1(String username, String password) throws InterruptedException {
System.out.println("Creating Chrome object");
System.setProperty("webdriver.chrome.driver", "D:/Library/chromedriver_win32/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
Long id = Thread.currentThread().getId();
System.out.println("Test method executing on thread with id: " + id);
driver.findElement(By.xpath("//*[@id='edit-name']")).sendKeys(username);
driver.findElement(By.xpath("//*[@id='edit-pass']")).sendKeys(password);

}
}

In the above code it is opening 2 chrome browsers parallel at a time.

But in the first browser it is not opening up the URL
But in the second browser it is opening the URL and entering the 2 credentials in the same username box and password box.

My Expectation: It should open 2 browsers and in one browser it should login with first user and in second browser it should login with second user.

Actual Result: It is not opening the url in first browser and in the second browser it is doing all the remaining thing as i mentioned above.

Please help me ASAP

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/49c486fb-f668-4f48-a917-4d7fb8094170%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAH1BzpWG-RuEjK9j8P3Qjeawh0vzySyJVm0H2Eg-Q3-fGfFXDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: When we use dataprovider with parallel tests then in the second browser it is not opening up the URL

prasanth kotagiri-2
HI,
Thanks for your support. How to overcome this one?

On Tuesday, May 22, 2018 at 8:22:20 PM UTC+5:30, Jonathan Herbaut wrote:
That's because your webDriver object is common in your parallel class. The first parallel run, you instanciate your webdriver that brings you a session to link your browser to the webdriver. During this time, your parallel code is executing. And he is trying to instanciate another webdriver in the same class in your code. And this instance erase your previous one. You lost the session Id and all your code is executing with the last session Id you get (so the last browser).
If you are working with Grid, you will see in the console that some of your sessions are used but never closed. Once you will correct your problem, you will fix another one : RAM consumption (you open and never close the first chrome for the moment) ! :)

2018-05-22 16:40 GMT+02:00 prasanth kotagiri <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="RVqu9G1-CwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">prasan...@...>:
Hi All,

Below is my code

ublic class SampleTest1 {

public WebDriver driver;

@DataProvider(name = "Authentication", parallel=true)

public static Object[][] credentials() {

return new Object[][] { { "<a href="javascript:" target="_blank" gdf-obfuscated-mailto="RVqu9G1-CwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">editor...@...", "Medscape@123" },{ "<a href="javascript:" target="_blank" gdf-obfuscated-mailto="RVqu9G1-CwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">editor...@...", "Medscape@123" } };

}

/*@BeforeMethod
public void openBrowser() throws InterruptedException {
System.out.println("Creating Chrome object");
System.setProperty("webdriver.chrome.driver", "D:/Library/chromedriver_win32/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get("<a href="https://authoring.qa00.medscape.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fauthoring.qa00.medscape.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF6KNsyWBiaHgSNcrXlohiTxxac4w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fauthoring.qa00.medscape.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF6KNsyWBiaHgSNcrXlohiTxxac4w&#39;;return true;">https://authoring.qa00.medscape.com/");
Thread.sleep(20000);
}*/

@Test(dataProvider = "Authentication",threadPoolSize = 3,invocationCount = 1)
public void sampletset1(String username, String password) throws InterruptedException {
System.out.println("Creating Chrome object");
System.setProperty("webdriver.chrome.driver", "D:/Library/chromedriver_win32/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.get("<a href="https://authoring.qa00.medscape.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fauthoring.qa00.medscape.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF6KNsyWBiaHgSNcrXlohiTxxac4w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fauthoring.qa00.medscape.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF6KNsyWBiaHgSNcrXlohiTxxac4w&#39;;return true;">https://authoring.qa00.medscape.com/");
Long id = Thread.currentThread().getId();
System.out.println("Test method executing on thread with id: " + id);
driver.findElement(By.xpath("//*[@id='edit-name']")).sendKeys(username);
driver.findElement(By.xpath("//*[@id='edit-pass']")).sendKeys(password);

}
}

In the above code it is opening 2 chrome browsers parallel at a time.

But in the first browser it is not opening up the URL
But in the second browser it is opening the URL and entering the 2 credentials in the same username box and password box.

My Expectation: It should open 2 browsers and in one browser it should login with first user and in second browser it should login with second user.

Actual Result: It is not opening the url in first browser and in the second browser it is doing all the remaining thing as i mentioned above.

Please help me ASAP

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="RVqu9G1-CwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">selenium-user...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="RVqu9G1-CwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">seleniu...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/selenium-users/49c486fb-f668-4f48-a917-4d7fb8094170%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/selenium-users/49c486fb-f668-4f48-a917-4d7fb8094170%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/selenium-users/49c486fb-f668-4f48-a917-4d7fb8094170%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/selenium-users/49c486fb-f668-4f48-a917-4d7fb8094170%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/bc0e9360-4d8b-46ee-bf11-fbca5f59576f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: When we use dataprovider with parallel tests then in the second browser it is not opening up the URL

Krishnan Mahadevan

Have your @BeforeMethod initialize a ThreadLocal variant of the WebDriver instead of the class level data member.

 

Change: public WebDriver driver;

To: private static final ThreadLocal<WebDriver> driver = new ThreadLocal<>();

 

Change: driver = new ChromeDriver();

To: driver.set(new ChromeDriver());

 

Create a method such as the one below to get access to the driver object :

 

private WebDriver getDriver() {

    return driver.get();

}

 

And use “getDriver()” instead of “driver” through-out your code.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

From: <[hidden email]> on behalf of prasanth kotagiri <[hidden email]>
Reply-To: <[hidden email]>
Date: Tuesday, May 22, 2018 at 8:34 PM
To: Selenium Users <[hidden email]>
Subject: Re: [selenium-users] When we use dataprovider with parallel tests then in the second browser it is not opening up the URL

 

HI,

Thanks for your support. How to overcome this one?

On Tuesday, May 22, 2018 at 8:22:20 PM UTC+5:30, Jonathan Herbaut wrote:

That's because your webDriver object is common in your parallel class. The first parallel run, you instanciate your webdriver that brings you a session to link your browser to the webdriver. During this time, your parallel code is executing. And he is trying to instanciate another webdriver in the same class in your code. And this instance erase your previous one. You lost the session Id and all your code is executing with the last session Id you get (so the last browser).

If you are working with Grid, you will see in the console that some of your sessions are used but never closed. Once you will correct your problem, you will fix another one : RAM consumption (you open and never close the first chrome for the moment) ! :)

 

2018-05-22 16:40 GMT+02:00 prasanth kotagiri <<a href="javascript:" target="_blank">prasan...@...>:

Hi All,

 

Below is my code

 

ublic class SampleTest1 {

 

public WebDriver driver;

 

@DataProvider(name = "Authentication", parallel=true)

 

public static Object[][] credentials() {

 

return new Object[][] { { "<a href="javascript:" target="_blank">editor...@...", "Medscape@123" },{ "<a href="javascript:" target="_blank">editor...@...", "Medscape@123" } };

 

}

 

/*@BeforeMethod

public void openBrowser() throws InterruptedException {

System.out.println("Creating Chrome object");

System.setProperty("webdriver.chrome.driver", "D:/Library/chromedriver_win32/chromedriver.exe");

driver = new ChromeDriver();

driver.manage().window().maximize();

 

Thread.sleep(20000);

}*/

 

@Test(dataProvider = "Authentication",threadPoolSize = 3,invocationCount = 1)

public void sampletset1(String username, String password) throws InterruptedException {

System.out.println("Creating Chrome object");

System.setProperty("webdriver.chrome.driver", "D:/Library/chromedriver_win32/chromedriver.exe");

driver = new ChromeDriver();

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

Long id = Thread.currentThread().getId();

System.out.println("Test method executing on thread with id: " + id);

driver.findElement(By.xpath("//*[@id='edit-name']")).sendKeys(username);

driver.findElement(By.xpath("//*[@id='edit-pass']")).sendKeys(password);

 

}

}

 

In the above code it is opening 2 chrome browsers parallel at a time.

 

But in the first browser it is not opening up the URL

But in the second browser it is opening the URL and entering the 2 credentials in the same username box and password box.

 

My Expectation: It should open 2 browsers and in one browser it should login with first user and in second browser it should login with second user.

 

Actual Result: It is not opening the url in first browser and in the second browser it is doing all the remaining thing as i mentioned above.

 

Please help me ASAP

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank">selenium-user...@....
To post to this group, send email to <a href="javascript:" target="_blank">seleniu...@....
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/49c486fb-f668-4f48-a917-4d7fb8094170%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/bc0e9360-4d8b-46ee-bf11-fbca5f59576f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/AA7ADD6E-EEDB-498D-966A-4BD6E6A13551%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: When we use dataprovider with parallel tests then in the second browser it is not opening up the URL

Jonathan Herbaut
I will look at this solution.
I have instanciate and declared my webDriver object in the test directly.
I have to use generic classes with my webdriver that's why I made this.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAH1BzpUD4Ff0vBWUfLhT%3D_bhwhJ_wko0MoG1Xv4qj%2B-Lmv-jtg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.