Saturday, December 30, 2017

Maven Tutorial 05: Maven Surefire plugin and its usage in test automation?

Maven Surefire Plugin is used during test phase of build life cycle to execute the unit tests of an application. It has only one goal and it is 'test', runs the tests of the application. In test automation surefire plugin can be used for running functional tests from pom.xml.

Maven Tutorial 04: What is POM.XML?

Maven is build management tool that is based on the concept Project Object Model (POM). POM.XML is an xml file and it is core unit of the maven project. It contains all the information about the project and its configuration.

Maven Tutorial 03:What is Maven? How to create Maven project?

Maven is a build management tool or software project management and comprehension tool. Maven is free and open source tool provided by Apache Software Foundation. Maven is based on the concept project object model (POM).

Friday, December 29, 2017

How to handle Google dynamic search (auto suggestions) in Selenium?

This is one of the most asked Selenium interview question and this question is to test our ability to handle dynamic objects.

The scenario is when we are searching some text say "seleniumhq" in Google, we will get some auto suggestions listed while we are entering the text and we need to click on the suggestion that matches with our requirement (here our requirement is "seleniumhq").

Wednesday, December 27, 2017

How open URL in new tab using StringSelection class in Selenium?

I have come across 'StringSelection' some how and came to know that it is a class that is used for copy and paste operations on Unicode text strings. Using this class we can copy the string to system clipboard. 'StringSelection' class is available in 'java.awt.datatransfer' package.

Using Robot class from Selenium WebDriver and StringSelection class we could able to open the URL in the new tab. Please check the code below

Wednesday, November 29, 2017

API Testing 01: What is a web service and what is an API?

In the real-world, applications talk (exchange data) with each other over the Internet using http protocol. This data exchange across different applications over the Internet is web service.

Saturday, November 18, 2017

How to get Coordinates, Width, Height and Size of the WebElement using Selenium WebDriver?

Selenium WebDriver provides Point class in org.openqa.selenium package. Using Point class we get the location and coordinates of the given element.

And using getSize() method that is available in the WebElement interface we can get the width and height of the given WebElement.

Five different ways to refresh the browser using Selenium WebDriver.

Below are the 5 different ways to refresh the browser using Selenium WebDriver.

Method 1: Using navigate.refresh()
Most of us know this approach, driver.navigate.refresh() will refreshes the current page.

Method 2: Using navigate.to()
In this approach using "driver.getCurrentUrl()" we will get the current url of the page and send to the navigate.to() method to refresh the page.

Method 3: Using get()
In this approach using "driver.getCurrentUrl()" we will get the current url of the page and send to the get() method to refresh the page.

Monday, November 13, 2017

How to apply Grouping to test cases in TestNG?

Grouping in TestNG is very simple, it is used to execute specific set of test cases at a time. This grouping can be done based on the test cases functionality or module that they belong or the test set they present (smoke or regression) it is completely depends on tester requirement.

A test method can be categorized into one or more groups, groups is the attribute used in the @Test annotation.

@Test(groups ={'Sales'}) // test method belongs to 'Sales' group
@Test(groups = {'Sales','Marketing'}) //test method belongs to 'Sales and Marketing' groups

Wednesday, November 8, 2017

Maven Tutorial 02: How to install Maven on Windows?

The prerequisites for installing the Maven on Windows machine are:
  • Install JDK (1.7 or above)
  • Set JAVA_HOME and PATH system variables

Sunday, August 27, 2017

How to prioritize test cases from different test sets (java classes) in TestNG?

In the previous post we have seen the importance of priority and how to use it in TestNG in one test set, here a test set is nothing but a java class that contains one or more test cases (@test methods). Now we will learn prioritizing the test cases that are present in different test sets.
As show in the below screenshot we have one regression test and one smoke test. And each test contains two test sets.

Saturday, August 26, 2017

What is priority in TestNG and How to use it ?

Priority is an attribute used along with @Test annotation to set the priority of a test case. Using priority user can define the order of the execution of test cases (@Test methods) in a java class. Some points on priority in TestNG are below:
  • The default priority of any test case (@Test method) is zero. That is highest priority.
  • Higher the priority value, lower is the priority. In test set (java class) @Test (priority=0) highest priority, @Test (priority=1) second priority, @test (priority=2) third priority and so on.
  • If no priority is defined, all the test cases are having zero priority. In this case the test cases will be executed in alphabetical order.
Real Time Scenario: There could be situations where we need to execute the test cases in a sequence to achieve a task, suppose I have a scenario sending an email. To do this task the sequence of test execution will be 1) launching application, 2) login to account, 3) compose email and send, finally 4) logout.  So here prioritizing the test cases is required. Let us do this…

Friday, August 25, 2017

How to execute multiple test cases in TestNG?

