Main payoff of selenium grid is nosotros tin run webdriver software exam cases inwards parallel using selenium grid 2 environment to reduce software exam execution time equally described inwards THIS POST. Also It helps us to perform compatibility testing equally it is supporting multiple browsers too. Earlier nosotros accept configured selenium grid 2 hub inwards THIS POST in addition to selenium grid nodes inwards THIS POST inwards simply unmarried machine. Now lets assay to role this environs to execute webdriver software automation exam cases inwards parallel.
Prerequisite : Selenium grid hub in addition to node should live on running equally described inwards previous steps.
I accept created uncomplicated software automation exam to execute it parallel inwards multiple browsers using selenium grid. It volition launch iii browsers (Mozilla firefox, google chrome in addition to IE) parallel in addition to thence execute same software automation exam within each browser.
Note : Please take network explorer related code materials from bellow given script if human face upwards whatever related mistake equally it is non rattling stable amongst selenium grid.
Create bellow hand exam inwards your eclipse projection nether Grid package.
SeGridTest.java
package Grid; import static org.testng.Assert.fail; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; import org.testng.annotations.Test; world flat SeGridTest { WebDriver driver = null; mortal StringBuffer verificationErrors = novel StringBuffer(); // Pass plateform, browser in addition to url parameters to launch browser in addition to URL inwards given plateform. @Parameters({ "platform", "browser", "url" }) @BeforeTest(alwaysRun = true) world void setup(String platform, String browser, String url) throws MalformedURLException { DesiredCapabilities caps = novel DesiredCapabilities(); // Set Platforms based on parameter received from testng.xml. caps.setPlatform(org.openqa.selenium.Platform.WINDOWS); // Set browser capability based on parameter received from testng.xml. if (browser.equalsIgnoreCase("Internet Explorer")) caps = DesiredCapabilities.internetExplorer(); if (browser.equalsIgnoreCase("Firefox")) caps = DesiredCapabilities.firefox(); if (browser.equalsIgnoreCase("chrome")) caps = DesiredCapabilities.chrome(); // Open browser on grid node. driver = novel RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),caps); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); driver.manage().window().maximize(); // Open URL of Application driver.get(url); } // Simple exam method to execute. @Test(description = "Wait for push enabled") world void waitForButtonEnabled() throws InterruptedException { WebDriverWait hold off = novel WebDriverWait(driver, 15); wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#submitButton"))); driver.findElement(By.xpath("//input[@id='submitButton']")).click(); } // Simple exam method to execute. @Test(description = "Wait for push enabled", dependsOnMethods = { "waitForButtonEnabled" }) world void testCalc() throws InterruptedException { driver.navigate().to(" "); driver.findElement(By.xpath("//input[@id='2']")).click(); driver.findElement(By.xpath("//input[@id='plus']")).click(); driver.findElement(By.xpath("//input[@id='5']")).click(); driver.findElement(By.xpath("//input[@id='equals']")).click(); String trial = driver.findElement(By.xpath("//input[@id='Resultbox']")).getAttribute("value"); // Get Browser advert in addition to version. Capabilities caps = ((RemoteWebDriver) driver).getCapabilities(); String browserName = caps.getBrowserName(); String browserVersion = caps.getVersion(); // Get OS name. String bone = System.getProperty("os.name").toLowerCase(); // Print exam trial amongst browser in addition to OS version detail. System.out.println("OS = " + bone + ", Browser = " + browserName + " "+ browserVersion + " Test Result = " + result); } @AfterTest world void afterTest() { // Close the browser driver.quit(); String verificationErrorString = verificationErrors.toString(); if (!"".equals(verificationErrorString)) { fail(verificationErrorString); } } }
If you lot remember, We accept used parallel inwards testng.xml file to execute software automation tests inwards parallel inwards selenium webdriver equally described inwards THIS POST. We volition role same affair hither but using selenium grid.
You tin see, We accept used parameters (plateform, browser in addition to url) amongst setup method. All these parameters volition live on served from testnx.xml file equally bellow. We accept configured iii exam inwards bellow given xml file amongst unlike browser parameter to run exam inwards unlike browsers. Create bellow given testng.xml file nether your projection in addition to run it.
testng.xml
<!--Set thread-count = 3 to execute exam parallel inwards 3 max browsers at at time. You tin increase it--> <suite name="Parallel Tests" verbose="1" thread-count="3" parallel="tests"> <tests> <!--Set exam parameters to execute exam inwards IE browser on windows plateform.--> <test name="Windows+IE Test" > <parameters> <parameter name="platform" value="Windows" /> <parameter name="browser" value="Internet Explorer" /> <parameter name="url" value=" " /> </parameters> <classes> <class name="Grid.SeGridTest" /> </classes> </test> <!--Set exam parameters to execute exam inwards Firefox browser on windows plateform.--> <test name="Windows+Firefox Test" > <parameters> <parameter name="platform" value="Windows" /> <parameter name="browser" value="Firefox" /> <parameter name="url" value=" " /> </parameters> <classes> <class name="Grid.SeGridTest" /> </classes> </test> <!--Set exam parameters to execute exam inwards chrome browser on windows plateform.--> <test name="Windows+chrome Test" > <parameters> <parameter name="platform" value="Windows" /> <parameter name="browser" value="chrome" /> <parameter name="url" value=" " /> </parameters> <classes> <class name="Grid.SeGridTest" /> </classes> </test> </tests> </suite>
Now, execute inwards a higher house testng.xml file in addition to uncovering exam execution process. It volition launch iii browsers parallel in addition to thence execute tests inwards all iii browsers. At the terminate of exam execution, It volition impress trial inwards console equally bellow.
OS = windows 7, Browser = chrome 43.0.2357.132 Test Result = seven OS = windows 7, Browser = network explorer 8 Test Result = seven OS = windows 7, Browser = firefox 38.0.5 Test Result = 7
Testng trial volition looks similar bellow.
This is the agency to execute selenium webdriver software automation test inwards parallel multiple browsers using selenium grid 2 to perform compatibility testing.
http://www.software-testing-tutorials-automation.com/