100% found this document useful (1 vote)
19 views52 pages

Week 06 Test Automation - Lab

Uploaded by

jehuabiabi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
19 views52 pages

Week 06 Test Automation - Lab

Uploaded by

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

Software Quality Assurance

HNDIT-4022

SELENIUM – TEST
AUTOMATION TOOL
CONTENT

• Selenium is.
• Features of selenium.
• Advantages of selenium.
• Components of selenium.
• References.
1.Selenium is

• Open source License.


• Browser based web application testing tool
• Support for multiple browsers.
• Extensible framework.
• Selenium Software is not just a single tool but a suite of software.
• Support mobile testing (Android,OS)
• Write test cases using language of choice java,c#.
• Support Native Browser Testing.
2.Features of selenium.
• Selenium is functional automation tool for web application.
• Selenium is an open source tool.
• Selenium supports the language like
HTML,Java,PHP,Perl,Python,Ruby, and C#.
• It supports the browser like IE,Mozilla Firefox,Safari,Google
Chrome and Opera.
• It supports the operating systems like Windows,Linux,Mac.
• It is very flexible.
3.Advantages of selenium.

• Free of cost for company because of open source software.


• Customize according to the requirements.
• Ajax based system.
• Support native testing for all major browsers.
• It can be integrated with tools such as TestNG & JUnit for
managing test cases and generating reports.
• Support for any operating system.
4.Components of selenium

• Selenium IDE.
• Selenium RC.
• Selenium Web Driver.
• Selenium Grid.
4.Components of selenium (Cotd.)

1.Selenium IDE.
• IDE stand for Integrated Development Environment.
• It was a Firefox plugin for faster creation of test cases.
• Which is use for Record and Play back the script.
• Selenium IDE is a accountable for user action.
1.Selenium IDE(contd.) - Features
1.Selenium IDE(contd.) – Pros & Cons
Pros
• Very easy to use and
install. Cons
• No programming • Available only in Firefox.
experience is required, • Designed only to create
through knowledge of prototypes of tests.
HTML and DOM are • No support for iteration
needed. and confidential
• Can export tests to operations.
formats unable in • Test execution is slow
Selenium RC and compared to that of
WebDriver. selenium RC and
• Has built-in help and test WebDriver.
results reporting module.
• Provide supports for
extensions.
Selenium IDE(contd.) – Demo

1.Record and playback


selenium
IDE Test Case
Steps to Record Selenium IDE Test Script
1. Launch Firefox and Launch Selenium IDE by Clicking
on Tools => Selenium IDE.
2. Type the Base URL value:
http://demo.guru99.com/v4
3. Click on the Record button to start the recording of
the Test Case. Record Button

URL
Steps to Record Selenium IDE Test Script (contd.)

4.In Firefox, navigate to http://demo.guru99.com/v4 Firefox


should take you to the page similar to the one shown below.
5.Right-click on any blank space within the page, this will
bring up the Selenium IDE context menu. Select
the Show IDE option. Then, select assert then, select
Title This is a command that makes sure that the page
title is correct.
6.Enter Username User1 in the first text box and
Password Password1 in the second text box. Then click
on Login button to submit.
7. Stop the recording by clicking on the Record button. In
the Table tab of Test Step Pane you can see the commands
recorded by selenium IDE.
2.Steps to Save Selenium
IDE Test Script
1. Save the test case for future use by clicking on Save
project icon or right click and click save as
Save project
icon
2. Choose your location, and then name the test as Invalid
Login. Click the Save button.

Save
3. The file was saved as
HTML.
3.Steps to PlayBack
Selenium IDE Test
Script
Run all tests
1.Selenium IDE(contd.) - Selenium IDE Commands
(Selenese)
2.Accessor 3.Assertio
1.Actions
Generally manipulate s ns
the state of the These commands These commands
application. examine the state are like accessors,
of the application but they verify that
Eg:-type this
and store the result the state of the
box, click this
link or select option in variables. application
conforms to what
If an Action fails Eg:-storeTitle is expected.
current test is stopped.
Selenium
Many Actions can be They are also used Assertions can also
called with to automatically be categorized into
the AndWait suffix,
generate three categories.
e.g. clickAndWait, ty
peAndWait. Assertions. Eg;-Assert,
Verify, WaitFor
1.Selenium IDE(contd.) - Commonly used Selenium IDE
commands

Additional Reading :- https://ui.vision/rpa/docs/selenium-ide

Command Description
1.type Sets the value of an input field, as though you typed it in
2.open Opens a page using a URL.
3.click Clicks on a link, button, checkbox or radio button.
4.assertTitle, Verifies an expected page title
VerifyTitle
5. Verify / Asserts the presence of an element on a web page.
assertElementPres
ent,
verifyElementPrese
nt
6. Verify / Asserts the presence of a text within the web page.
assertTextPresent,
verifyTextPresent
7.type, typeKeys, Enters a value (String) in the specified web element.
Command Description
8. Click, clickAt, Clicks on a specified web element within a web page.
clickAndWait
9. Sleeps the execution and waits until the page is loaded
waitForPageToLoad completely.
10. waitForElement Sleeps the execution and waits until the specified element is
Present present
11.chooseOkOnNex Click on ”OK” or “Cancel” button when next confirmation box
t appears.
Confirmation,
chooseCancelOn
NextConfirmation
12. highlight Briefly changes the background Color of the specified
element yellow. Useful for debugging.
13. echo Prints the specified message into the third table cell in your
Selenese tables. Useful for debugging.
14.pause Wait for the specified amount of time (in milliseconds).
1.Selenium IDE(contd.) - Locators

• These are the command which are like GUI elements.


