Department of Collegiate and Technical Education
Experiment 04: Install Selenium server and demonstrate it using
a script in Java/PHP.
Course outcome : CO-1
Software Testing Lab – 15CS64P
( VI Semester)
Computer Science and Engineering
15CS64P 1
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Contents
Selenium Web Driver
Installation of Selenium Web Driver
Test Scenario
Locating Web Elements
Developing Test Script: Code Explaination
MCQ
Computer Science & Engineering – 15CS64P 2
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Selenium Web Driver
• Selenium Web Driver is the most commonly used component of
Selenium Tool's Suite.
• Selenium Web driver is an open-source automated testing tool
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.
Computer Science & Engineering – 15CS64P 3
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
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 simple, flexible and faster compared to
Selenium RC server.
Computer Science & Engineering – 15CS64P 4
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Installation of Selenium Web Driver
• Download and install the Java
• Download and configure Eclipse
• Download Selenium Web Driver Java Client
• Download Chrome Driver and JUnit Jar file
Computer Science & Engineering – 15CS64P 5
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
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 – 15CS64P 6
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Download Eclipse IDE
• Download Eclipse IDE from URL:https://www.eclipse.org/downloads/.
• Click on “Download Packages” link.
• Click on “x86_64” under “Eclipse IDE for Java Developers”.
• Downloaded file will be in zipped format. Extract contents to any
specific folder.
• Open Eclipse folder and click “Eclipse(.exe file)” to open Eclipse IDE.
Computer Science & Engineering – 15CS64P 7
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Download Selenium WebDriver Java Client
• Download it from URL: https://www.selenium.dev/downloads/.
• Locate Selenium Client & WebDriver Language Bindings and click
“Download” link Java Client Driver.
• Downloaded file will be in zipped format. Unzip contents to any
specific folder.
• Unzipped folder contains all the jar files required to configure
Selenium Web Driver in Eclipse IDE.
Computer Science & Engineering – 15CS64P 8
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Download Chrome Driver
• Chrome Driver is needed to automate the testing on Google
Chrome Browser.
• Download it from following URL and download it as per version of
your Chrome Browser:
https://sites.google.com/a/chromium.org/chromedriver/downloads
• Downloaded file will be in zipped format. Unzip contents to any
specific folder. It contains ChromeDriver.exe file.
Computer Science & Engineering – 15CS64P 9
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Download Junit JAR File
• Junit is a unit testing framework and Junit JAR file is needed for unit
testing. It provides libarries needed for assertations.
• Download the latest version of Junit jar file URL:
http://www.java2s.com/Code/Jar/j/Downloadjunit4jar.htm
• Downloaded file will be in zipped format. Unzip contents to any
specific folder. It contains junit4.jar file.
Computer Science & Engineering – 15CS64P 10
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Test Scenario
• Launch Chrome Browser
• Maximize the Browser
• Open URL: https://www.google.com
• Validate whether search textbox accepts value or not and validate
“Google Search” button functionality.
• Validate title of search result webpage.
• Finally, Compare expected result with actual result and test results
should be generated.
Computer Science & Engineering – 15CS64P 11
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Locate Web Elements
Here, we need unique id or name of the required web elements(Search
Textbox and “Google Search” button) to develop test script for
automation and open URL: : https://www.google.com.
• Right click on the “Search” textbox and select “inspect” element.
From the source code of webpage, note down the id or name of
“Search” textbox. Here, Unique name of “Search” textbox is “q”.
• Repeat the same for “Google Search” button.
– Unique name of “Google Search button is “btnK”.
Computer Science & Engineering – 15CS64P 12
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Code Explaination
1. Open Eclipse IDE, create new project by clicking on “File -> New ->
Java Project” and name it.
2. Right click on src folder, create new class: “New->Class” and name
it.
3. Right click on src folder and click “Build Path”->”Configure Build
Path”.
4. Under Libraries tab, select classpath and click “Add External JARs”.
Then, add the following required JAR files :
• "client-combined-3.141.59.jar”
• “client-combined-3.141.59- sources.jar”
• All JAR files from “libs” folder
• “Junit4.jar”
Computer Science & Engineering – 15CS64P 13
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Code Explaination
5. Import the required packages and set the system property the
path of your ChromeDriver.exe file.
6. Create a instance of Web driver class, launch browser and navigate
it to the URL: https://www.google.com. Maximize the browser.
7. Next, you need to locate the Search textbox and send values.
8. Locate “Google Search" button and perform submit action.
Computer Science & Engineering – 15CS64P 14
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
Code Explaination
9. Finally, Compare Expected result with the actual result. Here,
Expected result is title of Search result webpage i.e. “Google
Search – Search Text”.
10. Close the browser.
11. Click on the “Run” and click “Run As” to run the test script. Test
results will be generated.
Computer Science & Engineering – 15CS64P 15
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
MCQ
Q. 1. To locate web element for id or name in browser,
______ option is used.
1. Inspect
2. Spell Check
3. Writing Direction
4. None of the above
Answer: 1
Description:
“Inspect” option in browser is used to locate web element for id or
name.
Computer Science & Engineering – 15CS64P 16
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
MCQ
Q. 2. Assert statements are used in java to verify results in
testing.
1. True
2. False
Answer: 1
Description:
Yes. In Java, Assert statements are used to verify or compare results in
testing.
Computer Science & Engineering – 15CS64P 17
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
MCQ
Q. 3. To close the browser, ______ method of web driver class
is used in selenium web driver.
1. close()
2. Quit()
3. abort()
4. None of the above
Answer: 1
Description:
In Selenium Web Driver, close() method of web driver class is used to
close the browser.
Computer Science & Engineering – 15CS64P 18
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
MCQ
Q. 4. To compare Expected result with actual result, ______
method of Assert Class is used.
1. assertTrue()
2. assertEquals()
3. assertFalse()
4. None of the above
Answer: 2
Description:
The assertEquals() method of Assert class is used to compare expected
result with actual result.
Computer Science & Engineering – 15CS64P 19
Experiment 4: Install Selenium Server and demonstrate it using a script in Java/PHP.
MCQ
Q. 5. To get title of current webpage, ______ method of web
driver class is used in selenium web driver.
1. getCurrentUrl()
2. getTitle()
3. findElement()
4. None of the above
Answer: 2
Description:
In Selenium Web Driver, getTitle() method of web driver class is used to
get title of current webpage.
Computer Science & Engineering – 15CS64P 20
References
[1] Testing in 30+ Open Source Tools, Rahul Shende, Shroff Publishers &
Distributor Pvt.Ltd, ISBN 13: 9789350231005
[2] https://www.selenium.dev/
[3] https://www.javatpoint.com/selenium-webdriver
[4]
https://www.tutorialspoint.com/selenium/selenium_webdriver.htm
Computer Science & Engineering – 15CS64P 21