Creating and Executing Automated Test Cases with Selenium & Java.



Selenium is a great tool and also one of the most popular tool for Test Automation available in the market, in this tutorial we will learn how to setup Selenium Test Automation Environment on Windows 7 Machine for Java Programming Language. This Tutorial is a part of Test automation Series in future parts we'll learn more about DOM Element locators and Executing automated TestCases using Selenium and Java.

We Have Setup Automated Test Environment in Previous Post

So let us now create a Selenium Automation Framework and Execute it

Overview

We have created a Simple Foo App The Cube Finder It basically take a number input from the user and then calcuates the Cube of the Given Number and then Displays the output. But We have Set the Compare Variable to "The Cube of 3 is 27" so if we calculate cube of any other number then case should fail.


The Case

Test Condition Expected Result Status
We Calculate the Cube of 3 The Cube of 3 is 27 Pass
We Calculate the Cube of 5 The Cube of 5 is 27 Fail

Step 1 : Write Automation Code


Importing Required Packages
This includes selenium libraries which we have added to our project in last tutorial, we are importing them into our code.


Writing the main Class and Initializing the Selenium WebDriver.
Executing Google Chrome Web Browser automatically with selenium java code.
Navigating to our Sample App


Locating input field by id and entering value '3'.
Adding an Implicit Wait time of 10 Seconds.
Locating Send button and performing click action.
Adding another Implicit Wait time of 10 Seconds.


Locating Output value and fetching text value and storing it in variable.
Adding another Implicit Wait time of 10 Seconds.
Defining a variable with static value as Expected Result.


Here we Write main logic for our Test Case.
We write an if else loop where we compare Expected Result with Actual Result and Then Display weather Test is Passed or Failed.

Step 2 : Execute Code

Execute the code by Clicking Run Button in Eclipse IDE of Pressing F5.

Execution Results

We Calculate the Cube of 3

We Calculate the Cube of 5

Conclusions

We have Sucessfully Automated Test Cases for our Cube Finder Application.

Channels :