Automated Testing Tool For Web Based Application: SQT Team
Automated Testing Tool For Web Based Application: SQT Team
SQT Team
Introduction to Selenium Basic usages of Selenium Installation steps of Selenium Selenium Testing Strategy Technical concepts of Selenium Hand on training in Selenium
Testing Workflow (within a Project Development) (link to CCC Procedures) Testing Workflow in Selenium Tips and Tricks
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)
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.
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
Selenium can be used for functional and regression testing. Selenium is not a tool for test management.
Selenium
Prerequisites:
also jdk1.6
Install Firefox go to this URL: http://www.mozilla.com/en-US/firefox/ Install Java JDK Download jdk , i.e: jdk1.5 or
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).
http://www.oracle.com/technetwork/java/javase/downloads/index.html
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 (Selenium
folder) , 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.
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
11
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
The creation of a Selenium Project has to be done using the Configuration Management Tool (ClearCase). In particular:
13
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
Create
Selenium Project Design Test Case Manage Test Suite
14
15
For Creating a Test Case in a Selenium Testing Environment, its necessary to:
Open the Selenium IDE 1.5.0
For each Requirement, its necessary to define a Test Case (FileNew Test Case) with this rule:
Test Case Name=<Req. Name><free text>
o Ex.: Button_check
16
For producing Test Script in a Selenium Testing Environment, its necessary 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
For running a Test Case, its necessary to select: Actions Play Current Test Case or click the button in the figure. The Log item and the bar provide the status of Test Case.
18
19
1) 2)
Installation of Selenium. 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
ClickAndWait (locator)
Clickandwait --- link = Login
21
VerifyTextPresent (text) (Check Point Confirmation) Click (text) Click at text (link) that present on the screen StoreConfirmation (text) To store the confirmation like (Data saved successfully)
StoreConfirmation --- var_name assertElementPresent --- link = SaveAs
assertElementPresent (locator)
22
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. 2. 3. verify assert waitFor
23
How to choose between Assertion and Verification 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 the test case.
For adding a Verification Point in a Selenium Testing Environment, its necessary to:
Select the row in the script where inserting it Select Insert new Command Define the Command, Target and Value for your VP.
24
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 File Save Test Suite As Type under CC into <your Test Suite Folder>
Test Suite Name=<Name of your Functionality>.html
Ex.: DataView.html
25
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
-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
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
(Creating Test Suite and Executing with checking the log and test result)
29
1)
Create a Test case for Logging for TLS, and perform the following commands,
Verify Make 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 Test Report.
30
User extensions are JavaScript files to customize features to add additional functionalities. A lot of useful extensions created by users, the most popular of 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, go to 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 order for the extensions file to be read.
31
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 -userExtensions C:\testsuite\user-extensions.js htmlSuite *firefox https://www.google.com C:\testsuite\testsuite_google.html C:\testresult\testresultgoogle.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
Make a JavaScript file which contains the parameter with its value Example: suppose to go to Unisys URL, insert login and password, search for a ticket that it is passed as parameter In a JavaScript file called data.js, it has to be inserted the following line: searchKey = "IM50021088269 For identifying this data.js file and access the variables inside it Import it as Selenium IDE Extension, going Selenium IDE Options General and in the Selenium IDE extension field browse the data.js file.
33
If the application is not working only in IE , then we have 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
35
To install firebug just Double click the file firebug 1.9.0.xpi file 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 Lite Open IE click Favorites add FavoriteFirebug. 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
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 tool to wait till the page is loaded.
37
WaitForTextPresent
This command will enable the selenium to wait till certain text is present 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
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
40
Create a script for TLS login with username and password parameterized (Single value) using userextension feature in Selenium. Install firebug(Firefox) and firelite(IE). Run the Test Case in IE using Selenium RC.
41
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
TestNG is a testing framework inspired from JUnit and NUnit but 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
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
Eclipse with TestNG plugin. Requires JDK 5 or higher. Jar file needed
Selenium server Selenium client Testng Junit jxl
46
Download eclipse package from shared area. Copy the TestNG plugin package to [ eclipse folder plugins ]. Click on eclipse icon, in eclipse package.
47
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
49
Open Selenium IDE add the test suite that need to be converted. Select one test case and click Option Format TestNG (Remote control). All test cases will be converted to TestNG script.
50
Just copy the TestNG script from selenium IDE, under the class and paste in the java project in the method under @Test annotation. 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 upon the 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
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
53
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
55
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 \n character with (*) wildchar.
56
57
Strategies
Types
General Testing Approaches
58
The minimum functional test coverage to be guaranteed for a product is at least one test case for each requirement.
1 2
59
White-Box
Testing
Coverage Criteria
Basic Path Testing Loop Testing Data Flow Testing
60
61
62
Selenium
Design Test Cases Manage Test Suite Write (add and/or update) Test Cases Create Test Suite
Note: In Selenium, you create a Test Suite, but its like to create a Test Plan.
63