There are different ways to execute the multiple test cases in TestNG using testng.xml file. As discussed in my previous post Importance of testng.xml testng.xml is used to define the test execution process. We can definethe test execution process based on requirement in testng.xml files. And we can have more than one testng.xml file (with different title) in your project. In this post we will discuss about different ways to execute the multiple test cases.

Assume we have a TestNG project with regression tests (“regressionTests”) and smoke tests (“smokeTests”). And regressionTests contains two sets of test cases regressionSet1 and regressionSet2. Similarly smokeTests contains smokeSet1 and smokeSet2. Each test set contains three test cases (@test methods). Please find the screen shot below.


Tuesday, August 15, 2017

How to take screenshot of WebElemets in Selenium?

In the previous post AShot() in Selenium 3 for taking full page screenshot? we have seen how to capture the full page screenshot in Selenium using AShot() utility. Now we will see how to capture the screenshot of WebElement using AShot().

Syntax: The below method is used to capture the screenshot of the web element.
  • We need to pass two arguments to the above method, one is WebDriver object and another is web element . 
aShot will find element's size and position and crop original image. WebDriver API provides a method to find the WebElement's coordinates  but different WebDriver implementations behave differently.

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.

Tuesday, June 20, 2017

Importance of testng.xml and How to create it?

The importance of the testng.xml file is to define the order of execution of different tests. User can put all the tests together in one testng.xml file or can create separate testng.xml files for different based on the requirement.

Sunday, June 11, 2017

Writing first Selenium test case with TestNG

Let us start write a simple test case, launching the website and verifying it's title.

Step 1: Launch Eclipse, Right Click on project source folder src --> TestNG --> Create TestNG Class


Saturday, June 10, 2017

Create TestNG project for Selenium Automation

This is very simple, in a nutshell we just need to add the TestNG and Selenium libraries or jar files to a java project.

To create  a TestNG project for selenium automation, eclipse should be installed with the TestNG plug-in.

If you need any help in installing TestNg plugin please check the post Install TesNG plugin in eclipse IDE.

Thursday, June 8, 2017

Jenkins Installation and Java Configuration for Windows

Jenkins can be downloaded and installed easily. Please follow below steps.

Step 1: Go to the URL  https://jenkins.io/download/

Step 2: Under Long-term Support (LTS) column, check for “Generic Java Package (.war)” to download the “jenkins.war” file.

Introduction to Continuous Integration and Jenkins

Continuous Integration is a software development practice in which developers will be committing their code copies to central repositories (Git, SVN GitHub) frequently and for each integration automated build verification tests (unit tests) will be executed to accept or reject the build.

Sunday, May 28, 2017

Installing TestNG Plugin in Eclipse

TestNG is comes as Eclipse IDE plug-in. It can be installed easily, please follow the steps below.

Step 1: Open Eclipse IDE and click “Install New Software” from Help menu.

Friday, March 3, 2017

How Create Maven Project for Selenium - Cucumber Automation?

In First Test Case in Selenium with Cucumber post we created java project and added all the required Jars to project build path. This involved more manual intervention work like downloading jars one by one from Maven Central Repository. But in Maven project we will avoid that maven intervention by adding all the dependencies in pom.xml.

Dependencies Required for Maven Project for Selenium with Cucumber:
        1. cucumber-java
        2. cucumber-junit
        3. junit
        4. selenium-standalone-server
Follow the below steps :
Step 1: Install Maven Plugin in Eclipse IDE

Maven Tutorial 01: How to install Maven Plugin in eclipse IDE?

Steps to install Maven in Eclipse IDE:

1. Launch Eclipse IDE and Select Help > Install New Software

Wednesday, March 1, 2017

How to write multiple test cases in Selenium with Cucumber?

In this post we will learn about writing multiple test cases (Scenarios) in a Feature file. This post is going to be an extension to the previous post First Test Case in Selenium with Cucumber. So please go through it to understand the current post better. Let's get started step by step...

Step 1: This time we are taking "Gmail valid login validation" as our test. Please copy the below code snippet in our feature file created "gmailLogin.feature" file and save it.

Tuesday, February 28, 2017

First Test Case in Selenium with Cucumber

Let us now implementing a simple cucumber test. We will validate "Gmail invalid login" scenario to understand the test case implementation. I would recommend you to go through my previous post What are Features and Step Definitions in Cucumber? and understand Features file and Step Definitions. Let us go step by step...
  • Create a project and adding Jars. Please go through my previous post Downloading Cucumber JVM and Selenium Jars to understand.
  • Create Features folder and features file.
  • Add a Feature and sample Scenario.
  • Create a Test Runner.
  • Create Step Definitions package and define steps.
  • Run the Test Runner as Junit test.
Step 1: Create a Project New Project select Java Project and click Next. Give the project name as “seleniumCucumberProject” (you can give any name).

Monday, February 27, 2017

What are Features and Step Definitions in Cucumber?

