0% found this document useful (0 votes)
45 views7 pages

STQA Practicals

The document provides an introduction to Selenium, detailing its history, components, and practical applications for web testing. It covers the installation and usage of Selenium IDE, Selenium RC, and TestNG, along with practical exercises for testing web applications and managing student records in Excel. Additionally, it discusses the integration of Selenium with Java and the use of external libraries for enhanced functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views7 pages

STQA Practicals

The document provides an introduction to Selenium, detailing its history, components, and practical applications for web testing. It covers the installation and usage of Selenium IDE, Selenium RC, and TestNG, along with practical exercises for testing web applications and managing student records in Excel. Additionally, it discusses the integration of Selenium with Java and the use of external libraries for enhanced functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

STQA Practical

INTRODUCTION TO SELENIUM

1. History of Selenium
• In 2004 invented by Jason R. Huggins and team.
• Original name is JavaScript Functional Tester [JSFT]
• Open source browser based integration test framework built originally by
Thought works.
• 100% JavaScript and HTML
• Web testing tool
• That supports testing Web 2.0 applications
• Supports for Cross-Browser Testing (ON Multiple Browsers)
• And multiple Operating Systems
• Cross browser – IE 6/7, Firefox .8+, Opera, and Safari 2.0+

2. What is Selenium?
• Acceptance testing tool for web-apps
• Tests run directly in browser
• Selenium can be deployed on Windows, Linux, and Macintosh.
• Implemented entirely using browser technologies -
– JavaScript
– DHTML
– Frames

3. Selenium Components
– Selenium IDE
Created by Shinya Kasatani of Japan
– Selenium RC
Created by Paul Hammant
– Selenium Grid
Developed by Patrick Lightbody

3.1 Selenium IDE


• The Selenium-IDE (Integrated Development Environment) is the tool you use to
develop your Selenium test cases.
• It is Firefox plug-in
• Firefox extension which allows record/play testing paradigm
• Automates commands, but asserts must be entered by hand
• Creates the simplest possible Locator
• Based on Selenese

Practical 1
1. Selenium IDE Demo Installation
Version to be used
(Selenium IDE Version 3.1.1 works with Firefox 56.0 and later)

You need
· Mozilla Firefox
· Active Internet Connection
· If you do not have Mozilla Firefox yet, you can download it
from http://www.mozilla.org/en-US/firefox/new.

STEPS:
1. Launch Mozilla Firefox Browser.
2. Type URL https://www.seleniumhq.org/download/
OR
https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/
3. Selenium IDE Add-ons page will get open then Click on Add to
Firefox button
4. Firefox will show one popup saying do you want to allow Mozilla
Firefox to install Selenium IDE Add-ons or not. Click on Install button.
5. Firefox will automatically install Selenium IDE software. After the
installation is completed, a pop up window appears asking to re-start the
Firefox. Click on the “Restart Now” button to reflect the Selenium IDE
installation. Click on Restart Now button.
6. On clicking on the Restart Now button, Firefox will restart automatically.
In case you missed the pop-up, simply close the Firefox and launch
again.
7. Once the Firefox is booted and started again, we can see selenium IDE
under the tools menu list. Selenium IDE icon will be displayed in the
Firefox toolbar.
8. Click on Selenium IDE icon to open Selenium IDE.

Step 1
· Launch Firefox and Selenium IDE.
· Type the value for our Base URL: http://demo.guru99.com/test/newtours/.
· Toggle the Record button on (if it is not yet toggled on by default).
Step 2
· In Firefox, navigate to http://demo.guru99.com/test/newtours/. Firefox
should take you to the page similar to the one shown below.
Step 3
· Right-click on any blank space within the page, like on the Mercury Tours
logo on the upper left corner. This will bring up the Selenium IDE context
menu. Note: Do not click on any hyperlinked objects or images
· Select the "Show Available Commands" option.
· Then, select "assertTitle exact: Welcome: Mercury Tours." This is a
command that makes sure that the page title is correct.
Step 4
· In the "User Name" text box of Mercury Tours, type an invalid username,
"invalidUNN".
· In the "Password" text box, type an invalid password, "invalidPWD".
Step 5
· Click on the "Sign-In" button. Firefox should take you to this page.
Step 6
· Toggle the record button off to stop recording.
Step 7
· Now that we are done with our test script, we shall save it in a test case.
Step 8
· Choose your desired location, and then name the Test Case as
"Invalid_login".
· Click the "Save" button.
Step 9
· Notice that the file was saved as side extension.
Step 10
· Go back to Selenium IDE and click the Playback button to execute the
whole script. Selenium IDE should be able to replicate everything properly.

Practical 2
2. Conduct a test suite for any two web sites.

Practical 3
3. Install Selenium server and demonstrate it using a script
in Java/PHP.

Introduction
1. Selenium-RC is the solution for tests that need more than
simple browser actions and linear execution.
2. Selenium-RC uses the full power of programming languages to
create more complex tests like reading and writing files, querying
a database, emailing test results.
3. You’ll want to use Selenium-RC whenever your test requires logic
not supported by Selenium-IDE.
4. What logic could this be? For example, Selenium-IDE does not
directly support:
• Condition statements
• Iteration
• Logging and reporting of test results
• Error handling, particularly unexpected errors
• Database testing
• Test case grouping
• Re-execution of failed tests
• Test case dependency
• Screenshot capture of test failures
5. Although these tasks are not supported by Selenium directly, all
of them can be achieved by using programming techniques with
a language-specific Selenium-RC client library.

