Showing posts with label Selenium 2. Show all posts
Showing posts with label Selenium 2. Show all posts

Monday, September 3, 2018

Appium - Perform Longpress Using Touchaction Inward Android Dialer App

Appium - Perform Longpress Using Touchaction Inward Android Dialer App

24Sometimes you lot take away to press together with hold(long press) an element for few seconds to decease required effect In your android software app. In this instance nosotros tin use longPress(org.openqa.selenium.WebElement el) method of TouchAction flat In appium automation test. Earlier nosotros accept used longPress method to generate activeness chain of DRAG AND DROP, SWIPE ACTION together with MULTI TOUCH ACTION. Here I am presenting uncomplicated representative on exact usage of longPress method of TouchAction class In appium software automation test.

App To Use In This Test
We volition utilization android mobile Dialler app In this representative to sympathize usage of LongPress method. Dialler app volition live on Installed yesteryear default In all android devices together with then no take away to Install It.

Aim To Achieve
On dialler pad, 0 push has 2 functions. 1. It volition dial 0 on normal press. 2. It volition dial + on long press. Try It manually first.

In our appium software automation test, We volition long press 0 push of dialler pad to dial + equally shown In bellow Image. It volition type + In dial set out textbox.


Create And Run Android Appium LongPress Test
Create novel flat file DialPad.java nether your project's parcel In eclipse together with re-create glue bellow given android appium software seek out script In It.