Features: File with “.feature” extension are called features file. A Feature file will contain one feature with one or more Scenarios. A line started with Keyword “Feature” in Feature file is the test feature that cucumber going to execute.  Each Scenario in Feature contains number of steps written using Gherkin language.

Step Definitions: Each step in a Scenario is mapped to Step definition. When Cucumber executes a Step Scenario it looks for a matching Step Definition to execute. Each step definition is a piece of code defined to do certain task in the scenario. Step definitions are attached to steps with a reference pattern, which is used for connecting steps in a scenario and step definitions.

Sunday, February 26, 2017

How to Encrypt password for Selenium WebDriver?

To secure our passwords we can use Base64 encoding scheme in Selenium WebDriver. We will import this Bas64 class in our script to get the encoded password.

Wednesday, February 22, 2017

Download Cucumber JVM and Selenium Jars for Eclipse

To write/run Cucumber Scenarios with Java in Eclipse the below Jar files are required. Please follow the steps and all download the all listed jar files.
·         junit
·         gherkin
·         cucumber-core
·         cucumber-java
·         cucumber-junit
·         cucumber-jvm-deps
·         cucumber-reporting
·         mockito-all
·         cobertura

Step 1: Search all the above terms in the Maven Central Repository one by one and download latest Jar file. Click Here! for Maven repository.

Tuesday, February 21, 2017

Installing Cucumber Eclipse Plugin

Why Cucumber Eclipse Plugin needed? This plugin highlights the Syntax’s or Keywords; basically it distinguishes syntax keywords from other sentences. That is fine if we do not install it but the entire scripts appears as plain text as in a notepad. So it is recommended to install Cucumber Eclipse Plugin.
Installation Steps:
Step 1: launch Eclipse IDE and Go to “Install New Software…” option.
Step 2: In the new dialog window click on “Add” button.

Monday, February 20, 2017

What is the advantage of Cucumber in Selenium Automation?

Or else we can ask our-self what makes us to bring Cucumber to Selenium Automation?             

In this agile world, the Stake Holders or Business Analysts or Product Owners decides behavior of the system first and writes System Requirements or System Scenarios in customer’s point of view. These requirements are reviewed and singed off to the developers for development. This is called Behavior Driven Development (BDD) approach.

            Now the above system requirements are converted to Use Cases, using BDD approach this Use Cases are converted into testing/developing entities directly using a simple English sentences(Gherkin), instead of splitting further into small functionalities. And this tests are easily understandable to the Clients or Business Analysts or persons with no or minimal technical knowledge. Whereas the tests developed using tools Selenium or UFT are pure technical and one has to be technically good to understand the tests, even that consumes some time and efforts. 

So if we can use BDD approach in out test automation that will increase the code readability. By seeing the tests we can tell what that test is testing. And Cucumber is one of the BDD tool that supports automation using Java and Ruby. Selenium Automation with Cucumber is becoming good choice in the automation industry. 

I tried bringing nearest answer to our question. Please comment your queries and suggestions on this topic. Thanks for reading!!

#seleniumbabu #HappyLearning

Introduction to Cucumber

  • Cucumber is an open source software tool used to test the other software. It is a Behavior Driven Development tool. 
  • The tests will be written in simple English language. Persons with no technical knowledge can understand the tests written just by reading high level. 
  • Writing the tests is easy and simple.
  • Though Cucumber is written in Ruby, supports other languages like Java, Scala, Groovy and etc. Cucumber supports web environment only.
  • Cucumber plugins works faster compared to UFT and Selenium. These features of Cucumber attracting the Clients and Automation Industry.


Saturday, February 18, 2017

Common Issues in Selenium Automation with IE Browser

The common issues that could be faced while automating IE Browser using Selenium are discussed below. One should ensure these settings set before the start of the automation.

1. Protected Mode Settings: Protected Mode must be set to the same value (enabled or disabled) for all zones under security tab in Internet Options. Find the screen shot attached.

Exception we would see in console when the settings are not properly: 
org.openqa.selenium.WebDriverException: Unexpected error launching Internet
Explorer. Protected Mode must be set to the same value (enabled or disabled) for all
zones.



Friday, February 17, 2017

launching Firefox with Gecko Driver using Selenium 3

Selenium 2 was supporting Firefox driver launch by default, no need of using external drivers. Now Selenium 3 is released with some improvements and changes.One of the enhancement or change is the support to Firefox browser is made external like Chrome and IE Browsers. We need to use Gecko Driver to launch Firefox using Selenium 3. See the below step by step procedure in launching the Firefox browser using Gecko Driver. Assuming Selenium 3 setup already done.

Step 1: Download Gecko Driver:

            Download the latest version of geckodriver.exe , unzip the downloaded file and keep it some location on your machine. To download the Gecko Driver Click Here!!

Step 2: Set the System Property in the Script.


      
         


   
       

How do you identify broken links in Selenium Automation?

When we are asked to identify the broken links in the application, what we do? Collecting all the links on the page to a list and looping t...