Wednesday, 26 December 2018

Jenkins Retry Failed Builds

We will use Jenkins Naginator Plugin to rerun the Failed/Unstable builds. This plugin allows you to automatically reschedule a build after a build failure.

Configure

  • Go to Manage Jenkins > Manage Plugin > Available Tab > Search 'Naginator' and install and restart


  • After installing the plugin, add the Post-Build action "Retry build after failure" on your Jenkins Job configuration page.


  • Set Build Retry

Above set Build retry screenshot shows that:

  • Job is enabled to rerun for unstable as well as Failure builds
  • Delay the build execution by Fixed 60 seconds
  • Maximum number of successive failed builds count is set to 3 (Limits successive failed build retries. Set to 0 for no limit.)

Friday, 3 October 2014

How To Execute JavaScript In Selenium WebDriver

Sometimes it is important to run JavaScript directly from the code to get any property of  Browser-BOM,  HTML-DOM  etc.
  • The Browser Object Model (BOM) allows JavaScript to "talk to" the browser. It includes Window, Navigator, Screen, History, Location etc.
  • With the HTML DOM, JavaScript can access and change all the elements of an HTML document. It includes Document, HTML, CSS, Elements etc.

We can execute JavaScript in 2 simple steps:

  1. Cast the WebDriver instance to a  JavascriptExecutor
    JavascriptExecutor js = (JavascriptExecutor) driver;
  2. Execute JavaScript
    js.executeScript("script for execution")

Example:


Saturday, 27 September 2014

Selenium WebDiver: Handle AJAX calls

The most common problem that we face during automation using Selenium WebDriver is how to handle AJAX calls. We never know when the call is complete and page has been updated. AJAX can be handled using JavaScript/JavascriptExecutor.

  In this post we will see how we can use JavaScript - jQuery.active to get all active AJAX calls and wait until all calls get served.

jQuery.active returns total number of active AJAX connections, and we are waiting until all active calls becomes zero or given Timeout reached.

Hope this helped you!!!

Thursday, 24 July 2014

Selenium WebDriver and TestNG: Running script in different browsers |Invoke different browsers

In this post will cover how to run a selenium script in different browsers.
To do so we will use TestNG and @Parameters annotation. Using TestNG we can directly pass parameter to test methods from testng.xml.  Below example makes it more clear

Prerequisites:


Java

  • Create a java class name BrowserContoller.java in your workspace.
  • Create a method setBrowser(String browser) to your class. This method takes a String as input parameter.
  • Add the annotation @Parameters ("browser") to this method. Value to the parameter will be passed from xml.

TestNG

  • Create a simple tesng.xml name say BrowserControllerTestng.xml
  • Define Test name, parameter and its value (firefox, chrome,  iexplore ) and class name.


Wednesday, 21 May 2014

Selenium WebDriver: Dropdown selection

Selenium has Select class designed to interact with drop down lists. Using it, we can easily choose option by displayed text, index or value.

Example:

Consider a dropdown list as shown below:


Now we just need to pass WebElement into Select Object as shown below

Select dropdown = new Select(driver.findElement(By.id("months")));

To select option say 'February', we can use any one of the method:
  • dropdown.selectByVisibleText("February");
  • dropdown.selectByValue("Feb");
  • dropdown.selectByIndex(2);

I have created a generic class Dropdown with all 3 methods shown above, we just need to call it.

  • Dropdown.selectByVisibleText(driver, By.id("months"), "February");
  • Dropdown.selectByValue(driver, By.id("months"), "Feb");
  • Dropdown.selectByIndex(driver, By.id("months"), 2);




Thursday, 8 May 2014

Selenium WebDriver – Handle Window Focus

Method and Description:

 

Example:

  • Below example opens a page of w3schools.com
  • And then clicks on ‘Try it yourself »’ link, which opens a new window.
  • Switch to new window, perform some actions on it and then switch back to previous window

Selenium WebDriver – Open a link in a new Window


We can use Action class to open a link in a new window.

Method and Description:


  • contextClick(WebElement onElement) - Performs a context-click at middle of the given element.
  • perform()- A convenience method for performing the actions without calling build() first.
  • sendKeys(java.lang.CharSequence... keysToSend) - Sends keys to the active element.

 

Example:

Below example opens w3schools.com
And click on “Learn HTML” link to open in new window.