₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,329,753 members, 8,442,041 topics. Date: Thursday, 09 July 2026 at 01:35 PM

Toggle theme

Selenium Tutorial - Education - Nairaland

Nairaland ForumNairaland GeneralEducationSelenium Tutorial (316 Views)

1 Reply

Selenium Tutorial by Akshaylak(op): 2:40pm On Sep 04, 2019
Introduction to Selenium
Selenium is a free (open-source) automated testing suite for web applications that supports cross-browser and cross-operating-system interoperability. It is quite similar to HP’s QuickTest Pro (QTP, now UFT), only that Selenium focuses on automating web-based applications. Testing done using the Selenium tool is usually referred to as Selenium Testing.
Selenium is useful for testing web applications only. Neither desktop (software) testing nor the testing of mobile applications is possible with Selenium.

Watch this Selenium Tutorial Video: https://intellipaat.com/blog/tutorial/selenium-tutorial/

Selenium Types
Selenium is not just a single tool but a suite of software, each catering to different testing needs of an organization. It has four components:
Selenium Integrated Development Environment (IDE)
Selenium Remote Control (RC)
Selenium Grid
Selenium WebDriver
Now that you know about its types, let’s talk about each of them briefly.

For the complete Tutorial on selenium visit: https://intellipaat.com/blog/tutorial/selenium-tutorial/

Selenium RC (Remote Control)
Let me first tell you that Selenium Core was the first version. But with that version, testers had to install both Selenium (a JavaScript program) and the web server containing the web application being tested on their local systems so that they would belong to the same domain.
Then, another ThoughtWorks’ engineer, Paul Hammant decided to create a server that will act as an HTTP proxy to trick the browser into believing that Selenium Core and the web application being tested belong to the same domain, thus making RC a two-component tool.
Selenium RC Server
Selenium RC Client (Library containing the programming language code)
RC can support the following programming languages:
Java
C#
PHP
Python
Perl
Ruby

You must have heard the term ‘browser elements’ a number of times. The next part of this Selenium tutorial will be about these elements, and you will see how testing happens on these web elements.
What are Browser Elements?
Browser elements are different components present on web pages. The most common elements you will notice while browsing are:
Text boxes
CTA buttons
Images
Hyperlinks
Radio buttons/Checkboxes
Text area/Error messages
Dropdown box/List box/Combo box
Web table/HTML table
Frame
Testing these elements essentially means, you have to check whether they are working fine and responding the way you want them to. For example, if you are testing a text box, what would you test it for?
1. Whether you are able to send text or numbers to the text box
2. If you can retrieve text that has been passed to the text box, etc.
If you are testing an image, you might want to:
Download the image
Upload the image
Click on the image link
Retrieve the image title, etc.
Similarly, operations can be performed on each of the elements mentioned earlier. But only after the elements are located on the web page, you can perform operations on them and start testing them.
Locating Browser Elements Present on a Web Page
Each element on a web page does have an attribute (property). Elements can have multiple attributes and most of these attributes will be distinctive for different elements. Consider an example, there is a page having two elements: an image and a text box. Both these elements have a ‘Name’ attribute and an ‘ID’ attribute. These attribute values need to be distinctive for each of these elements. In other words, no two elements can have the same attribute value.
In the above example, the image and the text box can have neither the same ‘ID’ nor the same ‘Name’ value. However, there are some attributes that can be common for a group of elements on the page, like a group of elements can have the same value for ‘Class Name’.
There are eight attributes which can be used to locate elements on a web page, they are ID, Name, Class Name, Tag Name, Link Text, Partial Link Text, CSS, and XPath. Since the elements are located using these attributes, they are referred to as ‘Locators’. The locators are:
By.id
driver.findElement(By.id(“Bleep”));
By.name
driver.findElement(By.name(“Bleep”));
By.className
driver.findElement(By.className(“Bleep”));
By.tagNam
driver.findElement(By.tagName(“Bleep”));
By.linkText
driver.findElement(By.linkText(“Bleep”));
By.partialLinkText
driver.findElement(By.partialLinkText(“Bleep”));
By.css
driver.findElement(By.css(“Bleep”));
By.xpath
driver.findElement(By.xpath(“Bleep”));

When you run this file as TestNG suite, the execution will start and you will get the detailed test reports. You will get the test output in your console tab and the result of the test suite in the next tab.
You decided to use TestNG for several reasons:
1. TestNG annotations are easy-to-create test cases.
2. Test cases can be grouped and prioritized more easily.
3. TestNG supports parameterization.
4. It also supports data-driven testing using data providers.
5. It generates HTML reports.
6. Parallel test execution is possible.
7. TestNG readily supports integration with other tools and plugins like Eclipse IDE and build tools like ANT, Maven, etc.
Now, this tutorial will move on with the hands-on part. This section is divided into three parts:
Java JDK Installation
Eclipse Installation
Performing Selenium Test Case
Installing Java JDK
Step 1: Download Java JDK from the link provided below and then click on the Oracle JDK Download button
https://www.oracle.com/technetwork/java/javase/downloads/index.html

Click on the radio button, Accept License Agreement, and download the .exe file related to your OS type

Step 2: Open the downloaded execution file, and click on Next

