0% found this document useful (0 votes)
30 views11 pages

Exp 3 SY

The document outlines a software testing lab experiment using Selenium WebDriver to automate the testing of a registration page. It details the installation process for required tools, the test scenario, and provides a complete test script for validating form fields. The script includes steps for launching the browser, entering data, and verifying the results against expected outcomes.

Uploaded by

smithashree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views11 pages

Exp 3 SY

The document outlines a software testing lab experiment using Selenium WebDriver to automate the testing of a registration page. It details the installation process for required tools, the test scenario, and provides a complete test script for validating form fields. The script includes steps for launching the browser, entering data, and verifying the results against expected outcomes.

Uploaded by

smithashree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

SOFTWATE TESTING LAB - 15CS64P 2020-21

Experiment 3: Using Selenium, Write a simple test script to validate


each field of the registration page.
Selenium Web Driver
Selenium Web Driver is the most important component of Selenium Tool's Suite. Selenium Web
driver is an open-source collection of APIs which is used for testing web applications. The
Selenium Web driver tool is used for automating web application testing to verify that it works as
expected or not.

Features of Selenium Web Driver:


• In Selenium Web Driver, test scripts can be developed using any of the supported
programming languages such as C#, Java, Perl, PHP, Python and Ruby.
• Selenium Web Driver supports browsers like Firefox, Chrome, Safari and Internet Explorer.
• Selenium Web Driver is faster compared to Selenium RC server.

Installation of Selenium WebDriver


Selenium WebDriver can be installed in four basic steps:
1. Download and install the Java
2. Download and configure Eclipse
3. Download Selenium WebDriver Java Client
4. Download Chrome Driver and JUnit Jar file

Download and Install the Java


Download and install the latest version of Java. You can download the latest version of Java
Development Kit (JDK 8 or above) from the below link:
http://www.oracle.com/technetwork/java/javase/downloads/index.html

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

Download and Configure Eclipse


• Open URL: https://www.eclipse.org/downloads/ and click on the "Download Packages"
link.

• It will redirect you to the "Download Packages" page. Click "Windows x86_64" under
"Eclipse IDE for Java Developers".
Developers" You can also select other
her options to download as per
the operating system you are using.

• Downloaded file will be in Zipped format. Unpack the contents to any drive or folder.

• Open "Eclipse" folder and click "Eclipse" (.exe file) to launch or open Eclipse IDE.

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

Download Selenium WebDriver Java Client

• Open URL: https://www.selenium.dev/downloads/ and locate Selenium Client &


WebDriver Language Bindings.
Bindings Click "Download" link of Java Client Driver as shown in
below figure:

• Downloaded file will be in zipped format. Unpack the contents to some folder. It contains all
the jar files required to configure Selenium web driver in Eclipse IDE. Following selected
jar files and all jar files in "libs"
"libs" folder are required jar file and they will be added to the java
project in Eclipse IDE.

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

Download Chrome Driver and JUnit Jar file


• Chrome Driver is required to automate the testing
t onn Google Chrome Browser and Junit jar
file is required for unit testing.
testin It provides libraries needed for assertations.
• Download
ownload the Chrome driver from the following URL. Download it as per the version of
your chrome browser. Unzip the downloaded file (it contains ChromeDriver.exe file) and
extract the file to your folder.
https://sites.google.com/a/chromium.org/chromedriver/downloads

• Download latest version JUnit jar file from the URL:


http://www.java2s.com/Code/Jar/j/Downloadjunit4jar.htm Unzip the downloaded file (it
http://www.java2s.com/Code/Jar/j/Downloadjunit4jar.htm.
contains junit4.jar file) and extract the file to your folder.

Test Scenario
Here, We will automate the testing for the following scenario in Google Chrome Browser by
developing Test Script using Selenium Web Driver:
Driver

• Launch Chrome Browser


• Maximize the browser
• Open URL: https://accounts.lambdatest.com/register
• Validating whether form elements are accepting values and "FREE SIGN UP" button
functionality.
• Finally, Concluding test result by comparing expected result with the actual result.

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

Locating required Web Elements

We need unique id or name for required web elements (Name, Email,, Password and phone number
textboxes and check box)) to automate them through your test script. It can be done as follows:

• Open URL: https://accounts.lambdatest.com/register. Right click on the


Name text box and select inspect element.
element. It will show source code of web page. Note down
the id or name of Name textbox from the source code. Here, Unique name of Name textbox
is "name".

• Repeat the same for Email textbox. Here,


Here name of Email textbox is "email
email".

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

• Repeat the same


me for password textbox. Here,
Here name of password textbox is "password".

