In my previous post, We learnt how to execute selenium WebDriver unmarried software automation examine inwards multiple browsers inwards parallel using Selenium Grid 2. We had used "parameter" tag inwards testng.xml file to feed browser advert inwards which your software automation examine needs to run inwards parallel. Instead of using @Parameters, We tin purpose @DataProvider musical note method to feed browser names too run selenium WebDriver examine inwards parallel using selenium Grid 2.
If you lot purpose @Parameters, You involve to write same examine multiple times(Depends on give away of browsers) in testng.xml file. Main produce goodness of using @DataProvider musical note method is you lot no involve to write same software automation examine illustration advert multiple times inwards testng.xml file. You cause got to write it entirely in ane lawsuit inwards testng.xml file. @DataProvider musical note method volition provide browser details to @Test method. To run examine inwards parallel, you lot involve to laid upwards (parallel=true) alongside @DataProvider annotation. Let's endeavour it alongside uncomplicated example.
My requirement is : I wants to run my selenium software automation examine parallel inwards 3 browsers using selenium grid ii too testng musical note @DataProvider.
- Selenium Grid ii hub should move inwards running agency every bit described inwards THIS POST.
- Selenium Grid ii node should move registered alongside hub too inwards running agency every bit described inwards THIS POST.
- Also IE browser's protected modes should move enabled for all zones every bit described in THIS POST and zoom score should move laid upwards to 100% every bit described in THIS POST if you lot are running your examine inwards IE browser too.
I am assuming your grid ii hub too node are working fine too forthwith this is fourth dimension to launch software automation test. Write bellow given examine inwards eclipse.
Note : Please take meshwork explorer related code materials from bellow given script if aspect upwards whatever related mistake every bit it is non real stable alongside selenium grid.
Note : Please take meshwork explorer related code materials from bellow given script if aspect upwards whatever related mistake every bit it is non real stable alongside selenium grid.
fillingForm.java
package Grid2; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Platform; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; populace course of written report fillingForm { //Used dataProvider parameter to acquire information from @DataProvider musical note method. //Can bring object array data(browser name, First Name too Last Name) from getNames method. @Test(dataProvider = "getNames") populace void gmailLogin(String browser, String fName, String lName) throws MalformedURLException, InterruptedException { //Initialize DesiredCapabilities null. DesiredCapabilities cap = null; //Initialize browser driver every bit per information received from getNames(). if (browser.equals("firefox")) { //Set firefox browser capabilities for windows platform. cap = DesiredCapabilities.firefox(); cap.setBrowserName("firefox"); cap.setPlatform(Platform.WINDOWS); } else if (browser.equals("chrome")) { //Set chrome browser capabilities for windows platform. cap = DesiredCapabilities.chrome(); cap.setBrowserName("chrome"); cap.setPlatform(Platform.WINDOWS); } else if (browser.equals("iexplore")) { //Set IE browser capabilities for windows platform. cap = DesiredCapabilities.internetExplorer(); cap.setBrowserName("internet explorer"); cap.setPlatform(Platform.WINDOWS); } //Initialize RemoteWebDriver on grid ii node alongside browser capability. RemoteWebDriver driver = novel RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //Open URL inwards requested browsers of node too execute examine steps. driver.get(" "); driver.findElement(By.name("FirstName")).sendKeys(fName); driver.findElement(By.name("LastName")).sendKeys(lName); driver.quit(); } //Created @DataProvider musical note method to render data(browser name, First Name too Last Name) for test @DataProvider(parallel=true) populace Object[][] getNames(){ Object data[][] = novel Object[3][3]; data[0][0] = "firefox"; data[0][1] = "FirstName1"; data[0][2] = "LastName1"; data[1][0] = "chrome"; data[1][1] = "FirstName2"; data[1][2] = "LastName2"; data[2][0] = "iexplore"; data[2][1] = "FirstName3"; data[2][2] = "LastName3"; render data; } }
You tin meet inwards in a higher house test. We cause got used @DataProvider musical note method alongside (parallel=true) to render information to @Test method. So no involve to set @Parameter inwards testng.xml file. Use bellow given testng.xml file to run inwards a higher house test.
testng.xml
<suite name="My Test Suite" verbose="2" parallel="tests" thread-count="5"> <test name="Selenium Grid Test"> <classes> <class name="Grid2.fillingForm" /> </classes> </test> </suite>
Execute inwards a higher house examine too verify execution. It volition run examine inwards parallel inwards dissimilar 3 browsers. This agency you lot tin purpose @DataProvider musical note method alongside (parallel=true) at house of @Parameter to execute examine inwards dissimilar browser parallel using selenium grid 2.
http://www.software-testing-tutorials-automation.com/