Step 3: Select Developers Tools and click on Next, and you will be directed to the below screen. It will take a few moments to set up JDK in your system

Step 4: Click on Close to complete the set up

Before moving ahead, you need to add the environment variables to the path as follows.
Step 5: Go to local C drive > Program Files > Java > jdk-12.0.1 > bin

Step 6: Copy the path as shown above
Step 7: Go to Control Panel > System and Security > System > Advanced system settings > System Properties

Step 8: Click on Environment Variables as shown above and the below window pops up in which you will perform the following steps:
1. Click on Path in the System variables section, under Environment Variables
2. Click on Edit

Step 9:
1. Click on Browse and find your file path as local C drive > Program Files > Java > jdk-12.0.1
Keep clicking ‘OK’
2. Now, you have Java JDK installed in your system

Installing Eclipse
Step 1: Go to the Eclipse download page (the recent one is Eclipse Installer 2019–06 R), with this link: https://www.eclipse.org/downloads/

Step 2: Click on Download 64 bit. You would land on a page as shown below:

Step 3: Once the download is finished, launch the installer
Step 4: Click on Eclipse IDE for Enterprise Java Developers

Step 5: Once done, click on INSTALL

Step 6: Then, click on Launch

Now that you have successfully set up Java and Eclipse in your environment, let’s perform a Selenium Test Case using Maven.
Performing Selenium Test Case
Step 1: Start a new Maven Project

Step 2: Check the Create a simple project checkbox and click on Next

Step 3: Enter Group Id and Artifact Id and click on Finish
Group Id: Group Id is the Id of the project’s group. Generally, it is unique among an organization.
Artifact Id: Artifact Id is the Id of the project. It specifies the name of the project.

Step 4: Now, your project would appear in the Project Explorer section as shown below:

Before moving on to the scripting part, you need to configure the Maven Dependencies to perform Selenium Test Case in Eclipse. You will be adding the Maven Dependencies to the pom.xml file under the target folder.
Step 5: Now, go ahead and add the below dependencies to the pom.xml file
Note: Copy the code from below and paste it after the junit dependency which will be already present in your .xml file
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.141.59</version>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
</dependency>

Step 6:
1. Right-click on the file name
2. Click on Properties

Step 7:
1. Select Java Build Path
2. Click on Libraries
3. Click on Add Library

Step 8:
1. Click on TestNG
2. Press Next and then Finish

Step 9: Click on the Apply and Close button
Step 10: Go to www.facebook.com, right-click on the page, and click on Inspect

Step 11: Follow the process shown below and copy the xpath of email:
1. You will use this arrow to select an element in the page to inspect it
2. Select the email web-element, which will point to the section of this web-element’s html code
3. Click on Chropath, this helps you in getting Xpaths and CSS selectors for web elements of a web page, uniquely
4. Copy the RelXpath. XPath is defined as XML path. It is a syntax or language for locating any element on the net page using XML path expression

Step 12:
1. Paste the xpath in the xpath expression (i.e., key)
2. Enter the value (email ID)

Step 13: Do the same for password xpath

Step 14: Do the same for login xpath as well

Step 15: Your code would look like this:
@Test
public class App

{
WebDriver driver;

public void test()
{
System.setProperty("webdriver.chrome.driver","C:\\Users\\intellipaat\\Desktop\\chromedriver.exe"wink;


driver = new ChromeDriver();
//The website name you want to visit
driver.get("http://www.facebook.com");
driver.findElement(By.xpath("//input[@id='email']"wink).sendKeys("helloworld@gmail.com"wink;
driver.findElement(By.xpath("//input[@id='pass']"wink).sendKeys("helloworld123"wink;
driver.findElement(By.xpath("//input[@id='u_0_2']"wink).click();
}
}
Note: Here, you must provide a valid email ID and password. In this example, dummy ID and password would be used.

Step 16:
1. Right-click on the screen and scroll down to Run As
2. Click on 1 TestNG Test

Step 17:
1. Once done, Chrome browser window will pop up
2. It will search for facebook.com
3. Then, it will automatically type the email
4. It will automatically type the password as well
5. It will then click on Log in and navigate you to your FB homepage

Step 18: You’ll be navigated to your FB account

Step 19: Go to Eclipse IDE again and see the console. You would see the Test report with the results

That’s it! You have successfully performed a Selenium Test Case.
Creating Automated Tests
There are three steps to execute automated tests:
Find an element on the web browser
Perform an action on that element
Test and create a test report with the results

Finding an Element on the Web Browser
An element on a web browser can be found using:
ID
Name
Class Name
Tag Name
Performing an Action on That Element
The next step is performing an action. For that you can try the following options:
Click(): Used to click on a web element
sendKey(): Used to take values into text boxes
Clear(): Used to clear text boxes of its current value
Submit(): WebDriver will automatically trigger the submit function of the web application where that element belongs to

Originally published at www.intellipaat.com on August 13, 2019.
1 Reply

Selenium Course:what Makes Selenium Such A Widely Used Testing Tool?|intellipaatFeatures Of Selenium.Best Selenium Training Institute In Chennai234

Governor Seyi Makinde Assures LAUTECH Governing Council Of Oyo State FulfillmentI Need Help From The EDUCATIONIST In The Forum.EKSU Student Allegedly Kills Lover Over N2500