Learn How To Build and Execute Selenium Projects

Last updated on Sep 11,2024 18.6K Views
A tech enthusiast in Java, Image Processing, Cloud Computing, Hadoop. A tech enthusiast in Java, Image Processing, Cloud Computing, Hadoop.

Learn How To Build and Execute Selenium Projects

edureka.co

In the previous articles on Selenium, we have covered the fundamentals of testing like Selenium IDE, Locators, WaitsSelenium Grid, TestNG etc.  In this ‘Selenium Projects’ article, I will be demonstrating as to how you can implement the above concepts and get a tight grip over them. This, in course, will help you to test your skills for project analysis, development and handling skills on the whole. 

You may also go through this recording of Selenium Projects by Selenium Certified Experts in the Selenium Certification Training where you can understand the topics in a detailed manner with examples.

 

Introduction to Selenium

Selenium is the preferred tool when it comes to automating the tests which are carried out on web browsers. With Selenium, only testing of web applications is possible. Any desktop (software) application or mobile application cannot be tested using Selenium. It is very helpful to write functional test cases. It also provides reliable performance with n number of test cases and it is obviously the best suitable automation tool for web applications.

Now let’s dive into this article and look at the interesting projects that help you in understanding more about Selenium.

Selenium Projects

The only way with which you can enhance your knowledge on Selenium is by working on some real-life projects. In this article, I will be discussing two important projects and a few case studies as well.

Let’s begin with our first project.  

Automating Edureka Website

Problem Statement 1: Consider a candidate who has registered for edureka portal wants to update all the personal details and career interests available in the portal. Now the task is to write a Selenium script to do the same and also explore the edureka portal.

Steps:

  1. Login to the Edureka
  2. Navigate to ‘My Profile’
  3. Update professional and personal details
  4. Explore the blogs and navigate to the Main page
  5. Logout of the portal

NOTE: Make sure that you are logged out of Edureka’s website while performing this practical.

Solution

Let’s now have a look at the code to understand this better.

