Download How To Use Selenium Grid 2 To Run WebDriver Test Cases In Parallel - Software Testing Tutorials graphic type that can be scaled to use with the Silhouette Cameo or Cricut. An SVG's size can be increased or decreased without a loss of quality. All of our downloads include an image, Silhouette file, and SVG file. It should be everything you need for your next project. Our SVG files can be used on adhesive vinyl, heat transfer and t-shirt vinyl, or any other cutting surface
Note : Please remove internet explorer related code stuff from bellow given script if face any related error as it is not very stable with selenium grid.
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;
public class SeGridTest {
WebDriver driver = null;
private StringBuffer verificationErrors = new StringBuffer();
// Pass plateform, browser and url parameters to launch browser and URL in given plateform.
@Parameters({ "platform", "browser", "url" })
@BeforeTest(alwaysRun = true)
public void setup(String platform, String browser, String url) throws MalformedURLException {
DesiredCapabilities caps = new 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 = new 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 test method to execute.
@Test(description = "Wait for button enabled")
public void waitForButtonEnabled() throws InterruptedException {
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#submitButton")));
driver.findElement(By.xpath("//input[@id='submitButton']")).click();
}
// Simple test method to execute.
@Test(description = "Wait for button enabled", dependsOnMethods = { "waitForButtonEnabled" })
public void testCalc() throws InterruptedException {
driver.navigate().to("http://only-testing-blog.blogspot.in/2014/04/calc.html");
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 result = driver.findElement(By.xpath("//input[@id='Resultbox']")).getAttribute("value");
// Get Browser name and version.
Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();
String browserName = caps.getBrowserName();
String browserVersion = caps.getVersion();
// Get OS name.
String os = System.getProperty("os.name").toLowerCase();
// Print test result with browser and OS version detail.
System.out.println("OS = " + os + ", Browser = " + browserName + " "+ browserVersion + " Test Result = " + result);
}
@AfterTest
public void afterTest() {
// Close the browser
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
If you remember, We have used parallel in testng.xml file to execute software automation tests in parallel in selenium webdriver as described in THIS POST. We will use same thing here but using selenium grid.
You can see, We have used parameters (plateform, browser and url) with setup method. All these parameters will be served from testnx.xml file as bellow. We have configured three test in bellow given xml file with different browser parameter to run test in different browsers. Create bellow given testng.xml file under your project and run it.
testng.xml
<!--Set thread-count = 3 to execute test parallel in 3 max browsers at at time. You can increase it-->
<suite name="Parallel Tests" verbose="1" thread-count="3" parallel="tests">
<tests>
<!--Set test parameters to execute test in 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="http://only-testing-blog.blogspot.in/2014/01/textbox.html" />
</parameters>
<classes>
<class name="Grid.SeGridTest" />
</classes>
</test>
<!--Set test parameters to execute test in 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="http://only-testing-blog.blogspot.in/2014/01/textbox.html" />
</parameters>
<classes>
<class name="Grid.SeGridTest" />
</classes>
</test>
<!--Set test parameters to execute test in 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="http://only-testing-blog.blogspot.in/2014/01/textbox.html" />
</parameters>
<classes>
<class name="Grid.SeGridTest" />
</classes>
</test>
</tests>
</suite>
Now, execute above testng.xml file and observe test execution process. It will launch three browsers parallel and then execute tests in all three browsers. At the end of test execution, It will print result in console as bellow.
OS = windows 7, Browser = chrome 43.0.2357.132 Test Result = 7
OS = windows 7, Browser = internet explorer 8 Test Result = 7
OS = windows 7, Browser = firefox 38.0.5 Test Result = 7
Testng result will looks like bellow.
Download How To Use Selenium Grid 2 To Run WebDriver Test Cases In Parallel - Software Testing Tutorials All SVG file downloads also come bundled with DXF, PNG, and EPS file formats. All designs come with a small business commercial license. These SVG cut files are great for use with Silhouette Cameo or Cricut and other Machine Tools.