Download Usage Of "maxInstances" In Grid 2 To Set Allowed Max Number Of Browser Instances - 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
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;
public class fillingForm {
// Used dataProvider parameter to get data from @DataProvider annotation method.
// Can accept object array data(browser name, First Name and Last Name) from getNames method.
@Test(dataProvider = "getNames")
public void gmailLogin(String browser, String fName, String lName) throws MalformedURLException, InterruptedException {
System.out.println(browser);
// Initialize DesiredCapabilities null.
DesiredCapabilities cap = null;
// Initialize browser driver as per data 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 2 node with browser capability.
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Pause test for 20 minutes to check exactly how many concurrent browsers opening at same time.
Thread.sleep(20000);
// Open URL in requested browsers of node and execute test steps.
driver.get("http://only-testing-blog.blogspot.in/2014/05/form.html");
driver.findElement(By.name("FirstName")).sendKeys(fName);
driver.findElement(By.name("LastName")).sendKeys(lName);
// Close browser instance.
driver.quit();
}
// Created @DataProvider annotation method to supply data(browser name, First Name and Last Name) for test
@DataProvider(parallel = true)
public Object[][] getNames() {
Object data[][] = new 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";
return data;
}
}
Calc.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.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class Calc {
// Used dataProvider parameter to get data from @DataProvider annotation method.
// Can accept object array data(browser name, num1, num2 and expected sum value) from getNames method.
@Test(dataProvider = "getCalcData")
public static void calcTest(String browser, String num1, String num2, String expSumNum) throws MalformedURLException, InterruptedException {
System.out.println(browser);
// Initialize DesiredCapabilities null.
DesiredCapabilities cap = null;
// Initialize browser driver as per data received from getCalcData().
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 2 node with browser capability.
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Pause test for 20 minutes to check exactly how many concurrent browsers opening at same time.
Thread.sleep(20000);
driver.get("http://only-testing-blog.blogspot.in/2014/04/calc.html");
driver.findElement(By.xpath("//input[@id='Resultbox']")).clear();
driver.findElement(By.xpath("//input[@id='" + num1 + "']")).click();
driver.findElement(By.xpath("//input[@id='plus']")).click();
driver.findElement(By.xpath("//input[@id='" + num2 + "']")).click();
driver.findElement(By.xpath("//input[@id='equals']")).click();
// Get actual result and compare with expected result.
String strResult = driver.findElement(By.xpath("//input[@id='Resultbox']")).getAttribute("value");
int actualResult = Integer.parseInt(strResult);
int expectedResult = Integer.parseInt(expSumNum);
Assert.assertEquals(actualResult, expectedResult);
// Close browser instance.
driver.quit();
}
// Created @DataProvider annotation method to supply data(browser name, num1, num2 and expected sum value) for test
@DataProvider(parallel = true)
public Object[][] getCalcData() {
Object data[][] = new Object[3][4];
data[0][0] = "firefox";
data[0][1] = "1";
data[0][2] = "3";
data[0][3] = "4";
data[1][0] = "chrome";
data[1][1] = "2";
data[1][2] = "5";
data[1][3] = "7";
data[2][0] = "iexplore";
data[2][1] = "3";
data[2][2] = "5";
data[2][3] = "8";
return data;
}
}
testng.xml
<suite name="My Test Suite" verbose="2" parallel="classes" thread-count="15">
<test name="Selenium Grid Test">
<classes>
<class name="Grid2.fillingForm" />
<class name="Grid2.Calc" />
</classes>
</test>
</suite>
Create above given 2 software automation tests in eclipse and observe its execution with above testng.xml file. It can launch 1 IE browser at a time but i wants to execute my both tests on 2 IE browsers concurrently.
To launch your above 2 software automation tests on 6 concurrent browser at same time, you need to restart your node with bellow given command where i have set maxInstances=2 for all three browser instances.
- Close current node using CTRL+c key press
- Run bellow given command to register node with hub with maxInstances=2 for all three browser instances.
java -jar selenium-server-standalone-2.52.0.jar -role node -Dwebdriver.ie.driver="D:/IEDriverServer.exe" -Dwebdriver.chrome.driver="D:/chromedriver.exe" -hub http://localhost:4444/grid/register -port 5566 -browser browserName=firefox,maxInstances=2 -browser browserName=chrome,maxInstances=2 -browser browserName=iexplore,maxInstances=2
- maxInstances=2 : It will tell node to prepare 2 browsers instances for that specific browser.
Download Usage Of "maxInstances" In Grid 2 To Set Allowed Max Number Of Browser Instances - 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.