Wednesday, January 8, 2020

KATALON STUDIO: Test case creation in manual mode

In this tutorial, we are going to learn, test script creation using Katalon Studio’s manual mode. As stated in our previous tutorials, Katalon studio inherently supports Keyword-driven framework. Katalon has a rich set of keywords or we can say commands to help in test case creation for users with limited programming knowledge. Users can directly use these keywords to simulate some user actions like opening a browser or to perform some tasks like validating if the expected and actual results are the same. Let’s first see some commonly used keywords provided by Katalon Studio for automating a web application.

Browser related keywords

KeywordDescription
Open BrowserOpens browser with the URL provided, if no URL is provided then it will just open a blank browser.
Close BrowserCloses a browser.
Navigate to UrlNavigates to a url provided in the Input cell.
Delete All CookiesDeletes browser cookies.
Wait For Page LoadWaits for page to load with the timeout value in seconds.
RefreshRefreshes the browser.
BackGoes back to the previous URL in the browser history.
ForwardGoes to the next URL in the browser history.

Web element related keywords

KeywordDescription
ClickSimulates mouse left-click on a web element.
Double ClickSimulates mouse double-click on a web element.
Right ClickRight clicks on a web element.
CheckChecks a check-box or radio button.
Un-checkUnchecks a check-box or radio button.
Set TextWrites a text on a textbox or any input field (similar to sendKeys() in selenium)
Select Option By IndexSelects a dropdown option by its index.
Select Option By LabelSelects a dropdown option by its visible text.
Select Option By ValueSelects a dropdown option by its value.

Common wait related keywords

KeywordDescription
Wait For Element ClickableWaits for an element to be clickable with timeout value in seconds.
Wait For Element VisibleWaits for an element to be visible with timeout value in seconds.
Wait For Element Not VisibleWaits till an element is not visible.

Commonly used validation related keywords

KeywordDescription
Verify Element PresentReturns a boolean value of true/false based on the presence of an element.
Verify Element Not PresentReturns a boolean value of true/false based on the absence of an element.
Verify Element TextReturn true if the element’s text is the same as expected text else false.
Verify EqualReturn true if the actual value is the same as the expected value.
Verify Not EqualReturn false if the actual value is the same as the expected value.

Other commonly used keywords

KeywordDescription
Accept AlertSimulates user action of accepting an alert or clicking ‘Ok’ on an alert dialog box.
Dismiss AlertSimulates user action of dismissing an alert or clicking ‘Cancel’ on an alert dialog box.
Get AttributeUsed to get a particular attribute of a web element e.g. name, type etc.
Get TextUsed to get the element text.
Drag And Drop To ObjectSimulates drag and drop action.
Switch To FrameSwitches to a particular iframe.
Switch To Window TitleSwitches to a particular window with the given title.
Close Window TitleReturn false if the actual value is same as expected value.
Switch To Default ContentSwitches to the parent window, called after performing some function on an iframe or a different window/tab.
Take ScreenshotTakes a screenshot of the browser when called.
Execute JavaScriptUsed to execute javascript command.
Upload FileUsed to perform file upload operation on a file type element.
Now, let’s begin with a test script creation using Katalon’s manual mode. In this demo, we will create a test that checks Google calculator functionality.
Let’s first quickly see, how to create a project in Katalon.
  1. On the Katalon Studio IDE, go to the File menu and click on New->Project.
  2. Name your Project, specify the project location, provide a description(optional) and click OK. Now, the “Test Explorer” on the left-hand side will get populated with pre-defined packages like ‘Test Cases’, ‘Object Repository’, ‘Test Suites’, ‘Data Files’ etc.
  3. Next, we need to create a test case. For this, right-click on ‘Test Cases’, click on the New button on the toolbar and select Test Case. Name your test case – ‘GoogleCalc’, provide a description and click OK. If everything is fine, the following screen will be displayed.
