Saturday, July 29, 2017

AShot() in Selenium 3 for taking full page screenshot?

As discussed in Important notes about Screenshots in Selenium 2 and Selenium 3 we can take only visible area screenshot using TakesScreenshot interface.

Ashot() is a third party utility supported by Selenium WebDriver to capture the screen shots. The below are the features supported by aShot() utility with repect to screenshots:
  • Capturing the entire page
  • Capture the Web Element
  • Prettifying the screenshot
  • Screenshot comparison
  • Several elements comparison
Our focus here is on capturing the entire page and capturing the web element screenshots. For more deatils on aShot() you can refer here.

To take the full page screenshot of a page AShot() scrolls down the page at particular time intervals “scrollTimeOut” till the bottom of the page and takes the screenshot of entire page.

Using shootingStrategy() method Ashot() takes the entire page screenshot. The syntax is:

Important notes about Screenshots in Selenium 2 and Selenium 3

  • In Selenium 2, TakesScreenshot interface used to capture the screenshots. But the screen shot capturing area varies between Firefox and other browsers (Chrome, IE and etc.)
  • In Selenium 2, TakesScreenshot captures only visible area as the screenshot for Chrome, IE, Safari and etc. but for Firefox it captures entire page as screenshot (including the invisible page area) because the Selenium 2 supports Firefox as default browser.
  • From Selenium 3, the default support to Firefox browser is removed and made it external. We need to use geckodriver to lunch Firefox browser.
  • Due to the above change, TakesScreenshot can capture only visible area as the screenshot in any browser Firefox, Chrome, IE and etc.

Friday, July 28, 2017

How take screen shots in Selenium WebDriver?

Screen shots are important to have in the results analysis of test cases. By looking at the captured screen shots we can tell what went wrong or what could be reason for a test case failure.

Selenium WebDriver provides TaskesScreenShot interface to capture the screen shots. This interface is available under package import org.openqa.selenium.TakesScreenshot.

The below test script explains how to capture the screen shot when a test case is failed. The below script launches Gmail login page and tries to enter the username to Email or Phone filed with an invalid id. Since there is no element with the given id on the page it's throws an exception. In the exception block captureScreenShot() method will be called to take the screen shot.

Tuesday, July 25, 2017

Why JavaScript is used in Selenium and What is JavaScriptExecutor?

Why JavaScript is used in Selenium?
Sometimes native actions like clicking, text entering will not work on the browsers, and we can’t access the hidden elements with our scripts in Java or Python or some other language. In such situations with the help of running JavaScript in browser we can make it work out (most of the times). Selenium Webdriver provided JavaScriptExecutor to run the JavaScripts.
Example, the native clicks in the IE browser will not have any effect, it clicks the button or link but there will be no response from it. But when I used JavaScript here to click the element it worked like a gem. Another situation is not able to enter text using sendKeys, using JavaScript I was able to enter the text in the field. Hope this gives basic understanding for using JavaScript in Selenium. 
JavaScriptExecutor:
  • JavaScriptExecutor is an Interface provided by Selenium WebDriver. WebDriver uses the JavaScriptExecutor to run the JavaScripts.
  • JavaScript is used along with HTML to enhance the browser capabilities like Dynamic pages creation, Dynamic validation of fields, To communicate with HTML DOM and etc.
  • When JavaScript is executed using JavaScriptExecutor, it communicates with the browser's DOM and performs necessary action.
  • JavaScriptExecutor provides two methods to execute JavaScript executeScript() and executeAsyncScript().
  • This is available under the package org.openqa.selenium.JavaScriptExecutor;

Thursday, July 20, 2017

How to parameterize Cucumber tests?

In our first cucumber test First Test Case in Selenium with cucumber we have hard coded the values in the step definitions. Which is not effective way of writing tests in the real world. It's time consuming, increased code length and etc.
Observe the below step definitions screen shot, previously we have directly given the URL, User name and Password in the code.
Step 1: In Cucumber we can easily parameterize the tests. I am taking the below test and parameterizing it.

How to email Selenium results reports using Jenkins?

In the previous post we have seen sending an e-mail notification when the build/tests failed. That email notification doesn’t provide us with details of Passed/Failed tests.

To get full details about the execution results, we have to use Email Extension Plugin in Jenkins.We can email the results reports that are generated in Jenkins. With which you can directly check how many tests Passed? How many failed?

Saturday, July 15, 2017

How to schedule Selenium tests in Jenkins and Send Email Notification?

Cron Pattern:

Jenkins uses Cron Pattern to schedule the test/build executions. It is used for specifying the time, it is a five field structure (* * * * *).

Based our requirement the fields are set to run the tests periodically or at regular intervals of time. The Cron Pattern fields are defined below:

Thursday, July 13, 2017

Configuration of email (Gmail) in Jenkins

One of the major beauty of Jenkins is to notify its users with e-mails as soon as the execution completed. It reduces the efforts of tester for checking results reports.

Testers need not to wait or stay back in office to send out the execution results e-mails. Jenkins will send notification email as soon as the execution completed to the intended user. And Jenkins supports different emails like Gmail, Yahoo, Outlook and etc.

Saturday, July 8, 2017

Execute Selenium Test Cases from Jenkins

In the previous post Jenkins Installation and Java Configuration for Windows we have learned installing Jenkins on windows machine and configuring Java in it. In this post we will learn executing the Selenium tests from Jenkins tool.

Friday, July 7, 2017

How to execute selenium test cases from Command Prompt using testng.xml?

We know how to execute the test cases from IDE like eclipse o IntelliJ. We just have to either right click on the test case and select the Run option or right right click on the testng.xml file and select TestNG --> Run as --> TestNG suite option.

In this post we will learn how to execute the scripts from command prompt.

Sunday, July 2, 2017

How to handle StaleElementReference Exception in Selenium?

The meaning of stale is no longer fresh. And when we say stale element which means element is not fresh or not valid.

The StaleElementRefrence  exception occurs when the web driver is trying to perform an action on the element that is no longer available on the page.

This exception will be thrown between an element identification and action being performed on the element”.

WebElement element = driver.findElement(By.id("btn_id")); // The element btn_id is identified or located.

DevOps 01: What is DevOps and How it benefits organizations?

DevOps is a culture in an organization, where the development team and operations team help each other by sharing information, process and t...