Usage Of maxInstances In Grid two To Set Allowed Max Number Of Browser Instances

"maxInstances" is configuration parameter which is used during selenium grid 2 node configuration. Using "maxInstances" inwards selenium grid 2, We tin gear upwards "how many max publish of same browser instances are allowed to opened upwards in addition to 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 verbalise over ane illustration to cleat your doubts.

If you lot launch selenium grid 2 node amongst default configuration every bit described inwards THIS POST, It volition set 1 IE, v Firefox in addition to v chrome browsers instances on node machine every bit bellow.



With this config, you lot tin run your software automation tests inwards parallel on 1 IE browser, v Firefox browsers in addition to v chrome browser at a time. That way node is non capable to run your tests inwards 2 IE browsers or half-dozen Firefox browsers or half-dozen chrome browsers at a time. Let's encounter it practically to verify how it industrial plant if non gear upwards required browser instances on node.


Example Scenario:  I stimulate got two software automation examine cases every bit bellow in addition to i wants to execute both of them inwards parallel on 2 IE, 2 Google chrome in addition to 2 Firefox browsers at the same time. Means it should opened upwards half-dozen browser at a fourth dimension on node machine to execute both software automation examine cases inwards all 3 browsers concurrently. Supposing i am using default node configuration (1 IE, v Chrome in addition to v Firefox instances at a time) to run to a higher house scenario. It volition starting fourth dimension executing examine inwards all half-dozen browser instances at the same time? No.. First it volition launch v browser instances(1 IE, 2 Google chrome in addition to 2 Firefox) only in addition to execute examine on them. Remaining 1 IE browser instance volition hold upwards launched in addition to executes examine ane time previous IE instance completes examine execution in addition to getting closed. That way your examine volition non run on 2 IE browser instances at the same fourth dimension using this node configuration.

Launch selenium grid hub every bit described inwards THIS POST and selenium grid node every bit described inwards THIS POST in addition to and hence execute bellow given tests. 

Note : Please take meshing explorer related code materials from bellow given script if human face upwards whatever related mistake every bit it is non real stable amongst 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 shape fillingForm {   // Used dataProvider parameter to larn information from @DataProvider notation method.  // Can stimulate got object array data(browser name, First Name in addition to 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 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 2 node amongst 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 twenty minutes to cheque precisely how many concurrent browsers opening at same time.   Thread.sleep(20000);    // Open URL inwards requested browsers of node in addition to execute examine steps.   driver.get(" ");   driver.findElement(By.name("FirstName")).sendKeys(fName);   driver.findElement(By.name("LastName")).sendKeys(lName);    // Close browser instance.   driver.quit();  }   // Created @DataProvider notation method to render data(browser name, First Name in addition to 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 shape Calc {   // Used dataProvider parameter to larn information from @DataProvider notation method.  // Can stimulate got object array data(browser name, num1, num2 in addition to expected amount 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 every bit 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 amongst 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 twenty minutes to cheque precisely how many concurrent browsers opening at same time.   Thread.sleep(20000);    driver.get(" ");   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 trial in addition to compare amongst 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 notation method to render data(browser name, num1, num2 in addition to expected amount 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 to a higher house given 2 software automation tests inwards eclipse in addition to notice its execution amongst to a higher house testng.xml file. It tin launch 1 IE browser at a fourth dimension but i wants to execute my both tests on 2 IE browsers concurrently.

To launch your to a higher house 2 software automation tests on half-dozen concurrent browser at same time, you lot take to restart your node amongst bellow given command where i stimulate 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 amongst 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 produce 2 browsers instances for that specific browser.
Now access URL = http://localhost:4444/grid/console inwards browser. It volition looks similar bellow.



Rerun your testng.xml file using to a higher house node configuration. It volition launch half-dozen browsers (2 FF, 2 Chrome in addition to 2 IE) at a fourth dimension in addition to run both tests on all of them concurrently.

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

This way you lot tin command max publish of allowed browser instances of same browser using maxInstances configuration parameter of grid 2.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post