DialPad.java
package Android;  import io.appium.java_client.TouchAction; import io.appium.java_client.android.AndroidDriver;  import java.net.URL; import java.util.concurrent.TimeUnit;  import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  populace flat DialPad {  AndroidDriver driver;   @BeforeTest  populace void setUp() throws Exception {   DesiredCapabilities capabilities = novel DesiredCapabilities();   capabilities.setCapability("deviceName", "ZX1B32FFXF");   capabilities.setCapability("browserName", "Android");   capabilities.setCapability("platformVersion", "4.4.2");   capabilities.setCapability("platformName", "Android");   capabilities.setCapability("appPackage", "com.android.dialer");   capabilities.setCapability("appActivity","com.android.dialer.DialtactsActivity");   driver = novel AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);  }   @Test  populace void dial() {   //Click on dial pad push to opened upwards dialer pad.   driver.findElementById("com.android.dialer:id/dialpad_button").click();   //Create object of TouchAction class.   TouchAction Action = novel TouchAction(driver);   //Create activeness chain using TouchAction flat reference to perform long press activeness on push 0 of dialer pad.   Action.longPress(driver.findElement(By.name("0"))).perform();   //Get the effect from dial text box.   String effect = driver.findElementById("com.android.dialer:id/digits").getText();   //Compare actual together with expected effect using testng assertion.   Assert.assertEquals(result, "+", "Actual value is : "+ result+ " did non fit amongst expected value: +");    }   @AfterClass  populace void tearDown() {   driver.quit();  } }

As you lot tin encounter In inward a higher house android appium software automation seek out script, 
  • First It volition launch dialler pad app using given parcel together with activity name.
  • Open dialler pad yesteryear clicking on dial pad button.
  • Action.longPress method Is used to press together with concur 0 push on dial pad.
  • Next disputation volition decease text from dial text box.
  • Used testng assertion Assert.assertEquals to compare actual together with expected result. You tin larn to a greater extent than close testng and It's assertions on THIS PAGE.
Run inward a higher house representative using testng together with uncovering execution In your android device screen. It volition dial + yesteryear long press 0 button.

This Is the means of using longpress method of TouchAction flat to long press on whatever chemical component of your android software app.
What Is Selenium Grid 2? When To Purpose Grid?

What Is Selenium Grid 2? When To Purpose Grid?

Earlier nosotros learnt selenium WebDriver/Selenium 2 tutorials amongst practical examples together with you lot tin honour all webdriver tutorials links on THIS PAGE. Selenium Grid 2 may last novel for close of you lot but you lot must needs to acquire It because If you lot wants to run your selenium software tests In multiple browser versions together with OS parallel hence you lot ask Selenium Grid 2. Let's endeavor to sympathise what Is selenium Grid together with when to purpose It.

What Is Selenium Grid 2?
Selenium Grid Is simply about other projection of selenium. Selenium grid render us facility for distributed software essay execution. Using selenium Grid, We tin execute our selenium WebDriver software tests In unlike browsers, unlike browsers versions together with unlike browser versions running on unlike operating systems In parallel at the same time.

Basically selenium grid has 1 hub together with multiple nodes. Each node amongst same or unlike environments (As per your requirement) to executed tests In parallel.

Bellow given Images shows representative construction of  selenium Grid. You tin run across at that spot Is unmarried Hub machine connected to multiple nodes(with unlike configuration) machine. You ask node machine equally per your requirement.

When To Use Grid 2?
Main questions Is what are the benefits of selenium grid together with why nosotros needs to purpose It. Mainly at that spot are ii reasons behind usage of selenium grid In software testing Industry.
  1. To perform compatibility testing - You tin run same essay In multiple environments hence that It volition last really slowly for you lot to perform compatibility testing using selenium grid.
  2. To trim down essay execution time - As you lot know, nosotros tin run same essay In multiple machines at same fourth dimension hence It volition trim down your essay execution time.
Using selenium grid, you lot tin speedup software essay execution process. Supposing your fifty software automation essay cases takes five hours to consummate execution In 1 machine hence selenium grid amongst five nodes configuration volition conduct keep solely 1 hr to execute fifty essay cases. This Is the primary create goodness of using selenium Grid.

NEXT POST volition depict you lot how to configure selenium grid from scratch to run selenium WebDriver software essay cases.

Selenium Grid Ii Configuration - Setup Hub To Live Selenium Webdriver Tests

Selenium Grid Ii Configuration - Setup Hub To Live Selenium Webdriver Tests

We learnt what is Selenium Grid 2 together with when to usage it inward PREVIOUS POST. Selenium Grid is approximately other projection of selenium thus y'all hollo for to configure selenium grid 2 from scratch to execute selenium webdriver software exam cases parallel in grid. Let's elbow grease to configure selenium grid In unmarried machine together with and thus nosotros volition run selenium webdriver tests In It.

As described In my previous post, We hollo for to setup 1 hub together with multiple nodes (number of nodes depends on your requirement) to execute selenium webdriver software exam cases parallel on selenium grid nodes.

What Is Hub?
In selenium grid, Hub is a fundamental indicate which have software exam requests together with transportation those software exam requests to nodes for execution. In our representative of selenium webdriver, When nosotros kickoff executing software exam on selenium grid, Grid hub volition have together with create create exam requests together with and thus transportation them to registered node machine. We tin configure node on same machine or dissimilar machines too. We volition acquire to a greater extent than nearly nodes inward upcoming post.

Setting Up Selenium Grid ii Hub
To execute selenium webdriver exam cases parallel In selenium grid, We hollo for to laid upwards selenium grid hub In your machine which volition supply available capabilities together with configuration to webdriver tests.

Step 1 : Download Selenium Standalone Server jar
You tin download selenium standalone server from THIS PAGE.

Current latest version of selenium standalone server is 2.52.0 thus y'all volition acquire "selenium-server-standalone-2.52.0.jar" file. Put it inward D: drive.

Note : If your selenium standalone server version is dissimilar than usage that version release inward all bellow steps. Otherwise it volition non run for you.

Step ii : Start Selenium Grid Hub
To kickoff hub,
  1. Open ascendance prompt
  2. Navigate to D: create past times typing ascendance D: inward ascendance prompt.
  3. Type bellow given ascendance syntax inward ascendance prompt and press ENTER button.
java -jar selenium-server-standalone-2.52.0.jar -port 4444 -role hub

Command elements
  • selenium-server-standalone-2.52.0.jar -> Selenium standalone server jounce file version. Modify It every bit per your jounce file version inward higher upwards ascendance if it is non 2.52.0.
  • 4444 -> Port used past times hub to brain nodes.
Note : Please restart hub and  if seem upwards whatsoever effect on whatsoever phase during test. To restart grid ii hub
  • Press CTRL+c keys of keyboard to shutdown node.
  • Run higher upwards ascendance in 1 lawsuit once to a greater extent than to register node amongst hub.
Verify whether grid hub is running fine
It volition exhibit y'all message -> "Selenium Grid hub is upwards together with running." every bit shown inward bellow image.

Now y'all tin access selenium grid console using URL : http://localhost:4444/grid/console. Open this URL inward whatsoever browser. It volition exhibit y'all page similar bellow.

That way selenium grid hub is configured properly together with develop to use. We volition acquire how to configure nodes for seleniun grid ii hub inward NEXT POST.

Sunday, September 2, 2018

Selenium Grid Two Tutorial

Selenium Grid Two Tutorial

This selenium grid ii tutorial volition need y'all how to purpose selenium grid ii to perform distributed software examination automation inward companionship to speedup software examination execution process. Using selenium grid 2, You tin execute your software automation examination inward unlike OS, unlike versions of browser as well as execute software automation tests inward parallel. Follow the tutorial links given at bellow to larn selenium grid ii from scratch.

 tutorial volition need y'all how to purpose selenium grid  Selenium Grid ii Tutorial


STAY TUNED.. MORE TUTORIALS ARE COMING SOON...

How To Configure Selenium Grid Two Node To Piece Of Occupation Webdriver Test

How To Configure Selenium Grid Two Node To Piece Of Occupation Webdriver Test

As described In my EARLIER POST, Selenium grid 2 Is useful to execute webdriver software tests on multiple nodes In parallel. So nosotros take away to set upwards selenium grid 2 nodes for webdriver software examination execution. But earlier that, Your selenium grid hub should hold upwards configured as well as inward running fashion equally described inward my PREVIOUS POST. Now lets configure selenium grid 2 unmarried node to execute webdriver software automation tests inward parallel inward selenium grid.

Note : Here nosotros are configuring selenium grid node on same machine where selenium grid hub is running for your slowly understanding. Later on nosotros volition larn how to configure hub as well as nodes on dissimilar machines as well as run software automation examination on it.

What Is Node
Node is the indicate which convey examination requests from hub as well as execute them. We tin plough over the sack configure node inward such a way to execute tests inward parallel on dissimilar browsers at the same time. Also nosotros tin plough over the sack laid max position out of browsers allowed to run examination at a time, timeout etc. inward upcoming posts.

Registering Selenium Grid 2 Node To Hub
We take away to register selenium grid node to hub hence that hub tin plough over the sack sympathise where to run software automation tests when have asking for examination execution. But earlier that delight read bellow given prerequisites.

Prerequisites :
  • Selenium grid hub should hold upwards In running fashion equally described In previous post.
  • "chromedriver.exe" file should hold upwards located inward D: drive. It volition hold upwards needed to run tests inward google chrome browser. Read THIS POST to know from where to download it if yous produce non have "chromedriver.exe" file.
  • "IEDriverServer.exe" file should hold upwards located in D: drive. It volition hold upwards needed to run tests inward Internet explorer browser.Read THIS POST to know from where to download it if yous produce non have "IEDriverServer.exe" file.
  • Internet explorer browser's protected modes should hold upwards enabled for all zones equally described in THIS POST and browser zoom marking should hold upwards laid to 100% equally described inward THIS POST.
Now follow the steps given bellow.
  1. Open unopen to other ascendance prompt (Separate than hub ascendance prompt).
  2. Navigate to D: motility past times typing ascendance D: inward ascendance prompt.
  3. Type bellow given ascendance syntax inward ascendance prompt as well as press ENTER button.
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

Command elements
  • selenium-server-standalone-2.52.0.jar -> Selenium standalone server jolt file. Modify It equally per your jolt file version inward in a higher house ascendance if it is non 2.52.0.
  • 5566 -> port position out which volition hold upwards used past times node.
  • http://localhost:4444/grid/register : URL to register node where hub is running. Our electrical current configuration is running hub as well as nodes on same machine hence localhost inward URL volition operate here. 
  • Note : If node Is running on dissimilar machine than the hub machine as well as hence yous take away to supervene upon IP address of hub machine alongside "localhost" inward in a higher house URL.
  • -Dwebdriver.ie.driver="D:/IEDriverServer.exe" : Set path of IEDriverServer.exe file for node to run examination inward network explorer browser.
  • -Dwebdriver.chrome.driver="D:/chromedriver.exe" : Set path of chromedriver.exe file for node to run examination inward google chrome browser.
Note : Please restart hub as well as node if confront whatsoever effect on whatsoever phase during test. To restart grid 2 node
  • Press CTRL+c keys of keyboard to shutdown node.
  • Run inward a higher house ascendance in 1 lawsuit once again to register node alongside hub.
We tin plough over the sack besides configure how many browsers yous take away on specific node(Example : 2 Firefox, iii chrome as well as iii IE browsers) as well as max how many allowed browsers to run on specific node. We volition larn it inward upcoming posts.

Verify whether grid node is running fine
When yous type inward a higher house ascendance In ascendance prompt, It volition exhibit yous message similar "The node is registered to the hub as well as cook to use" equally shown In bellow Image. That agency yous stimulate got configured node properly.


Now If yous access URL : http://localhost:4444/grid/console. It volition exhibit yous page similar bellow.

You tin plough over the sack see, in that place are dissimilar browsers similar 1 IE, five Firefox as well as five chrome browsers which yous tin plough over the sack utilisation to run your software automation test. Now, Selenium grid is cook to utilisation where hub as well as 1 node are running on same machine.

Now supposing nosotros stimulate got 1 examination illustration as well as wants to execute it inward parallel inward dissimilar iii browsers. Can nosotros produce it using this configuration? Answer is Yes.. View my NEXT POST to know how to produce it using selenium grid 2.
How To Purpose Selenium Grid Two To Piece Of Job Webdriver Examination Cases Inward Parallel

How To Purpose Selenium Grid Two To Piece Of Job Webdriver Examination Cases Inward Parallel

Main payoff of selenium grid is nosotros tin run webdriver software exam cases inwards parallel using selenium grid 2 environment to reduce software exam execution time equally described inwards THIS POST. Also It helps us to perform compatibility testing equally it is supporting multiple browsers too. Earlier nosotros accept configured selenium grid two hub inwards THIS POST together with selenium grid nodes inwards THIS POST inwards simply unmarried machine. Now lets endeavor to role this environs to execute webdriver software automation exam cases inwards parallel.

Prerequisite : Selenium grid hub together with node should live on running equally described inwards previous steps.

I accept created uncomplicated software automation exam to execute it parallel inwards multiple browsers using selenium grid. It volition launch 3 browsers (Mozilla firefox, google chrome together with IE) parallel together with and then execute same software automation exam within each browser.

Note : Please withdraw mesh explorer related code materials from bellow given script if confront whatever related mistake equally it is non really stable amongst selenium grid.

Create bellow laissez passer exam inwards your eclipse projection nether Grid package.

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;  populace cast SeGridTest {  WebDriver driver = null;  mortal StringBuffer verificationErrors = novel StringBuffer();   // Pass plateform, browser together with url parameters to launch browser together with URL inwards given plateform.  @Parameters({ "platform", "browser", "url" })  @BeforeTest(alwaysRun = true)  populace void setup(String platform, String browser, String url) throws MalformedURLException {   DesiredCapabilities caps = novel 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 = novel 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 exam method to execute.  @Test(description = "Wait for push enabled")  populace void waitForButtonEnabled() throws InterruptedException {   WebDriverWait hold off = novel WebDriverWait(driver, 15);   wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#submitButton")));   driver.findElement(By.xpath("//input[@id='submitButton']")).click();  }   // Simple exam method to execute.  @Test(description = "Wait for push enabled", dependsOnMethods = { "waitForButtonEnabled" })  populace void testCalc() throws InterruptedException {   driver.navigate().to("aa/search?q=what-is-selenium-grid-2-when-to-use-grid");   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 trial = driver.findElement(By.xpath("//input[@id='Resultbox']")).getAttribute("value");    // Get Browser elevate together with version.   Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();   String browserName = caps.getBrowserName();   String browserVersion = caps.getVersion();    // Get OS name.   String bone = System.getProperty("os.name").toLowerCase();    // Print exam trial amongst browser together with OS version detail.   System.out.println("OS = " + bone + ", Browser = " + browserName + " "+ browserVersion + " Test Result = " + result);  }   @AfterTest  populace void afterTest() {   // Close the browser   driver.quit();   String verificationErrorString = verificationErrors.toString();   if (!"".equals(verificationErrorString)) {    fail(verificationErrorString);   }  } }

If you lot remember, We accept used parallel inwards testng.xml file to execute software automation tests inwards parallel inwards selenium webdriver equally described inwards THIS POST. We volition role same matter hither but using selenium grid.

You tin see, We accept used parameters (plateform, browser together with url) amongst setup method. All these parameters volition live on served from testnx.xml file equally bellow. We accept configured 3 exam inwards bellow given xml file amongst unlike browser parameter to run exam inwards unlike browsers. Create bellow given testng.xml file nether your projection together with run it.

testng.xml
<!--Set thread-count = 3 to execute exam parallel inwards 3 max browsers at at time. You tin growth it--> <suite name="Parallel Tests" verbose="1" thread-count="3" parallel="tests">  <tests>      <!--Set exam parameters to execute exam inwards 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="aa/search?q=what-is-selenium-grid-2-when-to-use-grid" />    </parameters>    <classes>     <class name="Grid.SeGridTest" />    </classes>   </test>   <!--Set exam parameters to execute exam inwards 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="aa/search?q=what-is-selenium-grid-2-when-to-use-grid" />    </parameters>    <classes>     <class name="Grid.SeGridTest" />    </classes>   </test>    <!--Set exam parameters to execute exam inwards 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="aa/search?q=what-is-selenium-grid-2-when-to-use-grid" />    </parameters>    <classes>     <class name="Grid.SeGridTest" />    </classes>   </test>     </tests> </suite>

Now, execute inwards a higher house testng.xml file together with disclose exam execution process. It volition  launch 3 browsers parallel together with and then execute tests inwards all 3 browsers. At the halt of exam execution, It volition impress trial inwards console equally bellow.

OS = windows 7, Browser = chrome 43.0.2357.132 Test Result = vii OS = windows 7, Browser = mesh explorer 8 Test Result = vii OS = windows 7, Browser = firefox 38.0.5 Test Result = 7

Testng trial volition looks similar bellow.


This is the agency to execute selenium webdriver software automation test inwards parallel multiple browsers using selenium grid 2 to perform compatibility testing.

no image

Selenium Grid Ii - Using @Dataprovider To Last Parallel Webdriver Tests

In my previous post, We learnt how to execute selenium WebDriver unmarried software automation attempt out inwards multiple browsers inwards parallel using Selenium Grid 2. We had used "parameter" tag inwards testng.xml file to feed browser advert inwards which your software automation attempt out needs to run inwards parallel. Instead of using @Parameters, We tin purpose @DataProvider notation method to feed browser names in addition to run selenium WebDriver attempt out inwards parallel using selenium Grid 2.

If y'all purpose @Parameters, You postulate to write same attempt out multiple times(Depends on position out of browsers)  in testng.xml file. Main create goodness of using @DataProvider notation method is y'all no postulate to write same software automation attempt out representative advert multiple times inwards testng.xml file. You guide maintain to write it alone i time inwards testng.xml file. @DataProvider notation method volition provide browser details to @Test method. To run attempt out inwards parallel, y'all postulate to ready (parallel=true) amongst @DataProvider annotation. Let's travail it amongst elementary example.

My requirement is : I wants to run my selenium software automation attempt out parallel inwards 3 browsers using selenium grid 2 in addition to testng notation @DataProvider.

Prerequisites :
  • Selenium Grid 2 hub should last inwards running vogue every bit described inwards THIS POST.
  • Selenium Grid 2 node should last registered amongst hub in addition to inwards running vogue every bit described inwards THIS POST.
  • Also IE browser's protected modes should last enabled for all zones every bit described in THIS POST and zoom aeroplane should last ready to 100% every bit described in THIS POST if y'all are running your attempt out inwards IE browser too.
I am assuming your grid 2 hub in addition to node are working fine in addition to right away this is fourth dimension to launch software automation test. Write bellow given attempt out inwards eclipse.

Note : Please take network explorer related code materials from bellow given script if facial expression upward whatsoever 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 degree fillingForm {   //Used dataProvider parameter to acquire information from @DataProvider notation method.  //Can guide maintain 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 {      //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);   //Open URL inwards requested browsers of node in addition to execute attempt out steps.   driver.get("aa/search?q=selenium-grid-2-configuration-setup-hub");   driver.findElement(By.name("FirstName")).sendKeys(fName);   driver.findElement(By.name("LastName")).sendKeys(lName);    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;  }  }

You tin run into inwards in a higher house test. We guide maintain used @DataProvider notation method amongst (parallel=true) to render information to @Test method.  So no postulate to set @Parameter inwards testng.xml file. Use bellow given testng.xml file to run inwards a higher house test.

testng.xml
<suite name="My Test Suite" verbose="2" parallel="tests" thread-count="5">  <test name="Selenium Grid Test">   <classes>    <class name="Grid2.fillingForm" />   </classes>  </test> </suite>

Execute inwards a higher house attempt out in addition to verify execution. It volition run attempt out inwards parallel inwards dissimilar 3 browsers. This agency y'all tin purpose @DataProvider notation method amongst (parallel=true) at house of @Parameter to execute attempt out inwards dissimilar browser parallel using selenium grid 2.

Saturday, September 1, 2018

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

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

"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.

Friday, August 31, 2018

Usage Of Maxsession Inwards Grid Two To Laid Upward Publish Of Max Session Of Browser Instances

Usage Of Maxsession Inwards Grid Two To Laid Upward Publish Of Max Session Of Browser Instances

We learnt close "maxInstances" inward my PREVIOUS POST. "maxSession" is to a greater extent than or less other configuration parameter which helps to gear upwardly max allowed sessions to run at a fourth dimension on that specific node. Here session way publish of concurrent browsers inward price of all browser. It volition non allow that specific node to opened upwardly browser to a greater extent than than value of "maxSession". Let's sympathise alongside really uncomplicated instance scenario.
Example scenario : Let's see uncomplicated example. I wants to run two software automation attempt out cases as well as both should run on two dissimilar browsers concurrently(Firefox as well as Google chrome) using selenium Grid. But my to a greater extent than or less other status is, Node should opened upwardly max two browser at a time. In this case, only "maxInstances" volition non industrial plant for me but i take to exercise maxSession" inward node configuration. In this instance i tin gear upwardly maxSession = two for node to confine 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.

Note : Please take Internet explorer related code materials from bellow given script if facial expression upwardly whatever related fault every bit it is non really 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;  world shape 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 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.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 attempt out for xx minutes to banking concern tally precisely how many concurrent browsers opening at same time.   Thread.sleep(20000);    // Open URL inward requested browsers of node as well as execute attempt out steps.   driver.get("aa/search?q=usage-of-maxinstances-in-grid-2-to-set");   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 shape 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 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("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 attempt out for xx minutes to banking concern tally precisely how many concurrent browsers opening at same time.   Thread.sleep(20000);    driver.get("aa/search?q=usage-of-maxinstances-in-grid-2-to-set");   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 consequence 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 therefore nosotros volition exercise "maxInstances" inward node configuration to banking concern tally how it works.
  • Start grid two hub. You tin persuasion THIS POST to know how to inaugural of all hub.
  • Open ascendency prompt as well as navigate to D: campaign inward ascendency prompt where selenium server jolt file, IEDriver server file as well as chromedriver file is stored.
  • Start grid two node using bellow given command. You tin persuasion THIS POST to know prerequisite to inaugural of all 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 inward a higher house given 2 software automation  test cases using testng.xml file as well as detect attempt out execution sequence. It volition opened upwardly iv browsers at the same fourth dimension as well as execute both attempt out cases parallel inward all iv browsers.
  • Close electrical current running node using CTRL+c keys.
  • Start node using bellow given command. Now nosotros stimulate got used -maxSession two inward bellow given ascendency to bound 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 inward a higher house given 2 software automation  test cases as well as detect attempt out execution sequence. It volition opened upwardly only two browsers at a fourth dimension as well as two requests volition hold off for slot to travel costless every bit shown inward bellow given image. You tin meet it past times refreshing console page when your tests inaugural of all execution.

Once previous two requests volition consummate execution as well as unopen browser instance, Remaining two requests volition travel executed past times opening novel two browser instances. Means y'all volition meet max two browser instances at a fourth dimension on your grid node machine to execute tests.

This way, maxSession volition gear upwardly max allowed browsers at a fourth dimension to execute attempt out on grid node.
Set Selenium Grid Node Timeout When Running Webdriver Test

Set Selenium Grid Node Timeout When Running Webdriver Test

"timeout" is node configuration parameter using which you lot tin set timeout for selenium grid node browser session. If you lot laid upwardly "-timeout 20000" as well as run test, If node browser non receiving whatsoever ascendency as well as rest ideal for 20 seconds then it volition endure closed automatically past times -timeout parameter. That agency it tells node browser -> "wait max xx seconds to have whatsoever ascendency else unopen browser as well as clear session". Lets accept practical representative to understand "timeout" clearly.

Earlier nosotros learnt usage of "maxInstances" in THIS POST and "maxSession" in THIS POST to configure selenium grid node hence i promise you lot are good aware close usage of both these parameters equally nosotros are going to utilization them inwards this representative too. Now let's practise 2 selenium software automation bear witness cases equally bellow as well as and hence elbow grease to run them without timeout as well as and hence amongst timeout parameter.

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 {   @Test(dataProvider = "getNames")  populace void gmailLogin(String browser, String fName, String lName) throws MalformedURLException, InterruptedException {      System.out.println(browser);      DesiredCapabilities cap = null;    if (browser.equals("firefox")) {    cap = DesiredCapabilities.firefox();    cap.setBrowserName("firefox");    cap.setPlatform(Platform.WINDOWS);   } else if (browser.equals("chrome")) {    cap = DesiredCapabilities.chrome();    cap.setBrowserName("chrome");    cap.setPlatform(Platform.WINDOWS);   }    RemoteWebDriver driver = novel RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);   driver.manage().window().maximize();   driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);    driver.get("aa/search?q=usage-of-maxinstances-in-grid-2-to-set");   driver.findElement(By.name("FirstName")).sendKeys(fName);   driver.findElement(By.name("LastName")).sendKeys(lName);    // Commented driver.quit(); to verify browser is existence closed automatically past times timeout or not.   // driver.quit();  }   @DataProvider(parallel = true)  populace 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";    provide 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 {   @Test(dataProvider = "getCalcData")  populace static void calcTest(String browser, String num1, String num2, String expSumNum) throws MalformedURLException, InterruptedException {    System.out.println(browser);    DesiredCapabilities cap = null;    if (browser.equals("firefox")) {    cap = DesiredCapabilities.firefox();    cap.setBrowserName("firefox");    cap.setPlatform(Platform.WINDOWS);   } else if (browser.equals("chrome")) {    cap = DesiredCapabilities.chrome();    cap.setBrowserName("chrome");    cap.setPlatform(Platform.WINDOWS);   }    RemoteWebDriver driver = novel RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);   driver.manage().window().maximize();   driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);    driver.get("aa/search?q=usage-of-maxinstances-in-grid-2-to-set");   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();    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);    // Commented driver.quit(); to verify browser is existence closed automatically past times timeout or not.   // driver.quit();  }   @DataProvider(parallel = true)  populace 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";    provide 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>


Test Configuration
  • 2 Software Automation Test cases : fillingForm.java and Calc.java
  • driver.quit(); is commented from both software automation test cases hence webdriver volition non unopen driver instance.
  • Both tests are configured to run inwards parallel using selenium grid 2.
  • Our aim is to run both software automation test cases inwards parallel inwards 2 browsers as well as also it should run max 2 browsers at a fourth dimension hence nosotros volition launch node amongst -maxSession 2. 
Running bear witness without timeout for node
First of all nosotros volition launch node without timeout parameter as well as execute higher upwardly bear witness on it to cheque node browser condition on completion of test.
  • Start grid hub equally described inwards THIS POST.
  • Open ascendency prompt as well as navigate to D: elbow grease inwards ascendency prompt where selenium server jolt file, IEDriver server file as well as chromedriver file is stored.
  • Start grid node with -maxSession 2 to trammel 2 max browsers only at a time. timeout is non used. Launch node using bellow given command.
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 higher upwardly bear witness from testng.xml file. It volition launch 2 browsers to run both software automation bear witness cases parallel. Other 2 pending requests on node volition hold back for electrical flow session to endure closed equally bellow. 


But hither you lot know, We conduct maintain commented driver.quit(); from both bear witness cases hence tests volition endure executed successfully on both driver instances but driver instances volition non closed. It volition remain equally it is for five minutes (node default timeout period) hence remaining 2 tests volition rest inwards queue for five minutes equally no slot is complimentary on node to run test. When default timeout fourth dimension reached, both electrical flow driver instances volition endure closed as well as and hence remaining 2 requests volition kickoff execution past times launching novel driver instances on node.

Running bear witness amongst timeout for node
To reset node timeout, We tin utilization timeout parameter when launching node. You tin laid upwardly your desired timeout for node hence that it tin kickoff side past times side bear witness if driver instance rest steady for given time. Let's configure node amongst timeout to cheque how it plant inwards higher upwardly scenario.
  • Restart grid hub.
  • Restart grid node using bellow command. Here nosotros conduct maintain used -timeout 20000 (20 seconds) at the destination of command. You tin laid upwardly timeout equally per your requirement.
Note : Meaning of -timeout 20000 : During bear witness execution if browser volition remain steady for xx seconds, Node volition unopen it forthwith afterward 20 seconds.


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 -timeout 20000

Now run higher upwardly tests from testng.xml file. Both software automation tests volition endure executed, as well as hence browsers volition rest steady for xx seconds as well as and hence both of them volition endure closed automatically as well as novel requests volition kickoff execution on complimentary slots.

This way, node timeout tin aid you lot to unopen browser instance if it is stuck during bear witness execution.
Selenium Tutorial

Selenium Tutorial

Selenium tutorial for beginner is basic requirement of whatever selenium learner to acquire selenium perfectly if it's gratuitous too complete. Selenium is really rigid too open-source spider web application automation testing tool too therefore selenium testing tool is booming right away a days inward software testing industry.

Selenium has dissimilar projects similar selenium IDE, selenium RC, selenium Webdriver, Appium too selenium Grid. Please banknote here, I am maxim them dissimilar projects of selenium non a versions because each selenium projection has it's ain features too developed for dissimilar purpose.

is basic requirement of whatever selenium learner to acquire selenium perfectly if it Selenium Tutorial

I possess got created tutorial serial for dissimilar selenium projects amongst examples to back upwardly online selenium learner community. My selenium tutorial for beginners amongst examples volition helps you lot to acquire selenium testing really fast. All bellow given selenium project's tutorials volition accept you lot from basic to advanced degree footstep yesteryear footstep too you lot volition hold upwardly primary at the destination of series. Trust Me !! Selenium RC is officially deprecated right away too therefore i possess got non created tutorial serial for RC. Just start amongst selenium IDE tutorial serial too destination on selenium grid tutorial series.

Selenium Tutorial

Bellow is selenium coffee tutorial serial of dissimilar selenium projects.

1. Selenium IDE tutorial

Selenium IDE is commencement projection of selenium. It is basic tape too playback improver of firefox browser. You tin work selenium IDE if your application is non to a greater extent than complex to test. My Selenium IDE tutorial serial volition helps you lot to acquire selenium IDE.

2. Selenium WebDriver tutorial

Selenium Webdriver is latest projection of selenium which is interface too designed to automate spider web applications. It is designed to overcome limitations of selenium RC(which is deprecated now.) too therefore it is successor of selenium RC. I possess got created online selenium interview questions amongst 110+ interview questions. It volition helps you lot to confront selenium testing tool interview.

3. Appium tutorial

Appium is mobile native, spider web too hybrid application essay automation testing framework. You tin automate ios too android apps using appium. Appium Tutorial serial is created to depict how appium plant amongst examples.

4. Selenium Grid tutorial

Selenium grid helps you lot to run your selenium automation tests inward parallel on dissimilar machines too browsers to speedup your essay execution. So you lot tin run your tests on dissimilar machines which are running dissimilar browsers on dissimilar operating systems. Selenium Grid Tutorial serial which is created to exhibit you lot how genuinely grid tin helps you lot to speed-up your essay execution process.

All to a higher house selenium tutorial serial are created amongst practical examples too detailed description on each topic. Start selenium learning today to seat your footstep inward selenium automation testing manufacture too also portion your novel ideas amongst others.

5. Selenium Video Tutorial

Also you lot tin subscribe for selenium video tutorial if you lot tin pay about bucks for learning. As per my view, investment inward education/learning is best investment.