• Identification of correct GUI elements is a prerequisite to
creating an automation script.
• But accurate identification of GUI elements is more difficult
than it sounds.
• Since Selenium provides locators to precisely locate a GUI
element.
1.Selenium IDE(contd.) - Locators
Locator Define Description
1. Locating by ID id=id of the Way of locating elements since ID's
element

2. Locating by name name=name of the Locating elements by name.


element

3.Locating by Link link=link_text This type of locator applies only to


Text hyperlink texts.

4.Locating by CSS css=tag#id CSS Selectors are string patterns used


Selector to identify an element based on a
combination of HTML tag, id, class, and
attributes.
4.Components of selenium (Cotd.)

2.Selenium RC
• Flagship Testing Framework of the whole Selenium project for a
long time.
• Allow users to use a programming language they prefer.
• RC version 2.25.0 support for C#,PHP,and Java.
• Make request using GET/POST method and capable of setting
HTTP requests.
• Automate web application.
2.Selenium RC(contd.) – Pros & Cons

Pros Cons
• Installation is not easy
• Cross browser and
when comparing with IDE.
platform.
• User need technical
• Can perform looping and
knowledge regarding
conditional operations.
• Support for data-driven programming language.
• Need Selenium RC server
testing.
• Has matured and complete to execute.
• API commands are more
API.
• Support for new browsers. confusing.
• Less realistic browser
• Faster execution when
interaction.
comparing with IDE.
2.Selenium RC(contd.) – Main components

RC Client
Server Library

Selenium Applicatio
Core n Under
Test
2.Selenium RC(contd.) – Overview of Selenium RC
2.Selenium RC(contd.) – Installation

• https://www.protechtraining.com/content/selenium_tutorial-se
lenium_remote_control
4.Components of selenium (Cotd.)

3.Selenium WebDriver
• Better than both Selenium IDE and Selenium RC.
• Does not rely on JavaScript for Automation.
• It controls the browser by directly communicating with it.
• Support language ;- Java, C#, PHP, Python, Perl, Ruby.
• It mainly supports browsers like Firefox, Chrome, Safari and Internet
Explorer.
• You can now use conditional operations like if-then-else or
switch-case. You can also perform looping like do-while.
3.Selenium WebDriver(contd.) – Pros & Cons

Cons
• But installation is
Pros complicated when
• Easy to install comparing comparing with selenium
with RC. IDE.
• Directly connect with • Need programming
browser. language.
• Support for data-driven • Not support readily for
testing. new browsers.
• Browser interaction is • API commands are more
more realistic. confusing.
• Execution time is fast than • There was no any built-in
RC and IDE. mechanism to generate
result.
3.Selenium WebDriver(contd.) – Architecture
3.Selenium WebDriver(contd.) – Architecture with RC
3.Selenium WebDriver(contd.) – Installation

• Install Java SDK


• Install Eclipse
• Install Selenium Driver Files
3.Selenium WebDriver(contd.) – Install Selenium Driver
Files

1. Download the Selenium Java Client Driver.

2. Configure Eclipse IDE with WebDriver


https://www.guru99.com/installing-selenium-webd
river.html
First Selenium
Web driver Script
3. First Selenium Web driver Script
1.Instantiating objects and variables
The default Firefox profile will be launched by our Java program

2.Launching a Browser Session


get() method is used to launch a new browser session and directs it to the URL

3. Get the Actual Page Title


getTitle() method that is always used to obtain the page title of the currently
loaded page.
4. Compare the Expected and Actual Values
simply uses a basic Java if-else structure to compare the actual title with the
expected one..

5. Terminating a Browser Session


simply uses to close the browser window...
4. Running the Test
On Eclipse's menu bar, click Run > Run.
Press Ctrl+F11 to run the entire code.

5. Final Result – Console View


Locating GUI
Elements
We used the getTagName() method to extract the tag name
of that particular element whose id is "email". When run, this
code should be able to correctly identify the tag name "input"
and will print it out on Eclipse's Console window.
Closing and
Quitting
Browser Windows
quit(), all windows will be closed - not just the parent one. Try
running the code below and you will notice that the two pop-
ups above will automatically be closed as well.
that only the parent browser window was closed and not the
two pop-up windows.
Switching Between
Pop-up Windows
WebDriver allows pop-up windows like alerts to be
displayed, unlike in Selenium IDE. To access the elements
within the alert (such as the message it contains), we must
use the "switchTo().alert()" method.
On the Eclipse console, notice that the printed alert
message is:
4.Components of selenium (Cotd.)

• 4.Selenium Grid.
• Used together with Selenium RC to run parallel tests (running multiple
tests at once)
• Across different machines and different browsers all at the same time.
• Since Saves time enormously.
• Utilizes the hub-and-nodes concept(The hub acts as a central
source of Selenium commands to each node connected to it)
• To run a huge test suite, that needs to complete in the soonest time
possible.
4.Selenium Grid (cotd.) - hub-and-
nodes concept

Hub Node
1.Central point where you load 1.Selenium instances that will
your tests into execute the tests that you loaded
on the hub
2. Only be one hub 2.Can be one or more nodes
3. Launched only on a single 3. Can be launched on multiple
machine machines with different platforms
and browsers.
4. The machine containing the 4.The machines running the
hub is where the tests will be run nodes need not be the same
platform as that of the hub.
5.References

• https://www.guru99.com/introduction-selenuim-ide.html
• https://www.guru99.com/first-webdriver-script.html
• https://www.guru99.com/introduction-to-selenium-grid.html#:
~:text=Selenium%20Grid%20is%20a%20part,server%20acts
%20as%20a%20hub.
• https://www.edureka.co/blog/what-is-selenium/
• https://www.toolsqa.com/selenium-ide/locators-in-selenium-id
e/

You might also like