package edureka;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
public class HandlingAllControls {
static WebDriver driver;
@Test( priority = 0)
public void EdurekaProfile() throws InterruptedException{
System.setProperty("webdriver.chrome.driver","C:Selenium-java-edurekachromedriver_win32chromedriver.exe");
driver = new ChromeDriver();
//Put a Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
//Launch the Edureka Website
driver.get("https://www.edureka.co/");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.findElement(By.linkText("Log In")).click();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.id("si_popup_email")));
Thread.sleep(2000);
actions.click();
actions.sendKeys("TestingEdureka@gmail.com");
Thread.sleep(2000);
actions.build().perform();
actions.moveToElement(driver.findElement(By.id("si_popup_passwd")));
Thread.sleep(2000);
actions.click();
actions.sendKeys("12345678");
Thread.sleep(2000);
actions.build().perform();
actions.moveToElement(driver.findElement(By.xpath("//button[@class='clik_btn_log btn-block']")));
Thread.sleep(2000);
actions.click();
actions.build().perform();
driver.findElement(By.xpath("//a[@class='dropdown-toggle trackButton']//img[@class='img30']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//ul[@class='dropdown-menu user-menu profile-xs hidden-sm hidden-xs']//a[@class='giTrackElementHeader'][contains(text(),'My Profile')]")).click();
Thread.sleep(2000);
WebDriverWait waitElement = new WebDriverWait(driver,20);
waitElement.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li[@class='active']//a[@data-toggle='tab'][contains(text(),'My Profile')]")));
driver.findElement(By.xpath("//li[@class='active']//a[@data-toggle='tab'][contains(text(),'My Profile')]")).click();
String Pagetitle = driver.getTitle();
driver.findElement(By.xpath("//div[@class='personal-details']//i[@class='icon-pr-edit']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//input[@placeholder='Name']")).sendKeys("Edureka");
Thread.sleep(2000);
System.out.println("b");driver.navigate().to("https://learning.edureka.co/my-profile");
Thread.sleep(2000);
System.out.println("a");
System.out.println("abc");
driver.navigate().to("https://learning.edureka.co/onboarding/careerinterests");
Thread.sleep(3000);
Select dropdownCurrentJob = new Select(driver.findElement(By.xpath("//select[@name='interestedJob']")));
Thread.sleep(2000);
dropdownCurrentJob.selectByVisibleText("Software Testing");
Thread.sleep(2000);
Select dropdownEmployementType = new Select(driver.findElement(By.xpath("//select[@name='elementType']")));
Thread.sleep(2000);dropdownEmployementType.selectByVisibleText("Both");
Select dropdownCTC = new Select(driver.findElement(By.xpath("//select[@name='lastDrawnSalary']")));
Thread.sleep(2000);
dropdownCTC.selectByVisibleText("Not applicable");
driver.findElement(By.xpath("//label[contains(text(),'Yes')]")).click();
Thread.sleep(2000);
driver.findElement(By.name("preferredCity")).sendKeys("Mumbai");
Thread.sleep(2000);
driver.findElement(By.xpath("//button[@type='submit']")).click();
Thread.sleep(2000);
driver.navigate().to("https://learning.edureka.co/");
Thread.sleep(2000);
driver.findElement(By.xpath("//span[@class='user_name']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//a[contains(text(),'Log Out')]")).click();
Thread.sleep(2000);
System.out.println("a");
try {Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

So, when you execute the above program, the Chrome driver will launch Google Chrome, navigate to edureka.co website and enter the login username and password. After that, it will navigate through my profile and update the personal and professional details and then log out of the account. So everything will be automated with the help of Selenium.

Now let’s understand the next project.

Automating Flight Booking Application

Problem Statement 2: Let’s consider this particular project where we will try automating the process of booking a flight. Let’s take a look at how it’s done using Selenium.

Let’s divide the process into the various steps to understand the working of a project in a better way.

Steps:

  1. We’ll start with initializing the browser driver and then log in to the web page
  2. Find the flight according to the user requirements
  3. Select a flight and book it
  4. Capture a screenshot of the confirmation page

Now let’s have a look at the steps involved in the creation of this project.

Solution

Step 1: Create a Java Project

Go to File-> Go to New-> Others -> Maven Project to create a new Java project. Below figure depicts the same.

Step 2: Add the dependencies to pom.xml file

Step 3: Create the packages

Create the packages under the src/main/java folder and the src/test/java folder and start writing the piece of code.

Step 4: Write the code to run the test cases

If you wish to know the detailed solution and the complete project, you can check out this article on Selenium Maven Project with Eclipse.

So this was all about Automating a Flight Booking application. Now let’s delve further into this article and know few important real-time case studies of Selenium.

Selenium Case Studies

Case Study 1: Enterprise Management System

Client: Information Technology Service Provider
Industry: IT
Solution Provider: Mindfire Solutions

Technologies: Selenium 3.1, Eclipse, Java, Ant

Situation

The Enterprise Management System was a complex application with many modules. Various modules of the application were used by the client and its customer organizations for corporate communication, project management, customer and sales channel management, human resource management, accounting, knowledge & learning management, internal social networking, etc.

Challenges

There were a large number of test cases to check the functionality and workflow of the application. It was becoming increasingly difficult and costly for the client to go through manual testing for any change in the application. So there was a need for automating the testing effort which needed to be very effective and efficient.

Solution

Step 1: After a thorough analysis of the application and various automation tools, Selenium seemed like the best tool for functional and regression testing and it very well suited for the client’s needs.

Step 2: Next the solution provider went through the application, understood its functionality and work‐flow, and prepared the automation plan.

Step 3: After that, they designed a high-level hybrid framework which made the scripts very easy to run even for non-technical users. Also, developed sufficient sets of scripts to be simply run whenever there was a change in the application.

Step 4: This not only saved money but the automation scripts took lesser time to run and also generated eminently readable and understandable HTML reports simultaneously.

Step 5: These HTML reports display information such as pass/fail result, script execution time, screen‐shots, etc., for each of the test cases and test steps separately. These results can also be automatically emailed through the script to any number of persons as desired.

Find out our Automation Testing Course in Top Cities/Countries

IndiaUSAOther Cities/Countries
BangaloreNew YorkUK
HyderabadChicagoLondon
PuneDallasCanada
ChennaiAtlantaAustralia
CharlotteSingapore
WashingtonUAE

Case Study 2: Automating Physical Fitness Data

In this case study, our client provides training, nutrition, and physical therapy programs by a team of specialists. They utilize the software that integrates with workout machines to provide the user with recommended training exercises based on previous workouts, weekly workout challenges, and member goals.

The client is looking to implement a functional test automation framework for their application in order to perform regression testing as new builds are released.

Challenges

The functional test automation framework must support the Google Chrome web browser. They need the framework to be implemented in such a way that script maintenance should be kept at minimal.

Strategy

Basically, the solution provider of the framework made use of Selenium WebDriver to automate business transactions. RTTS(Solution Provider) took advantage of the page object design pattern to help minimize the maintenance required once an application undergoes UI changes. 

Solution

The implemented automation framework is 100% open source and the components are as follows:

Step 1: As soon as the framework was in place, the page object design pattern was utilized to create classes for each page in the application. Page object classes provided an interface for the testers to interact with each page.

Step 2: Test scripts were then created by calling methods from the page object classes that performed specific transactions, such as login as registered user, create a new user, create a workout, etc. All work was committed to a Subversion repository for version control.

Step 3: As Selenium WebDriver lacks any built-in logging mechanism, a custom solution was used to record logs into an excel file using the open source Java API JExcel. Each command and verifications performed were logged. This actually provided a detailed view of where the test script had failed and the steps performed that caused the failure.

Step 4: Once the framework was in place and several test scripts created, training was provided to the client’s employees on the usage of Selenium 2.

Step 5: After training, the QA testers began creating test scripts for any issues that were encountered.

Step 6: At the time of scripting, majorly the issues occurred due to heavy AJAX usage in the application. As AJAX would only update a section of the application instead of the entire page, the Selenium WebDriver test script was executing commands faster than AJAX was updating the UI. Selenium Waits ExpectedConditions class was used to wait for certain conditions to be met prior to executing the next Selenium WebDriver command, such as visibility.

Step 7: Now, the report was generated after executing a test suite. To create the report, Apache Ant was used to execute the JUnit tests and generate a JUnit report. The report displayed metrics on the number of tests that failed and passed. Reports can also be drilled down to display additional information about each failure and what caused the failure to occur.

Step 8: Finally, a local server was set up with virtual machines of different operating systems that supported different browser versions. Thus, the virtual machines will serve to provide an environment in which full regression testing will be performed using the Selenium Grid.

Benefits

By choosing an open source framework, there was no cost involved in obtaining the required components to set up the framework. Additional savings were also made by implementing the Selenium Grid. Initially, the client had opted to utilize a third party company to execute Selenium WebDriver test scripts. The cost of using the third party company came in at $149/month with limits on the number of tests that could be executed. With the Selenium Grid, the client is now able to run Selenium WebDriver test scripts without any limits or fees.

I hope you found these real-life case studies interesting. With this, we come to the end of our article on Selenium Projects. I hope you guys enjoyed this article and added value to your knowledge.

Find out our Selenium Training in Top Cities/Countries

IndiaOther Cities/Countries
BangaloreUS
HyderabadUK
PuneCanada
ChennaiAustralia
MumbaiSingapore
KolkataEdinburgh

Got a question for us? Please mention it in the comments section of  Selenium Projects article and we will get back to you.

Upcoming Batches For Selenium Course
Course NameDateDetails
Selenium Course

Class Starts on 4th January,2025

4th January

SAT&SUN (Weekend Batch)
View Details
BROWSE COURSES
REGISTER FOR FREE WEBINAR Navigating the Web with Selenium and Python