Saturday, September 1, 2018

Usage Of Maxinstances Inwards Grid Ii To Railroad Train Allowed Max Give Away Of Browser Instances

| Saturday, September 1, 2018
"maxInstances" is configuration parameter which is used during selenium grid 2 node configuration. Using "maxInstances" inward selenium grid 2, We tin john laid "how many max release of same browser instances are allowed to opened upwards as well as run software examine at same time". "maxInstances" tells node machine to non allow to a greater extent than than allowed instances on that specific machine at the same time. Lets utter over ane representative to cleat your doubts.

If yous launch selenium grid 2 node alongside default configuration equally described inward THIS POST, It volition set 1 IE, five Firefox as well as five chrome browsers instances on node machine equally bellow.



With this config, yous tin john run your software automation tests inward parallel on 1 IE browser, five Firefox browsers as well as five chrome browser at a time. That agency node is non capable to run your tests inward 2 IE browsers or vi Firefox browsers or vi chrome browsers at a time. Let's run into it practically to verify how it industrial plant if non laid required browser instances on node.


Example Scenario:  I cause got two software automation examine cases equally bellow as well as i wants to execute both of them inward parallel on 2 IE, 2 Google chrome as well as 2 Firefox browsers at the same time. Means it should opened upwards vi browser at a fourth dimension on node machine to execute both software automation examine cases inward all 3 browsers concurrently. Supposing i am using default node configuration (1 IE, five Chrome as well as five Firefox instances at a time) to run higher upwards scenario. It volition offset executing examine inward all vi browser instances at the same time? No.. First it volition launch five browser instances(1 IE, 2 Google chrome as well as 2 Firefox) only as well as execute examine on them. Remaining 1 IE browser instance volition move launched as well as executes examine ane time previous IE instance completes examine execution as well as getting closed. That agency your examine volition non run on 2 IE browser instances at the same fourth dimension using this node configuration.

Launch selenium grid hub equally described inward THIS POST and selenium grid node equally described inward THIS POST as well as thence execute bellow given tests. 

Note : Please withdraw meshing explorer related code materials from bellow given script if human face upwards whatever related fault equally 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 flat fillingForm {   // Used dataProvider parameter to instruct information from @DataProvider tone method.  // Can convey object array data(browser name, First Name as well as Last Name) from getNames method.  @Test(dataProvider = "getNames")  populace void gmailLogin(String browser, String fName, String lName) throws MalformedURLException, InterruptedException {   System.out.println(browser);    // Initialize DesiredCapabilities null.   DesiredCapabilities cap = null;    // Initialize browser driver equally 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 2 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);    // Pause examine for xx minutes to cheque precisely how many concurrent browsers opening at same time.   Thread.sleep(20000);    // Open URL inward requested browsers of node as well as execute examine steps.   driver.get("aa/search?q=how-to-configure-selenium-grid-2-node");   driver.findElement(By.name("FirstName")).sendKeys(fName);   driver.findElement(By.name("LastName")).sendKeys(lName);    // Close browser instance.   driver.quit();  }   // Created @DataProvider tone method to provide data(browser name, First Name as well as 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;  } }

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;  populace flat Calc {   // Used dataProvider parameter to instruct information from @DataProvider tone method.  // Can convey object array data(browser name, num1, num2 as well as expected total value) from getNames method.  @Test(dataProvider = "getCalcData")  populace 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 equally per information 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 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);    // Pause examine for xx minutes to cheque precisely how many concurrent browsers opening at same time.   Thread.sleep(20000);    driver.get("aa/search?q=how-to-configure-selenium-grid-2-node");   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 effect as well as compare alongside 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 tone method to provide data(browser name, num1, num2 as well as expected total value) for test  @DataProvider(parallel = true)  populace Object[][] getCalcData() {   Object data[][] = novel 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";    render 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 higher upwards given 2 software automation tests inward eclipse as well as give away its execution alongside higher upwards testng.xml file. It tin john launch 1 IE browser at a fourth dimension but i wants to execute my both tests on 2 IE browsers concurrently.

To launch your higher upwards 2 software automation tests on vi concurrent browser at same time, yous yell for to restart your node alongside bellow given command where i cause got set maxInstances=2 for all 3 browser instances.
  • Close electrical flow node using CTRL+c primal press
  • Run bellow given command to register node alongside hub with maxInstances=2 for all 3 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 volition say node to ready 2 browsers instances for that specific browser.
Now access URL = http://localhost:4444/grid/console inward browser. It volition looks similar bellow.



Rerun your testng.xml file using higher upwards node configuration. It volition launch vi browsers (2 FF, 2 Chrome as well as 2 IE) at a fourth dimension as well as run both tests on all of them concurrently.

Note : You tin john laid whatever value for maxInstances fro whatever browser. 
Example : -browser browserName=firefox,maxInstances=25 volition say node to laid 25 firefox browser instances.

This way yous tin john command max release of allowed browser instances of same browser using maxInstances configuration parameter of grid 2.

Related Posts