• Repeat the same for phone number textbox. Here,


Here name of phone number textbox is "phone".

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

• Repeat the same for check box. Here,


Here name of check box is "i_agree".

Code Explaination

1. Open Eclipse application,, click "File -> New -> Java Project" and create Java project as
"ST Lab".
2. Right click on the "src" folder and create a new class file from the "New
New -> Class".
3. Give Class name as "Exp3"
"Exp3 and click the "Finish" buton.
4. Right click on the "src" folder and click "Build Path" ->
> "Configure Build Path".

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

5. Under Libraries tab, select "Classpath" and click "Add External JARs".
JARs" Then add all the
downloaded required JAR files ("client-combined-3.141.59.jar", " client-combined-3.141.59-
client
sources.jar", all jar files from "libs" folder and "junit4.jar" file) and finally click "Apply
and Close".

6. Import the required packages and set the system property "webdriver.chrome.driver" to
the path of your ChromeDriver.exe file.

System.setProperty("webdriver.chrome.driver",
("webdriver.chrome.driver", "D:\\STLab\\chromedriver.exe");
chromedriver.exe");

7. Create a instance of Web driver class, launch the browser and navigate it to the required
URL: accounts.lambdatest.com/register.
https://www.accounts.lambdatest.com/register Maximize the browser if
required.

WebDriver driver=new ChromeDriver();


driver.navigate().to("https://www. accounts.lambdatest.com/register");
accounts.lambdatest.com/register
driver.manage().window().maximize();

8. Next, you need to locate the Name, Email, Password and phone
hone textbox elements and
Checkbox based on its unique name and send values as below:

driver.findElement(By.
.findElement(By.name("name")).sendKeys("Shiva");
driver.findElement(By.
.findElement(By.name("email")).sendKeys("[email protected]
[email protected]");
driver.findElement(By.
.findElement(By.name("password")).sendKeys("Test@123");
@123");
driver.findElement(By.
.findElement(By.name("phone")).sendKeys("1122447788
"1122447788");
driver.findElement(By.
.findElement(By.name("i_agree")).click();

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

9. "FREE SIGN UP" button located on the text of button and submit action is carried out using
following statement:

driver.findElement(By.
driver.findElement(By.xpath("//button[text()='Free Sign Up']")).submit();
']")).submit();

10. To validate results, assertions are needed. Asserts compares expected result with actual
result. Here, Expected URL on successful
succes login is https://accounts.lambdatest.com/email/verify.
It is compared with current actual URL as below:

String Expurl = "https://accounts.lambdatest.com/email/verify


https://accounts.lambdatest.com/email/verify";
";
Assert.assertEquals(Expurl, driver.getCurrentUrl());
11. close the browser.
driver.close();

12. click on the "Run" and click "Run As" to run


un the application. Test results will be
generated.

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

Test Script

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Exp3 {
@Test
public void testRegForm()
{
//Set system property
System.setProperty("webdriver.chrome.driver", "D:\\STLab\\chromedriver.exe");

//Creates instance of webDriver class


WebDriver driver=new ChromeDriver();

//Launch the browser and navigate to "https://www.linkedin.com/login"


driver.navigate().to("https://accounts.lambdatest.com/register");

//Maximize the Browser


driver.manage().window().maximize();

//Locate the textboxes and send value


driver.findElement(By.name("name")).sendKeys("Shiva");
driver.findElement(By.name("email")).sendKeys("[email protected]");
driver.findElement(By.name("password")).sendKeys("Test@123");
driver.findElement(By.name("phone")).sendKeys("1122447788");

//Locate the check box and click


driver.findElement(By.name("i_agree")).click();

//Locate "Free Sign Up" button and submit


driver.findElement(By.xpath("//button[text()='Free Sign Up']")).submit();

//Expected URL on successful login is: https://accounts.lambdatest.com/email/verify


String Expurl = "https://accounts.lambdatest.com/email/verify";

//Compares expected result with actual result.


Assert.assertEquals(Expurl, driver.getCurrentUrl());
System.out.println("Test Passed\nRegistration Successful: ");

//Close the browser


driver.close();
}
}

Computer Science & Engineering


SOFTWATE TESTING LAB - 15CS64P 2020-21

Test Result:

REFERENCES

[1] https://www.selenium.dev/
[2] https://www.javatpoint.com/selenium-webdriver
https://www.javatpoint.com/selenium
[3] https://www.tutorialspoint.com/selenium/selenium_webdriver.htm
[4] https://www.accounts.lambdatest.com/register
accounts.lambdatest.com/register

Computer Science & Engineering

You might also like