Installation of Selenium RC and Eclipse


Download Eclipse
1. Go to URL – http://www.eclipse.org/downloads/
2. Select Eclipse IDE for Java Developers (Click on Windows 32 bit
platform)
3. Click on OK button and save to a local drive (i.e. C: or D:, etc)
4. Unzip the downloaded zip file and rename that to Eclipse
5. Create one more folder “Eclipse-Workspace” (i.e. C:Eclipse-
Workspace)in the same drive where Eclipse is unzipped and renamed.
6. Create Eclipse desktop shortcut (go to C:Eclipse folder –> right click
Eclipse.exe and then click on “desktop create shortcut”).
1. Now we need to create a workspace folder –> C:Eclipse-
WorkspaceSeleniumTests
2. Double click on “Eclipse shortcut on Desktop”
3. This opens the Eclipse
4. Close Eclipse welcome screen
5. Click File menu –> Launch Worspace –> other
6. Now Select the C:Eclipse-WorkspaceSeleniumTests folder.

We have finished setting up the eclipse.

Now, we need to download Selenium RC server / client driver and


configure that to Eclipse
1. Download Selenium server: http://seleniumhq.org/download/
2. Download Selenium Client driver for Java (from Selenium Client
Drivers section)
3. Create “Selenium” folder in C: drive and copy the Selenium-
server.jar as well as unzip the Selenium Client driver (C:Selenium)

Downloading and unzipping the files into a folder is done.


We need to configure the appropriate Selenium Client driver Jar file to
the Eclipse.
J
1. Go to Eclipse –> Click File –> New –> Project (from various options
need to select just “project”)
2. In Select Wizard –> Click Java –> “Java Project”
3. Give the project name (e.g. DemoTests)
4. Click Finish – Click Yes
5. Now we are done with creation of project and need to configure the
Selenium Client driver to this Project
6. Right Click “DemoTests” project
7. Click “Java Build Path”
8. Click Libraries tab
9. Click “Add External JARs” button
10. Select “Selenium Client Drivers” unzipped in C:Selenium folder
(Selenium
Server JAR file should not be added)
11. Click OK
12. Referenced libraries –> contains both the Selenium Client driver jar
files.
13. Create a new class file as “SeleniumDemo” in the “DemoTest” by
right click on src folder.
Practical 4

Practical 5
Write and test a program to update 10 student records
into table into Excel file (using TestNG)
TestNG is a testing framework inspired from JUnit and NUnit but
introducing some new functionality that make it more powerful and
easier to use, such as: Annotations.
Run your tests in arbitrarily big thread pools with various policies
available (all methods in their own thread, one thread per test class,
etc...).
Test that your code is multithread safe.
Flexible test configuration.
Support for data-driven testing (with @DataProvider).
Support for parameters.
Powerful execution model (no more TestSuite).
Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven,
etc...).
Embeds BeanShell for further flexibility.
Default JDK functions for runtime and logging (no dependencies).
Dependent methods for application server testing.

TestNG is designed to cover all categories of tests: unit,


functional, end-to-end, integration, etc...

Installing TestNG in eclipse


1. Select Help / Software updates / Find and Install.
2. Search for new features to install.
3. New remote site.
4. For Eclipse 3.4 and above, enter http://beust.com/eclipse.
5. For Eclipse 3.3 and below, enter http://beust.com/eclipse1.
6. Make sure the check box next to URL is checked and click Next.
7. Eclipse will then guide you through the process.

Launching your tests in Eclipse


We finished writing our tests, now how can we run them?
You can launch TestNG from the command line, using an Eclipse
plugin or even programatically. We are going to use the Eclipse plugin.
Follow the steps described on the official TestNG documentation over
here.
If you installed TestNG correctly, you will see this menu when you
right click on the XML file:

Click on “Run as TestNG Suite” and your test will start running.

Selenium Tests with Microsoft Excel


Parameterizing a test from external sources such as Microsoft Excel is
always recommended in order to handle large amount of test data. To
read data from
Excel, we need APIs which support opening file, reading data, and
writing data into Excel. We should know various classes and methods
which support above mentioned operations. In this post, let us try to
figure out which is the API that supports all the activities we need to do
during execution of a test.
Jxl.jar is an open source Java API which supports read Excel
spreadsheets and to write into Excel spreadsheets. Below are some of
the operations that we can handle with this API.
1. Read data from Excel spreadsheet
2. Read and write formulas into spreadsheets
3. Generate spreadsheets
4. Supports formatting of font, number, and date
5. Supports coloring of cells
To access the methods and classes provided by this API inside Eclipse
we need to add this JAR file to the Java Build Path.
(I have explained steps to add external Jar files to Java Build
Path in previous examples)

Download the jxl.jar from “http://jexcelapi.sourceforge.net/”


Add the JAR file to Java Build Path

You might also like