Now that we know, how to create a project on Katalon, let’s focus on the test case creation part. We can create tests in the Manual mode by adding keyword using Add button. For keywords related to web application automation, click on the arrow icon in the Add button and select Web UI Keyword option.
When dealing with web elements we need to capture or locate the elements. For this, we can use Spy Web feature. Clicking the Spy Web option launches an Object Spy window where we can pass the URL of the application. After passing the URL and clicking Start link, the browser launches with the given URL. Now we can hover over any element and pressing Alt+` will save the object in the object repository.

Google calculator test in manual mode

  • Select Open browser from the Web UI Keyword, leaving the Input cell blank, in order to launch a browser.
  • For opening a URL, select Navigate To URL keyword with the exact URL in the Input cell – https://google.com.
  • Now, using object spy, capture the locator for the google search box.
  • For writing into the search box, select Set Text option, in the Object cell enter the name of the object captured (you can also drag and drop the object from the Object Repository into the Object cell). The arithmetic operation e.g. 2+2 will be entered in the Input cell.
  • Next, add a Click keyword on the Google Search button(Google search button present in the auto-suggestion for 2+2).
Now we just need to add an Assertion or validation point which checks that the result of 2+2 is getting correctly calculated as ‘4’. For this, we will use “Validate element text” keyword. Now, double-click Input cell corresponding to “Verify Element Text” action and enter ‘4’ in the ‘Value’ cell.
  • For closing the browser, select the Close Browser keyword.
This completes the test script creation part. Now, we can execute our test script by clicking the ‘Run’ button. You can see the test steps getting executed in the selected browser and the result of the test as passed. Also, you can change the expected value to ‘5’ instead of the correct value ‘4’ and run the test to see it getting failed.
This concludes our post on test script creation using manual mode feature. In the next tutorial, we will study the creation of test script in script mode of Katalon Studio.

Thursday, December 18, 2014

Selenium Training Series - Getting Started with Selenium IDE


Today we are announcing to launch of Selenium training series. In this series we’ll covering all Selenium topics in details & learn Selenium from basic to advanced. After requesting many readers for Selenium topics, we are creating Selenium Training videos with practical examples which is easy to understand and learn selenium quickly. As Selenium is open source, we recommend that practice at home on Selenium Training Series which will help to get learn easily. If you have any questions then please feel free to ask questions in the comments section below. We will make sure all relevant questions get answered. Keep eye on all Selenium series of training articles, so that you won’t miss any topic.

1 – Getting Started with Selenium IDE
2 – Difference between selenium IDE, RC & WebDrive
3 – What is Selenium Webdriver? – Selenium Training Serie
4 – How to run your first Selenium WebDriver script
5 – Why Selenium Server not required by Selenium WebDriver?
6 – How to Create Project in Eclipse IDE 
7 – How to create Selenium WebDriver Test using Selenium IDE?
8 – Start Selenium WebDriver Test Script on your ow
9 – Introduction to JUnit Annotations
10 – How to use JUnit Annotations in Selenium WebDriver Automation Script?
11 – Introduction of TestNG framework


What is Selenium IDE?

Selenium IDE is simple, easy to learn & portable record and play tool for web applications. Learning curve for Selenium IDE is less & no need to learn test scripting language. It is open-source tool & available for download for free. Selenium IDE means Integrated Development Environment (IDE) used for selenium tests. It is come in terms of Firefox extension & used for recording, editing & playback scripts.

Features of Selenium IDE:

  • Simple & easy record and playback
  • Supports intellectual field selection options like ID’s, XPath, and Names.
  • Support for Selenium user-extensions.js file
  • Clever option for adding different assert options in scripts
  • Save test scripts in several formats like Selenese, Ruby and many more formats.
  • Supports Walkthrough tests
  • Allow to customization through plug-ins easily
  • Allow to set breakpoints & debug the scripts.
  • Supports Auto-complete commands

Installation of Selenium IDE:

To learn Selenium-IDE, first you have to download Firefox & Selenium IDE extension on Firefox. Here are the simple steps to be followed to install Selenium IDE: 1) Download Firefox browser (if required) 2) Get Selenium IDE here.
Download Selenium IDE for Installation
Download Selenium IDE for Installation
3) Install Selenium IDE plugin on Firefox browser 4) Restart Firefox. 5) Navigate to Tools menus & click on newly added Selenium IDE (Ctrl + Alt + S) option.
Launch Selenium IDE
Launch Selenium IDE
Now you  are ready to learn Selenium IDE!! Base URL: The Base URL field at the top of the Selenium-IDE window is very useful for allowing test cases to be run across different domains. Tool Bar:It supports different options like: Speed Control, Run All, Run, Pause/Resume, Step, TestRunner Mode, Apply Rollup Rules Test Case Listing Pane: Selenium IDE is open in new window. In the left side of the window shows the test case pan & all test cases will be listed in the section (default entry United). Multiple test cases can be added in this section & upon executing test cases all test cases are executed sequentially. Record Button: On the right side of the window you will see Record ON/OFF button, using this you can record start and stop the script recording. Test Case Pane: It’s test script editing window where your script is displayed in this section. It has two tabs, one for displaying the command and their parameters in a readable “table” format. The “Command” column displays the commands that takes the the action & values in this columns are very straight-forward like: open, click, select etc. The “Target” column displays the what you are trying to interaction with command. It can be represented a variety of ways:
  • URLs – “/dashboard.action” – represents a url. The first part of the URL is the Base URL up at the top, and this URL is relative to that.
  • Text – “link=Recording a Test” – the text of the link
  • XPath – “//input[@value=’Search’]” – XPath is an XML-like language that can be used to specify the location of an element in a document
  • Label – “label-Selenium IDE” – selects the item with the visible label of Selenium IDE.
  • HTML id – “spacelink-SIDE” – this is the HTML id of the link
  • HTML name = “searchQuery.queryString”
The “Value” column used to pass if any data pass to command. If you explore more on above three options then The best way to understand these values is to click on the command you are trying to use, and look at the bottom, on the Reference tab. It will give you information on how the command works, and what all the arguments are. Log Pane: At the bottom of the window you will see the Log panel where you can get the log generated once the test case is executed. It allows you to resize the all pans. Selenium IDE window is look like as:
Getting Started With Selenium IDE
Getting Started With Selenium IDE

Recording the first test case using Selenium IDE:

In the section we are seeing how to record the test case & re-run the test cases:
  • Launch Firefox browser
  • Enter URL https://www.google.com
  • Navigate to Firefox menu Tools > select Selenium IDE option
  • Confirm the Record button present in the right side of the toolbar is switched ON.
  • In Google website enter search for “Software Testing Class”
  • Click on Record button again to stop recording.
  • Click on Run button to playback recorded test.
  • The result will display something like this:
The first test case in Selenium IDE
The first test case in Selenium IDE

Difference between selenium IDE, RC & WebDriver

Selenium is an automation testing tool used to automate various types of applications. It consists of three main parts Selenium IDE, Selenium RC & Selenium WebDriver. In today’s date the WebDriver is the latest version of the Selenium. In today’s article we are seeing what is actual “Difference between selenium IDE, RC & WebDriver“. Also we gonna take a look at
What all different testing Frameworks can be used along with Selenium.
The Selenium IDE is basically something having record & playback options which present in the every automation tool like QTP, Sliktest etc. & also has very good user interface. The core part of Selenium IDE is based on JavaScript & also supports different extension in it. Along with record & playback, you can use Selenium IDE for multiple dynamic stuffs. The main limitation of Selenium IDE is that, it supported in only Firefox browser. If you want to execute your scripts on different browsers, then you can use Selenium RC (Selenium Remote Control). The Selenium RC supports multiple browsers like IE, Firefox, Chrome, Safari, Opera etc.
It also supports multiple languages like Java, Ruby, C#, Perl, Python etc. You have to get expertise in one language (preferred Java language) & code in selenium RC. The application under test in developed in C# & it does not matter the to create your script in the Java or C# or in any language. It’s totally independent on which your testing is carried out. Similar to language independent it is also platform independent, same code will work on Windows OS, Linux, Mac & Solaris. Most common extension used in the selenium RC is the Java Extension, because Java is platform independent language. Similar to Selenium IDE, the RC is also has its limitations. Before start testing, we have to start & stop the server to execute you test.
Difference between selenium IDE, RC & WebDriver
Difference between selenium IDE, RC & WebDriver
So to overcome the all issues & increase the scope of Selenium RC, introduced new version of SE called Selenium WebDriver. WebDirver is come up with the some cool features. Also supports the multiple languages. Main feature over the Selenium RC is that we don’t have to start the server in the Selenium WebDriver. One of the cool feature is that it supports the Android Testing & iPhone testing as well.
The code of WebDriver look different than RC & IDE, it allows you to convert the IDE code to WD & RC code. As IDE supports with the user interface but WebDirver & RC does not have UI, we have to use core programming language in it.

What are difference between Selenium IDE, RC and WebDriver

Selenium IDE
Selenium RC
Selenium WebDriver
It only works in Mozilla browser.It supports with all browsers like Firefox, IE, Chrome, Safari, Opera etc.It supports with all browsers like Firefox, IE, Chrome, Safari, Opera etc.
It supports Record and playbackIt doesn’t supports Record and playbackIt doesn’t supports Record and playback
Doesn’t required to start server before executing the test script.Required to start server before executing the test script.Doesn’t required to start server before executing the test script.
It is a GUI Plug-inIt is standalone java program which allow you to run Html test suites.It actual core API which has binding in a range of languages.
Core engine is Javascript basedCore engine is Javascript basedInteracts natively with browser application
Very simple to use as it is record & playback.It is easy and small APIAs compared to RC, it is bit complex and large API.
It is not object orientedAPI’s are less Object orientedAPI’s are entirely Object oriented
It doesn’t supports of moving mouse cursors.It doesn’t supports of moving mouse cursors.It supports of moving mouse cursors.
Need to append full xpath with ‘xpath=\\’ syntaxNeed to append full xpath with ‘xpath=\\’ syntaxNo need to append full xpath with ‘xpath=\\’ syntax
It does not supports listenersIt does not supports listenersIt supports the implementation of listeners
It does not support to test iphone/Android applicationsIt does not support to test iphone/Android applicationsIt support to test iphone/Android applications

What all different testing Frameworks can be used along with Selenium?

When we use selenium, then we make scripts like Script1, Script2, Script3… etc. & execute the script. Sometimes to execute script we have to get the test data from XLS file or user. To read the data from XLS file, the process of reading the data from XLS file is called Parameterization. Along with this you have to generate the test reports, we need to know what happened after executing the script, is script Passed or Failed? Also along with the reports you need to add logging as well. If your script is taking more time to execute script then you need to know what happened at each and every minute, you need to log each & everything to get idea what script is doing & also at what point script is failed & why.
So we need a centralized controller which will read the test data, execute the test cases, generate reports & do the logging as well. In the market two frameworks are available for testing. So that the centralize testing controller are TestNG OR JUnit framework. You can use selenium with TestNG or JUnit framework. These frameworks will execute the test scripts. They will read the data from XLS file generate the reports & also do the logging while executing the scripts. How to started with these testing frameworks can be seen in next couple of articles to get hands on it.
If you missed any article in this Selenium training series please check all articles on this page: Selenium Training Tutorials. You can also share this article using multiple sharing options below with your friends.

What is Selenium Webdriver? - Selenium Training Series

In the previous article we have learned about the Difference between selenium IDE, RC & WebDriver. In Selenium Training Series today’s article will move to What is Selenium WebDriver?, Advantages of Selenium WebDriver & what all features in it.
Basically Selenium IDE is record play back tool & its disadvantage is that, it only works with Firefox plug-in. To overcome this problem, new version of Selenium was introduced i.e. Selenium1.0 RC (Remote control server). It is powerful tool & supports multiple browsers. But nowadays websites are more robust in terms of security & websites using rich API. Also Android market is growing day by day. Selenium RC is powerful tool but cannot support Android & other features, so RC lagging behind the market for automation testing tool. To overcome these problems & supports Android, website Rich API’s & many new features introduced latest version of Selenium WebDriver.

What is Selenium WebDriver?

Selenium WebDriver supports many more powerful features which are not supported in the primitive Selenium rc 1.x. Learning curve for Selenium Web Driver is less, as you don’t need to have knowledge of Selenium RC and you can directly start working on WebDriver. One advantage over Selenium testing on RC is that you don’t need to start the server prior to executing test scripts. The goal of the WebDriver’s to provide a well-designed object-oriented API which gives you the enhanced hold up for modern advanced web-app testing problems. Also WebDriver is supporting dynamic web pages where elements of a page may change without the page itself being reloaded. The main contribution ofSelenium WebDriver is that it’s API and the native drivers.
What is Selenium Webdriver?
What is Selenium Webdriver?
Selenium Web Driver is a tool for writing automated tests of websites. It aims to mimic the behavior of a real user, and as such interacts with the HTML of the application.
I like about WebDriver is, it provides a user friendly API which you can understand and explore easily, as a result it will help to read & maintain your script easier. As it is not tied with any specific framework, so it allows you to easily integrate with testing framework like JUnit or TestNG (We will see these frameworks in our upcoming training series articles).
The more pain while doing automation is the handling Javascripts alerts & prompts. The WebDriver very verse with handle the Javascript alerts, prompts and handling multiple frames, multiple browser windows. Selenium-WebDriver supports multi browsers multi OS, it uses browser’s native support for automation to make direct calls to the browser. The WebDriver supports multiple browser like FirefoxDriver, ChromeDriver, InternetExplorerDriver, SafariDriver etc. The direct calls are made to each browser is depends on which browser you are using.
Advantages of Selenium WebDriver:
  1. Improved features & functionality which were not supported in the Selenium 1.0.
  2. No need to start server prior to start executing scripts.
  3. Added advantage to support for iPhone and Android testing
  4. Similar to QTP, It allows you to extract the objects in bulk. In RC this is big pain to extracting the objects.
  5. It supports features like Page navigation, Drag-and-drop and AJAX-based UI elements.
  6. Using WebDriver can easily find the coordinates of any object.
  7. WebDriver is open source & it allows you to easily integrate with testing framework like JUnit or TestNG.
  8. It allows you to simulate the mouse movements.
  9. It provides the improved reliability between browsers.
  10. A most awaiting feature added in WebDriver is “Implementation of listeners”.
  11. For web application testing, it provides standard programming interface.
  12. It allows you to simulate keyboard key press events using different classes.
  13. You have classes in Webdriver which help you to simulate key press events of keyboard.
  14. It allows you to simulate the clicking of browser front and back button.


How to run your first Selenium WebDriver script - Selenium WebDriver Tutorial

In previous article we have seen about What is Selenium Webdriver?In this article we are concentrating on implementation of the WebDriver, we will see how to selenium webdriver download and configure the Selenium Webdriver with Eclipse & run your first selenium web driver script.
Selenium WebDriver installation is divided in to simple steps to get & learn how to Install & configure WebDriver to kick of your automation testing. Also we will run your first automation script using WebDriver.

Step 1) Download & Install Java on your Computer

Before start working with the Learn Selenium WebDriver, we will need the first download Java Development Kit (JDK).
Here you can download Java Development Kit (JDK).
Download Java Development Kit (JDK)
Download Java Development Kit (JDK)
Step 2) Install Eclipse on your computer
Eclipse is open source software development environment written in Java. It supports supports multiple languages. In this tutorial we will using Eclipse to write the code in Java & execute your first test script.
Here you can download “Eclipse IDE for Java Developers
Make sure that you are downloading correct version of Eclipse based on the Windows 32 or 64 bit version.
Download “Eclipse IDE" for Java Developers
Download “Eclipse IDE” for Java Developers
Once you select the windows version based on your requirement, you should be able to download a “eclipse-java-juno-SR2-win32-x86_64.zip” ZIP file.
Once you successfully download the ZIP file, extract the ZIP file in your PC.
For Eclipse, you do not need any installation; just double click on “eclipse.exe” file in the extracted ZIP folder.

Step 3) Download Selenium Java Client Driver

Selenium client driver is available in the different languages like Java, C#, Ruby, Python etc. But in this article we are concentrating on Java language.
Here you can download “Selenium Java Client Driver
Download “Selenium Java Client Driver”
Download “Selenium Java Client Driver”
Once you click on Download link for Java client then you should be able to download a “selenium-java-2.31.0.zip” ZIP file.
Once you successfully download the ZIP file, extract the ZIP file in your PC in the directory “C:\selenium- java-2.31.0”. You will see JARs files in extracted folder which would be imported in to Eclipse before running our first Selenium WebDriver script.

Step 4) Configure Eclipse with Selenium WebDriver

In Step 2 we have installed Eclipse, just Launch the “eclipse.exe” file from the extracted Eclipse folder.
Once you open the “eclipse.exe” file then it will ask you to select the workspace, here you can select the path where you want to save Eclipse project.
Selenium WebDriver workspace in eclipse
Selenium WebDriver workspace in eclipse
First step is to create a Java Project:
  • Go to File menu > New > Java Project.
  • Enter Project Name as “Selenium_webdriver_project”
  • Click on Finish button.
Create Java Project - Selenium WebDriver
Create Java Project – Selenium WebDriver
Second step is to create a Class under Java project:
  • Under newly created project “Selenium_webdriver_project” you will see the “src“ folder & right click on the “src” folder & create the new class as “Webdriver_class”.
Create Java Class - Selenium WebDriver
Create Java Class – Selenium WebDriver
Once you created the class you will see the Eclipse screen like this.
Start with Eclipse
Start with Eclipse
  • Right click on “Selenium_webdriver_project” & select Properties option.
  • Select “Java Build Path” option in the left side of the Properties dialog box.
  • Click on Libraries tab
  • Click on “Add External JARs..” button.
  • Select the extracted Selenium Java Client Driver folder downloaded in Step3 & add all JAR files present in the inside & outside of the “libs” folder. Once you select these JAR files then your properties folder will look like as below.
Import External- Selenium Client JAR Files
Import External- Selenium Client JAR Files
  • Click on OK in the Properties dialog box to import.

Step 5) Run your first Selenium WebDriver script.

Once you complete the Step 1 to Step 4 then you are ready to execute your first WebDriver script. You can just copy paste the code written below & click on Run button to execute your first script. Code below which is written to opens the new Firefox browser window & open the Google page in it. It also read the Title of the page & close the browser window.
//Run yout First Selenium WebDriver script by copy paste below code after executing above five simple steps.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Webdriver_class
{
   public static void main(String[] args)
   {
       WebDriver driver = new FirefoxDriver();
       driver.get("http://google.com");
       System.out.println(driver.getTitle());
       driver.close();
   }
}

Why Selenium Server not required by Selenium WebDriver?

In previous article we have seen about Difference between selenium IDE, RC & WebDriver.
As we already know Selenium RC requires starting the server to kick of the execution of Selenium Automated RC test suites. The Selenium server is the intermediator between browser and Selenium RC because Selenium RC won’t make direct call to browser. So we have to start Selenium server prior to start running Selenium RC test cases.
In case of Selenium WebDriver, it does not required to start Selenium Server for executing test scripts. Selenium WebDriver makes the calls between browser & automation script. Selenium WebDriver has native supports for each browser to supports Test Automation; on same machine (both Selenium WebDriver Automation tests & browsers are on same machine.)
We use FireFox native support to execute the Selenium Test Automation script with the FireFox browser. In the Selenium WebDriver there are different browsers are supported like FireFox, Chrome, and Safari etc. To execute the Test Automation on different browsers we have to add its libraries to our Selenium WebDriver to execute automation tests.
Here we have seen because of different browsers native supports, we don’t need to start the Selenium Server before running the test scripts.
But it might be possible to use Selenium server while running Selenium WebDriver test scripts if bothSelenium WebDriver Automation tests & browsers are on different machine. This is possible while using Selenium Grid, because of executing different test scripts simultaneously on different machines to save the execution time. If we have to execute the test suite having 5 independent test cases that might take 5 days to finish, so we use Selenium Grid with 5 machines & execute test cases simultaneously to finish the automation test cases in 1 day.
So in this article we have seen that why Selenium Server not required by Selenium WebDriver when the both Selenium WebDriver Automation tests & browsers are on same machine. In next article I will explain how to Create a JUnit Selenium WebDriver Test using Selenium IDE.
If you enjoy reading this article please make sure to share it with your friends. Please leave your questions/tips/suggestions in the comment section below and I’ll try to answer as many as I can.

How to Create Project in Eclipse IDE?

Before start creating project in Eclipse IDE, the latest Java & Eclipse IDE should be installed on your machine. We have covered how install the Java & Eclipse in our previous article “How to run your first Selenium WebDriver script – Selenium WebDriver Tutorial” (First three steps). Once you complete the installation of both Java & Eclipse IDE, you can begin creating the project in Eclipse IDE.

To create a project in Eclipse IDE, you have to follow some simple steps:
1) Navigate the extracted Eclipse software zip file showing in following screen shot (Download latest version of Eclipse here: http://www.eclipse.org/downloads/):

open-extracted-eclipse-ide-folder

2) In the extracted Eclipse folder double click on the Eclipse Application file to launch the Eclipse application same as mention in the below screenshot:

open-eclipse-application

Eclipse will take some time to launch the Eclipse welcome window, so wait for little time.

3) Eclipse will ask you to select the workspace, here you can select the path where you want to save Eclipse project. Once you enter the path click on OK button shown as mention below screen shot:

eclipse-set-workspace

4) Eclipse will setup the workspace path & launch the Eclipse Welcome window first time as below, this means that eclipse ide is successfully installed on your machine.

eclipse-welcome-window

5) Go to File menu > New > Java Project.

eclipse-new-project

6) Enter Project Name as “First Project”:

java-project-in-eclipse

In New Java Project window under JRE section select “Use Project specific JRE” radio option & select any value from the JRE version (here I am selecting ‘jre7’). Everytime you have to select the JRE version based on the project.

7) In New Java Project dialog click on Finish button.

create-java-project

8) The new java project called “First Project” is created here & you can see the name of the project in the left section in the below screenshot:

first-eclipse-java-project




How to create Selenium WebDriver Test using Selenium IDE? - Selenium Tutorial

Today we are going to see how we can record the test case using Selenium IDE & convert recorded script to Java WebDriver format & execute the automated test script using Eclipse. To start with you should have Eclipse, Java & Firefox installed on your machine. You can refer this article “How to run your first Selenium WebDriver script” to set up your environment & ready to execute your first selenium testing tool tutorial.





A. Record a Test case using in Selenium IDE

1) Launch FireFox & open to Selenium IDE by selecting “Tools > Selenium IDE” option.

launch selenium ide

2) Make sure that Selenium IDE window is opened. In Selenium IDE the recording option is turned ON by-default.

Selenium IDE Window

3) Launch FireFox browser & enter URL as www.google.com same as shown below:
In Google Home page enter search keyword as Google and click on “Google Search” button as shown below:

Selenium WeDriver Google Search

4) Once the recording is done, you will able to see the recorded command in the command section. Turn off the recording option same as mentioned below. Upto this point you have successfully recorded script in Selenium IDE.

Selenium WeDriver Recorded Commands

B. “Enable Experimental Features” from Selenium IDE options

1) Navigate to Options > Options
In Selenium IDE option, select “Enable Experimental Features” check box.

Selenium IDE Enable Experimental Features

2) Navigate to Options > Format & select the “Java/ Junit 4 / WebDriver” option.

JavaJunitWebDriver1

3) JavaScript Application dialog will be display. Click on OK button.

Java/Junit/WebDriver2

4) Now you will able to see the Java code is displayed in Selenium IDE – Source tab. This code will be used for creating Selenium WebDriver code.

Java/Junit/WebDriver3

C. Create “firstPackage” under Selenium WebDriver project

1) In previous article we have learnt about “How to Create Project in Eclipse IDE?
Launch Eclipse IDE & open same project created in above step.
Right click on project name select option, New > Package.

Selenium WebDriver First Package

2) In New Java Package dialog enter Name as “firstPackage”

Eclipse new java package

3) Once you created the first package, ensure that it is added under “src” folder same as below:

Created first package in Eclipse

4) Right click on newly created package “firstPackage” select option, New > Class.

Create Class in Eclipse

5) In New Java Class dialog box enter class name in Name text box as “GoogleSearch” shown in below screenshot:

Eclipse Class Name

6) Once you created the “GoogleSearch” class, ensure that it is added under “firstPackage” folder same as below:

Eclipse Google Search Class

6) Now copy the Java/Junit4/WebDriver format converted code to from the previously recorded in Selenium IDE Source tab (Step A4).
Without deleting existing code paste the above recorded in Selenium IDE copied code below as shown below:

Selenium java/junit4/webdriver converted code

7) Upon pasting the code you will display some errors in the eclipse, don’t worry in next few steps we are resolving the all errors:

Selenium java/junit4/webdriver converted code error

8) Now in the code you experience that there are two packages, first is “package firstPackage;” & second is the “package com.example.tests;”.
The Class is allow to declare only one package but the copied code is added new package. So copied package is not present in the Eclipse IDE, so let’s comment out the package name “package com.example.tests;”.

Selenium code comment extra package

9) Once you resolve the more than one class declaration error then you will observe few warning messages as shown below:

Selenium code comment extra class

D. Remove the warning messages

1) We can see there are three warning messages shown in the below screen shot. To remove these warning messages, remove or comment the warning message lines.

Selenium WebDriver - comment warning message

2) Two methods called isElementPresent & closeAlertAndGetItsText methods are never used locally, so let’s comment out these two method sections:

Selenium code comment never used methods

3) One more warning message will get displayed once you commenting unwanted methods:

accept-next-alert

4) To resolve this problem comment out this line as this is never require while executing the code & click on Save All button shown below:

Save All Selenium WebDriver code

Download Code – Below is the final converted code from recorded Selenium IDE code. You can also copy below code & use directly.
package firstPackage;

//import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
//import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.support.ui.Select;

public class GoogleSearch {
  private WebDriver driver;
  private String baseUrl;
  //private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "https://www.google.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testGoogleSearch() throws Exception {
    driver.get(baseUrl + "/");
    driver.findElement(By.id("gbqfq")).clear();
    driver.findElement(By.id("gbqfq")).sendKeys("Google");
    driver.findElement(By.id("gbqfb")).click();
  }

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }
/*
  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alert.getText();
    } finally {
      acceptNextAlert = true;
    }
  }
  */
}

Here we have completed updating the Selenium WebDriver code in Eclipse. Before executing the script please make sure that Firefox browser is installed in your machine as we have used Firefox browser libraries. When you click on Run icon (Ctrl+F11) then your Selenium WebDriver code will be executed successfully.

Conclusion:

1) We have recorded a Test case using in Selenium IDE recording feature.
2) “Enable Experimental Features” from Selenium IDE options & converted generated HTML code to JUnit 4/Java/WebDriver format.
3) In Eclipse, created “firstPackage” & Class under Selenium WebDriver project & pasted above automated generated code in class.
4) One by one resolved all error & warning messages observed in code.

Introduction to JUnit Annotations - Learn JUnit annotations used for your Selenium WebDriver automation

In previous article we have covered on Start Selenium WebDriver Test Script on your own – Selenium Tutorial. I have used “@Test” annotation in the script, one of our reader ask in comments about “what is use of annotaions & why we added @Test annotation”. So I have started writing this post to clear the concept of what is JUnit Annotations & what are different JUnit annotations with meaning of each. Also what is different testing framework used in Selenium WebDriver automation other than JUnit.

What is JUnit Annotations?

JUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development. To execute Selenium WebDriver testing using JUnit we have to add JUnit annotations in your test.
Introduction to JUnit Annotations

Different JUnit Annotations:

We are using following most commonly used five annotations in our Selenium WebDriver test scripts:
  1. @Test
  2. @Before
  3. @After
  4. @BeforeClass
  5. @AfterClass
Test methods must be annotated by the @Test annotation. If the situation requires it, it is also possible to define a method to execute before or after of the test methods with the @Before or @After and @BeforeClass or @AfterClass annotations.
Let’s elaborate on these JUnit annotations here:

@Test

The annotation @Test identifies that a method is a test method. When it is mentioned as @Test before a test method, it tells JUnit framework that the following is a Test Method.

@Before

The @Before annotation is used to identify the method which is executed before executing the Test Method. This method can be used to set up the test environment.

@After

The @After annotation is method which is executed after executing the Test Method. This method can be used to do teardown i.e. deleting temporary data or setting up default values or cleaning up test environment etc.

@BeforeClass

The @BeforeClass method is used only once before start all tests. Basically this is used to perform time intensive activities, like connect to a database.

@AfterClass

The @AfterClass method is used only once after finish executing all tests. Basically this is used to perform clean-up activities, like disconnect from a database.
In upcoming article the we will use above listed JUnit annotations and create the Selenium WebDriver automation tests.

Different Testing Frameworks:

TestNG is a one of the more popular testing Framework used as alternative to JUnit testing Framework. It supports multiple advantages, powerful and unique features in the TestNG framework. As JUnit is comes with Eclipse so we don’t want to install separately. For TestNG testing framework we have to install this explicitly in Eclipse.
Many people’s are using JUnit testing Framework as it is come with Eclipse by default. It is simple & easy to use that why we have started with JUnit testing framework to execute Selenium WebDriver tests. Once time comes we will see how to install TestNG testing framework & how to execute test using this powerful framework.
In next Selenium Tutorial article, we are using above explained JUnit annotations and will explain “How to run a Selenium WebDriver Test with different JUnit Annotations” in this post. If you like this article then make sure to share it with your friends & please leave your questions/tips/suggestions in the comment section below and I’ll try to answer as many as I can.

How to use JUnit Annotations in Selenium WebDriver Automation Script

In our previous article we have learned basic Introduction to JUnit Annotations used in your Selenium WebDriver Automation Test script. Now I want to give you brief idea about how to use these JUnit Annotations & what is actual use in the Selenium WebDriver code.
In Selenium WebDriver if you want to run test script using JUnit framework we have to add few JUnit Annotations in Selenium WebDriver Test script.
Below we are using few most commonly used JUnit annotations & execute our Selenium WebDriver Tests:
  1. @Before
  2. @Test
  3. @After
Let’s open previously created project in Eclipse IDE (click here to get How to create Selenium WebDriver Test using Selenium IDE? – Selenium Tutorial)
1) Once you open the above created Selenium WebDriver Test script and then check if have we used JUnit annotations in the code or not?
Junit Annotations Used In Selenium Webdriver Code
2) The highlighted part in above script is saying that we have used JUnit annotation in Selenium WebDriver code. In this script we have used @Before, @Test and @After annotations.
@Test
When we Run the script as JUnit then all the methods specified below @Test are executed using JUnit Test. As @Test JUnit annotation is specified before the testUntitled() method, this method will be executed when we run the “GoogleSearch” class using JUnit (i.e. Run As > JUnit Test)
Test Annotation Used In Selenium Webdriver
@Before
All the methods are defined in the @Before are executed first & then method which are defined in @Test are executed. The primary use of this annotation is used to set up the test environment which is needed for executing the test. You can in below screen shot we have used setup() method in @Before.
@After
All the methods are defined in the @Test annotation are executed first & then method which are defined in @After are executed. The primary use of this method is to do tear down i.e. deleting temporary data or setting up default values or cleaning up test environment etc.
Here @After annotation is specified before the ‘teardown()’ method. Hence this method will be executed by JUnit after executing all methods that are specified with @Test Annotation.
After Annotation Used In Selenium Webdriver

Run Selenium WebDriver Test Code without JUnit Annotaions:

Now let’s try to run Selenium WebDriver Test Code with commenting JUnit Annotaions & check if you are able execute test code as JUnit Test or not.
1. Comment all three Annotations line as shown in below screen shot. To comment line we have to add // before each line which we have to comment.
Comment Test Annotation Used In Selenium Webdriver
2. Run the Selenium WebDriver Test code with JUnit Test after commenting the annotations as shown below:
Junit Option Not Present
Now you understand if we are not using JUnit annotations in the Selenium WebDriver code then while running the code you cannot able to run the code as JUnit Test.
3. Now let’s uncomment annotations same as shown in below screen shot & check if you able to run the test using JUnit or not:
Uncomment Test Annotation Used In Selenium Webdriver
4. Have you notice that if we try to Run Selenium WebDriver code then the JUnit Test option is available as shown below:
Junit Option Present
So till now we have learned we can run the code using JUnit only if the JUnit annotations added in the code else Run As > JUnit Test option will not be available to Run the test.


Introduction of TestNG framework - Advantages of TestNG over Junit framework

In Selenium WebDriver training tutorial we have seen how to run Selenium scripts using JUnit framework. Until now we have execute selenium tests but we have not generated reports in JUnit. In this Selenium training article series we are introducing powerful new testing framework called TestNG. The TestNG framework means Next Generation testing framework, so we are seeing what all next generation features available in TestNG, also I will talk about advantages of TestNG over Junit. I will be discussing about different ways of using TestNG features in my coming articles.
I do not say that don’t use JUnit, but you should really consider using TestNG for your next project. Apparently TestNG is more complete and clean than JUnit.

What is TestNG?

TestNG is testing framework inspired from most popular JUnit framework used for the Java programming language. The TestNG framework is introduced to overcome the limitations of JUnit framework. Most of the automation users are using this framework because of its advantages & more supported features. Until we have executed selenium test script but not even generated test reports. So using this TestNG framework we will learn how to generate test reports.
TestNG Framework

Features of TestNG Framework:

TestNG supports many powerful features & it is easy to use. Let’s see what all new features are supported in new testing framework:
  • Support for parameters.
  • Supports dependent methods testing.
  • Test configuration flexible.
  • Supports powerful execution model.
  • Embeds BeanShell for further flexibility.
  • TestNG has a more elegant way of handling parameterized tests with the data-provider concept.
  • For the same test class TestNG support for multiple instances.
  • Extendibility of using different Tools and plug-ins like Eclipse, Maven, IDEA etc.
  • Default JDK functions for runtime and logging (no dependencies).
  • Supported different Annotations like @BeforeSuite, @AfterSuite, @BeforeClass, @AfterClass, @BeforeTest, @AfterTest, @BeforeGroups, @AfterGroups, @BeforeMethod, @AfterMethod, @DataProvider, @Factory, @Listeners, @Parameters, @Test.
TestNG supports annotations which are very helpful to guide test case executions. Similarly in JUnit, the TestNG annotations are always preceded by the ‘@’ symbol. It permit you do parallel execution of test cases & we can also skip the test cases effortlessly while executing test cases.
TestNG is specially designed to cover all types testing categories like Unit, Functional testing, Integration testing, End-to-end etc. Using TestNG framework allows us to generate test reports in both HTML and XML formats. Using ANT with TestNG, we can generate primitive Testng reports as well.

Advantages of TestNG over Junit:

  1. In TestNG Annotations are easy to understand over JUnit.
  2. In TestNG there is no constraint like you have to declare @BeforeClass and @AfterClass, which is present in JUnit.
  3. As method name constraint is present in JUnit, such method name constraint is not present in TestNG and you can specify any test method names.
  4. In TestNG enable you to grouping of test cases easily which is not possible in JUnit.
  5. TestNG supports following three 3 additional setUp/tearDown level:
    @Before/AfterSuite, @Before/AfterTest and @Before/AfterGroup.
  6. TestNG do not require extend any class.
  7. TestNG allows us to define the dependent test cases each test case is independent to other test case.
  8. TestNG allows us to execute of test cases based on group. Let’s take a scenario where we have created two set of groups “Regression” & “Sanity”. If we want to execute the test cases under Sanity group then it is possible in TestNG framework.
  9. Parallel execution of Selenium test cases is possible in TestNG.