We learnt most "maxInstances" inward my PREVIOUS POST. "maxSession" is about other configuration parameter which helps to laid upwards max allowed sessions to run at a fourth dimension on that specific node. Here session agency position out of concurrent browsers inward damage of all browser. It volition non allow that specific node to opened upwards browser to a greater extent than than value of "maxSession". Let's sympathise alongside real unproblematic instance scenario.
Example scenario : Let's regard unproblematic example. I wants to run two software automation essay out cases as well as both should run on two unlike browsers concurrently(Firefox as well as Google chrome) using selenium Grid. But my about other status is, Node should opened upwards max two browser at a time. In this case, only "maxInstances" volition non industrial plant for me but i postulate to usage maxSession" inward node configuration. In this instance i tin laid upwards maxSession = two for node to restrain only two browsers at a time. Let's sympathise how it industrial plant alongside practical example.
Create bellow given software automation test cases inward eclipse alongside given testng.xml file.
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; world course of didactics fillingForm { // Used dataProvider parameter to acquire information from @DataProvider notation method. // Can convey object array data(browser name, First Name as well as Last Name) from getNames method. @Test(dataProvider = "getNames") world 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.ANY); cap.setVersion("8"); }*/ // Initialize RemoteWebDriver on grid two 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 essay out for xx minutes to banking concern jibe precisely how many concurrent browsers opening at same time. Thread.sleep(20000); // Open URL inward requested browsers of node as well as execute essay out 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 provide data(browser name, First Name as well as Last Name) for test @DataProvider(parallel = true) world Object[][] getNames() { Object data[][] = novel Object[2][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; world course of didactics Calc { // Used dataProvider parameter to acquire information from @DataProvider notation method. // Can convey object array data(browser name, num1, num2 as well as expected total value) from getNames method. @Test(dataProvider = "getCalcData") world 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("iexplore"); cap.setPlatform(Platform.ANY); cap.setVersion("8"); }*/ // Initialize RemoteWebDriver on grid two 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 essay out for xx minutes to banking concern jibe 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 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 notation method to provide data(browser name, num1, num2 as well as expected total value) for test @DataProvider(parallel = true) world Object[][] getCalcData() { Object data[][] = novel Object[2][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="6"> <test name="Selenium Grid Test"> <classes> <class name="Grid2.fillingForm" /> <class name="Grid2.Calc" /> </classes> </test> </suite>
without using "maxInstances"
First of all let's run our software automation test without using "maxInstances" as well as and hence nosotros volition usage "maxInstances" inward node configuration to banking concern jibe how it works.
First of all let's run our software automation test without using "maxInstances" as well as and hence nosotros volition usage "maxInstances" inward node configuration to banking concern jibe how it works.
- Start grid two hub. You tin sentiment THIS POST to know how to starting fourth dimension hub.
- Open dominance prompt as well as navigate to D: get inward dominance prompt where selenium server jounce file, IEDriver server file as well as chromedriver file is stored.
- Start grid two node using bellow given command. You tin sentiment THIS POST to know prerequisite to starting fourth dimension grid two node.
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
using "maxInstances"
Now execute higher upwards given 2 software automation test cases using testng.xml file as well as let out essay out execution sequence. It volition opened upwards four browsers at the same fourth dimension as well as execute both essay out cases parallel inward all four browsers.
- Close electrical flow running node using CTRL+c keys.
- Start node using bellow given command. Now nosotros have got used -maxSession two inward bellow given dominance to boundary max whatever two browser instances at a time.
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 -maxSession 2
Now run testng.xml file to execute higher upwards given 2 software automation test cases as well as let out essay out execution sequence. It volition opened upwards only two browsers at a fourth dimension as well as two requests volition hold off for slot to move costless equally shown inward bellow given image. You tin come across it past times refreshing console page when your tests starting fourth dimension execution.
Once previous two requests volition consummate execution as well as unopen browser instance, Remaining two requests volition move executed past times opening novel two browser instances. Means you lot volition come across max two browser instances at a fourth dimension on your grid node machine to execute tests.
This way, maxSession volition laid upwards max allowed browsers at a fourth dimension to execute essay out on grid node.
http://www.software-testing-tutorials-automation.com/
Great, thanks for sharing this post.Much thanks again. Awesome.
ReplyDeletebest selenium online training
online training for selenium