Upload
jayaraj-dhanasekaran
View
217
Download
0
Embed Size (px)
Citation preview
8/2/2019 Selenium Doc
1/64
Automated Testing Tool for Web BasedApplication
SQT Team
8/2/2019 Selenium Doc
2/64
8/2/2019 Selenium Doc
3/64
Selenium is an Open Source suite of tools to automate web
browsers across many platforms.
It runs in many browsers and operating systems.
It can be controlled by many programming languages (Java,
C#, Perl, Python) and testing frameworks (Junit, TestNG).
Full support to Web 2.0 from Ajax to DHTML.
Components of Selenium:
Selenium IDE
Selenium RC (Selenium Server)
3
8/2/2019 Selenium Doc
4/64
Selenium IDE is a Firefox plugin
to record/playback tool for
authoring tests without learning a
test scripting language.
It is implemented as a Firefox
extension (Firefox Plugin) and
allows recording, editing,
debugging and exporting tests in
different languages: e.g.: html,
Java, Perl, Ruby, etc. It also allows to test both http and
https within the same application.
4
8/2/2019 Selenium Doc
5/64
5
Selenium Server consists of two components:
Selenium Server It has the ability to launch a browser and control the
browser to play back tests. Selenium Server receives Selenium commands
from your test program, interprets them, and reports back to your program
the results of running those tests.
Selenium client(s) There is a different client library for each supported
language. The client library takes a Selenese command and passes it to the
Selenium Server for processing a specific action or test against the
application under test (AUT). The client library also receives the result of
that command and passes it back to your program.
8/2/2019 Selenium Doc
6/64
Selenium can be used for functional and regression
testing.
Selenium is not a tool for test management.
6
8/2/2019 Selenium Doc
7/64
7
8/2/2019 Selenium Doc
8/64
Selenium Prerequisites:
Install Firefox go to this URL: http://www.mozilla.com/en-US/firefox/
Install Java JDK Download jdk , i.e: jdk1.5 or also jdk1.6 http://www.oracle.com/technetwork/java/javase/downloads/index.html
Selenium Installations:
Selenium IDE go to this pathRun the selenium-ide-1.5.0.xpi After that,
Selenium IDE option should be in Firefox (installed Selenium IDE v.1.5.0).
Selenium RC It can be installed or in each Project Team member PC or in a
Testing Project PC Download it from this pathCopy the jar in your PC (Seleniumfolder) , go to folder containing file 'selenium-server-standalone-2.13.0.jar' via CMD
command and execute: java -jar selenium-server-standalone-2.13.0.jar (installed Selenium
RC 2.13.0). The server will be started on port 4444 and it is ready to accept test commands.
8
http://seleniumhq.org/download/8/2/2019 Selenium Doc
9/649
8/2/2019 Selenium Doc
10/64
Selenium Testing Strategy
Selenium Commands
User Extensions (Read a file data)
Parameterization (by a single parameter)
Selenium scripts coding Capturing Element property
Installation of Firebug and Firebuglite
Handling Synchronization
Handling of different browsers
Selenium - TestNG
10
8/2/2019 Selenium Doc
11/6411
8/2/2019 Selenium Doc
12/64
Standard way to manage Selenium repository in ClearCase Definition of a Selenium Project
Definition of Testing Environment
Execution of a Test Case
Execution of a Test Suite (Modular Approach)
Result Analysis
12
8/2/2019 Selenium Doc
13/64
13
The creation of a Selenium Project has to be done using the
Configuration Management Tool (ClearCase). In particular:Create a Project folder
Project folder Name=_Testing
Ex.: LiotroX_Testing
Each version of a Project will be managed by a baseline in
ClearCase.
8/2/2019 Selenium Doc
14/64
14
Only in case of big Project, it will be created a Suite for
Functionality and its necessary to follow this added rule:Create a sub-folder for each Functionality
Functionality subfolder Name=
Ex.: Button
CreateSeleniumProject Design Test
Case
Manage Test
Suite
Create
Test Suite
Write (addand/or update)Test Cases
8/2/2019 Selenium Doc
15/64
Test Case
Test Script
Verification Point
Test Suite
15
CreateSeleniumProject
Manage Test Suite
DesignTest Cases
Record TestScript
CreateVerificationPoints
Write (addand/or update)Test Cases
Create TestSuite
8/2/2019 Selenium Doc
16/64
For Creating a Test Case in a
Selenium Testing Environment, itsnecessary to:
Open the Selenium IDE 1.5.0
For each Requirement, its necessary to
define a Test Case (File
New TestCase) with this rule:
Test Case Name=
o Ex.: Button_check
16
8/2/2019 Selenium Doc
17/64
For producing Test Script in a Selenium Testing Environment, itsnecessary to:
Record Test Case previously defined, clicking the red button in the figure and
selecting all steps required:
Ex.: Recording LiotroX Button Test Case
Enter the URL in Firefox press enter (Recording started).Perform the required action on the site.
Click on record button to stop recording.
Click on play entire test suite button to play back.
A Test Script will be produced as in the figure.
17
8/2/2019 Selenium Doc
18/64
For running a Test Case, its necessary to
select: Actions
Play Current Test Caseor click the button in the figure. The Log
item and the bar provide the status of Test
Case.
18
8/2/2019 Selenium Doc
19/64
(Installing Selenium, Creating Test Cases and Recording the script)
19
8/2/2019 Selenium Doc
20/64
1) Installation of Selenium.
2) Creating a new Test Case, recording the script for TLS
application logging and executing using Selenium
IDE.
TLS(Login and Logout)
Data
Url - http://tls.sgp.st.com
Username(epm test2, epm test3,,epm test10)
Password - (epmtest2, epmtest3,,epmtest10)
20
8/2/2019 Selenium Doc
21/64
Open (url)Opens a URL in the test frame Open --- /http://www.google.com
Type (locator,value)To type text in text box
Locator = id(unique id), link(text), css(unique path), name(text),
xpath.
type --- id = ext-1234567
type --- link = Install Firebug
type --- css
type --- name = SaveAs
Type --- xpath = //input
ClickAndWait (locator) Clickandwait --- link = Login
21
8/2/2019 Selenium Doc
22/64
WaitForTextNotPresent (text)(Ajax solution) WaitFortextNotPresent --- loading
VerifyTextPresent (text) (Check Point Confirmation) Verifytextpresent --- visitor
Click (text)Click at text (link) that present on the screen Click --- link = SaveAs
StoreConfirmation (text)To store the confirmation like
(Data saved successfully) StoreConfirmation --- var_name
assertElementPresent (locator) assertElementPresent --- link = SaveAs
22
8/2/2019 Selenium Doc
23/64
Selenium IDE allows multiple ways of checking for User Interface
(UI) elements.
It verifies the state of the application and confirms to what is
expected.
Examples include make sure the page title is X and verify that
this checkbox is checked. Check points or verification points are known as Assertions in
Selenium. The keywords with below mentioned prefix will be used
for adding check points or verification points.
1. verify2. assert
3. waitFor
23
8/2/2019 Selenium Doc
24/64
How to choose between Assertion andVerification Depends on convenience and
management of failures. Assert fail the test and abort the current test
case.
Verify fail the test and continue to run thetest case.
(Tip: Put an assert followed by one or more verify testcommands).
For adding a Verification Point in aSelenium Testing Environment, itsnecessary to:
Select the row in the script where inserting it
Select Insert new Command
Define the Command, Target and Value for yourVP.
24
8/2/2019 Selenium Doc
25/64
Every new version of a Project will be managed by a Suite and for big
Project it will be created a Suite for Functionality.
For Creating a Test Suite in a Selenium Testing Environment, its
necessary to:
Select FileSave Test Suite As
Type under CC into
Test Suite Name=.html
Ex.: DataView.html
25
8/2/2019 Selenium Doc
26/64
A Test Suite is a collection of various test
cases.
For running a Test Suite, its necessary to
select: Actions Play Entire Test Suite or
click the button in the figure. The Log item
and the bar provide the status of Test Suite.
26
8/2/2019 Selenium Doc
27/64
Command to run test suite in selenium RC
C:\selenium>
java -jar selenium.jar
-htmlSuite
*firefox (browser)
"http://tls.sgp.st.com" (Url)
"C:\testsuite\test.html" (path of test suite)
"C:\testresult\result.html" (path of test result)
27
8/2/2019 Selenium Doc
28/64
For getting the Results Analysis of a Test
Suite, its necessary to execute in RC The Selenium Functional Test Runner
starts and results of Test Suite are got as
in the figure 1.
An Evaluation Report (HTML format) is
created using the results of a Test Suite as
in the figure 2 and saved as the same
name and location provided in the
Selenium RC command (see above).
28
1
2
8/2/2019 Selenium Doc
29/64
(Creating Test Suite and Executing with checking the log and test result)
29
8/2/2019 Selenium Doc
30/64
1) Create a Test case for Logging for TLS, and performthe following commands,
VerifyMake a verification point after logging into the
application. Eg(verify the User name (Any text in the
page) ) Assert(Any text in the page)
WaitFor - (Any text in the page)
2) Create a Test Suite that contain two Test Cases and
Run the Test Suite in the Selenium RC and get the TestReport.
30
8/2/2019 Selenium Doc
31/64
User extensions are JavaScript files to customize features toadd additional functionalities.
A lot of useful extensions created by users, the most popularof all Selenium-IDE extensions is: goto_sel_ide.js that provides flow control in the form of while
loops and primitive conditionals To install this extension, goto Selenium-IDEs Options => Options=> General tab and put its
pathname in the Selenium Core extensions field.
Click the OK button and close and reopen Selenium-IDE in orderfor the extensions file to be read.
31
8/2/2019 Selenium Doc
32/64
User extensions can be also got in Selenium RC using
userExtensions parameter via the following command:
java -jar selenium-server-standalone-2.13.0.jar -userExtensionsC:\testsuite\user-extensions.js htmlSuite *firefoxhttps://www.google.com
C:\testsuite\testsuite_google.html C:\testresult\testresult-google.html
Note: Typing the following command: java -jar selenium-server-standalone-2.13.0.jar
-userExtensions, it is got a list of possible options to execute.
32
8/2/2019 Selenium Doc
33/64
Parameterization can be done in Selenium IDE:Make a JavaScript file which contains the parameter with its
value Example: suppose to go to Unisys URL, insert loginand password, search for a ticket that it is passed as parameter In a JavaScript file called data.js, it has to be inserted thefollowing line: searchKey = "IM50021088269
For identifying this data.js file and access the variables inside
it Import it as Selenium IDE Extension, going SeleniumIDE Options General and in the Selenium IDE extensionfield browse the data.js file.
Restart the Selenium IDE.
33
8/2/2019 Selenium Doc
34/64
If the application is not working only in IE , then wehave to manually type the commands using IDE or we
can make the script using html language directly.
To capture the locator of the elements used in the
commands , you can use Firebug (for Firefox) and
Firebug Lite (for IE).
34
8/2/2019 Selenium Doc
35/64
Firebugadd-on for Firefox. Firebug is a web development tool that facilitates the
debugging, editing, and monitoring of any website's CSS,
HTML, DOM, XHR, and JavaScript.
Firebug liteadd-on for Internet Explorer It is similar to firebug.
Firebug and Firebug lite are free and open source.
35
8/2/2019 Selenium Doc
36/64
To install firebug just Double click the file firebug 1.9.0.xpifile from shared area under (Softwarefirebug). It will be
prompt you to click on install, then click on install now
firebug is installed as a plugin in firefox.
For Firebug LiteOpen IE click Favorites addFavoriteFirebug.
Then right click on the Firebug Favorite in Favorites, select
properties Delete the url Copy the java script and paste
in url box (Java script = Software
Firebuglite
Firebuglite-javascript)
36
8/2/2019 Selenium Doc
37/64
Synchronization Problem :Suppose we record 3 transactions of some application in
selenium.
Transaction 2 takes around 2 minutes to load.
Selenium will wait for a particular amount of time (timeout)and will pass to the next transaction giving Transaction 2 as
failed.
How to solve ?
Selenium provides us certain commands which makes the toolto wait till the page is loaded.
37
8/2/2019 Selenium Doc
38/64
Commands used for SynchronizationClickAndWait
This Command Clicks at the element and wait for the reaction.
WaitForTextPresent
This command will enable the selenium to wait till certain text ispresent on the page. After the text appears , the commands return
true and will move to next command.
WaitForTextNotPresent
This command will ask selenium to wait till certain text gets
disappeared from the screen. (e.g loading.)
38
8/2/2019 Selenium Doc
39/64
Selenium IDE will work with only Firefox.
Different browser options can be used in the run time only.
Check the command:
C:\selenium>
java -jar selenium-server-standalone-2.17.0.jar
htmlSuite
*iexplore (browser)
https://www.google.com (url)
C:\testsuite\test1.html (path of test suite)C:\testresult\testresult.html (path of test result)
39
8/2/2019 Selenium Doc
40/64
(Read a file, Value Substitution, Element property )
40
8/2/2019 Selenium Doc
41/64
Create a script for TLS login with username andpassword parameterized (Single value) using user-
extension feature in Selenium.
Install firebug(Firefox) and firelite(IE).
Run the Test Case in IE using Selenium RC.
41
8/2/2019 Selenium Doc
42/64
8/2/2019 Selenium Doc
43/64
What is TestNG? Why we need TestNG?
Requirement for TestNG to run Selenium Scripts.
Installation of TestNG.
Creating and Configuring Project
Converting Selenese script to TestNG
Creating Test Cases in TestNG
Running the Test Suite
43
8/2/2019 Selenium Doc
44/64
TestNG is a testing framework inspired from JUnit and NUnitbut introducing some new functionalities that make it more
powerful and easier to use, such as:
Annotations.
Support for data-driven testing (with @DataProvider).
Support for parameters.
Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven,
etc...).
TestNG is designed to cover all categories of tests: unit,
functional, end-to-end, integration, etc...
44
8/2/2019 Selenium Doc
45/64
To extent functionality of Selenium: Parameterize the value (multiple values).
Regression Testing.
Read data from a file.
Customize the execution of code in Test Case.
Customize the execution of Test Case in Test Suite.
45
8/2/2019 Selenium Doc
46/64
Eclipse with TestNG plugin. Requires JDK 5 or higher.
Jar file needed
Selenium server
Selenium client Testng
Junit
jxl
Selenium IDE (Optional)(Recommended)
46
8/2/2019 Selenium Doc
47/64
Download eclipse package from shared area.
Copy the TestNG plugin package to [ eclipse folder plugins ].
Click on eclipse icon, in eclipse package.
47
8/2/2019 Selenium Doc
48/64
Open eclipse File New java project
Give the project name Finish
In project New Source Folder (create two folder lib and
resource)
In project New class
In lib add the jar from the folder Required jar (Shared area).
Just copy the standard file in the class and rename it.
48
8/2/2019 Selenium Doc
49/64
(Installation steps for TestNG)
49
8/2/2019 Selenium Doc
50/64
8/2/2019 Selenium Doc
51/64
Just copy the TestNG script from selenium IDE, under the class
and paste in the java project in the method under @Testannotation.
Create a excel with name data.xls and put in resource folder.
Give the data in excel that need to be parameterized.
Rename the argument name in test case method(), based uponthe name in excel.
Select the test case and click Run As TestNG test.
Result will be available under the folder test-output in the
project.
51
8/2/2019 Selenium Doc
52/64
Create different Test Case under same project.
Create an xml file, for suite that contain test cases name what
need to be executed (Example file is given in shared area).
Select the testngRun.xml and click Run as TestNG Suite.
Script will start the selenium server and start running the script.
After running all the Test Cases under the suite selenium server
will stop and prepare a result.
Result will be available under the folder test-output in the
project.
52
8/2/2019 Selenium Doc
53/64
(Converting, Creating and Running TestNG script )
53
8/2/2019 Selenium Doc
54/64
Convert the TLS Login Test case to testng. Create a class in the TLS project, copy converted test
case and run in TestNG
Parameterize the Username and password using
@Dataprovider. (For two user)
54
8/2/2019 Selenium Doc
55/64
8/2/2019 Selenium Doc
56/64
Handling Window PopupsWhich are
not part of web page.Uploading of a file
Confirmations having window properties
Solution: This is possible by calling an
autoIT script to do this functionality. How to check the whole content of a table
Solution: Using the VerifyTextPresent
command with the usage of Text
Patterns replacing all spaces and \ncharacter with (*) wildchar.
56
8/2/2019 Selenium Doc
57/64
57
8/2/2019 Selenium Doc
58/64
Strategies
Types
General Testing Approaches
58
8/2/2019 Selenium Doc
59/64
Testing Strategy depends on
development phases:
# Phase for TestPlanning
Type ofTesting
Owner
1 Requirement Acceptance User2 Functional
General Design
Functional
Integration
Performance
Service Delivery
Application
Manager
3 Detail Design /Coding
Unit ApplicationManager
59
The minimum functional test coverage to be guaranteed for a product
is at least one test case for each requirement.
8/2/2019 Selenium Doc
60/64
8/2/2019 Selenium Doc
61/64
61
8/2/2019 Selenium Doc
62/64
62
CreateSelenium
Project
Manage Test Suite
Design TestCases
Record Test Script
CreateVerification Points
Analyze Test Log
Create EvaluationReport
Write (addand/or update)Test Cases
Run Test Case
Execute TestSuite
Create TestSuite
CreateSelenium
Project
Manage Test Suite
Design TestCases
8/2/2019 Selenium Doc
63/64
8/2/2019 Selenium Doc
64/64