Selenium course
Selenium scripting standards
Selenium scripting standards
Selenium presentation
Selenium presentation
Selenium presentation2
Selenium presentation2
SELENIUM IDE
Selenium
IDE is an integrated development environment for Selenium tests. It is
implemented as a Firefox extension and it allows you to record, edit, and debug
tests. Selenium IDE is not only recording tool: it is a complete IDE. Selenium IDE includes the entire Selenium
Core, allowing you to easily and quickly record and play back tests in the
actual environment that they will run. You can choose to use its recording
capability, or you may edit your scripts by hand. With auto complete support
and the ability to move commands around quickly, Selenium IDE is the ideal environment
for creating Selenium tests no matter what style of tests you prefer.
Selenium IDE is also
the easiest way to use Selenium and most of the time it also serves as a
starting point for your automation. Since selenium IDE comes as an extension to
the Firefox web browser. This can be installed from either openqa or mozilla
distribution site. Selenium extension will be downloaded as XPI file. If it is
opened using fileàopen
in Mozilla, it should get installed.
Features:
Record and playback
Autocomplete for all common Selenium commands
Walk through tests
Debug and set breakpoints
Save tests as HTML, Ruby scripts, or other
formats
Advantages:
Selenium IDE is the easiest way to use Selenium
Simple
Easy to install
Easy to work with
only flavor of Selenium which allows you to
record user action on browser window
can also record user actions in most of the
popular languages like Java, C#, Perl, Ruby
It will not record any operation that you do on
your computer apart from the events on Firefox browser window.
During recording if you right click on any
element it will show all the selenium commands available.
You can also edit existing command, by selecting
it and editing on the boxes available.
You can also insert/delete commands by choosing
appropriate option after right clicking.
Choose appropriate run option - i.e walk, run or
test runner and review your results
Disadvantages:
limitation in terms of browser support
Installation:
It is easy to install selenium IDE.
Selenium IDE can be downloaded from the below site.
[http://selenium.openqa.org/]
4.5 Working:
Once the installation is successfully completed,
go to ‘Tools’ in the firefox window. You can find Selenium IDE.°
Click on Selenium IDE
The small red button on the right hand side
gives you an indication on whether Selenium is in recording mode or not. Click
the red button to start recording and click the red button again to stop the
recording.
Run will execute the tests with the
maximum possible speed
Walk will execute them with relatively
slow speed
In Step
mode you will need to tell Selenium to take small steps.
Green tilted triangular button is to execute the
test
Yellow button to pause while executing the test
Blue button helps to place checkpoints
And the final green button is the Selenium TestRunner
Test Runner gives you nice browser interface to
execute your tests and also gives summary of how many tests were executed, how
many passed and failed. It also gives similar information on commands which
were passed or failed. TestRunner is available to tests developed in
HTML only.
In selenium, there is option to start a new
test, save test and open the saved test
It is also possible to export scripts.
We have other self explanatory options like
encoding of test files, timeout under the Options tab.
When we access the Format tab under Options tab,
we have an option as to specify what kind of formatting we would like in the
generated code as Selenium IDE can generate code in variety of languages.
Consider the following example.
Suppose we select
HTML as our language choice for automation under OptionsàFormat, Then an
additional tab called Table appears on the Selenium IDE called the Table. Table
has 3 columns under it, namely, Command, Target and Value.
For any element
present in the browser, selenium maps its action in all the columns
E.g.: you want to
type user name in the user name text box
Selenium will
translate it as:
+Command=type,
Target=username text box and value=your username+
Table of Contents
1.0 Change Log 3
2.0 About Selenium 4
2.1 What is Selenium? 4
2.1.1 What is Selenium IDE? 4
2.1.2 What is Selenium RC? 5
3.0 Installing Selenium 5
3.1 Selenium IDE 5
3.2 Selenium RC 6
4.0 Working with Selenium 7
4.1 Understanding Selenium Script 7
4.2 CVS Checkout 7
4.3 Recording Test Cases 7
4.4 Playing back Test Cases 11
4.5 Data Externalization 13
4.6 GUI Externalization 16
4.7 Library 17
4.8 Test Suites 18
4.9 User Extension 19
5.0 Executing Test scripts 20
5.1 Selenium RC 20
5.2 Test Runner 21
About Selenium
What is Selenium?
Selenium is an acceptance and functional testing tool for web applications. Selenium tests run directly in a browser, just as real users do. And they run in Internet Explorer, Mozilla and Firefox on Windows, Linux, and Macintosh.
Link: http://www.openqa.org
What is Selenium IDE?
Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and allows us to record, edit, and debug tests. Selenium IDE includes the entire Selenium Core, allowing us to easily and quickly record and play back tests in the actual environment that they will run.
Features:
Easy record and playback
Autocomplete for all common Selenium commands
Walk through tests
Debug and set breakpoints
Save tests as HTML, Ruby scripts, or any other format
Support for Selenium user-extensions.js file
Link: http://www.openqa.org/selenium-ide/
What is Selenium RC?
Selenium Remote Control is a test tool that allows us to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser. Selenium RC provides a Selenium Server, which can automatically start/stop/control any supported browser .It works by using Selenium Core, a pure HTML+JS library that performs automated tasks in JavaScript.
The Selenium Server acts as a client-configured HTTP proxy, to stand in between the browser and the website you want to test. This allows a Selenium-enabled browser to run JavaScript on arbitrary websites.
Visit http://www.openqa.org/selenium-rc to study more about Selenium RC.
Visit http://release.openqa.org/selenium-core/nightly/reference.html to explore Selenium RC Commands
Installing Selenium
Selenium IDE
Pre-requisites:
Firefox version 1.5 or more.
Steps to install:
Open Firefox browser.
Go to http://www.openqa.org/selenium-ide/download.action and download version 0.8.0
Allow for popups and click Install now button.
Selenium IDE gets installed as a Firefox extension.
Re-start Firefox (close all existing Firefox browser windows and open) and choose Tools menu.
Play with Selenium IDE!!!
Selenium RC
Pre-requisites:
Java Runtime Environment (JRE)
Jre and browser executable should be set in PATH.
Steps to install:
Go to http://www.openqa.org/selenium-rc/download.action and download version 0.8.1
Unzip the archived file.
Voila RC!!!
Open the corresponding folder in a terminal and set the browser executable and JRE in the PATH variable.
Working with Selenium
Understanding Selenium Script
The test scripts can be recorded by using Selenium IDE or written manually.
The Selenium test script is a plain html table which will consist of the Command (Selenium Command), Target and the Value, and the script will be in simple readable and understandable format.
Selenium IDE also provides the option of converting this html/selenese script generated to other formats like java, ruby, Perl, python, C#.
(Refer to Appendix – I for a Walkthrough of a sample Selenium Script)
CVS Checkout
Check out the Regression_Testing folder from the Final folder of the repository given below
Server Name : cvsserver.etrade.com
Repository Name : QA_Automation
Complete Folder path : /etrade/cvsserver/cvs/QA_Automation/Selenium
Recording Test Cases
Step1. After installing Selenium IDE, we can open Selenium IDE from the Tools menu of firefox as shown below.
Step2. Once opened, it is automatically in record mode. Otherwise we can change it to record mode by clicking the red button present in the right side of the Selenium IDE.
Step3. After doing this, minimize the Selenium IDE and proceed with the steps as per the test case. All events will be recorded by Selenium IDE as a test script.
Step4. We can also edit the test scripts using IDE by modifying the command, target, value triplet.
Command: The Selenium command. We can rightclick to get a list of all commands.
Target: Target is an item on which an action is performed.
Value: Value is the data associated with the action we perform.
Eg. If we are typing text in a textbox, type is the command, the locator name of the text box is the target and the text to be entered is the value.
Step5. After recording we can save the script by giving .html extension.
Playing back Test Cases
Step1. Once the recording process is over, we can play back the test script by clicking the green button over the Selenium IDE as shown below.
Step2. As each command in the test is executed, the cell that contains the command turns either red or green. If an assertion fails, then the cell turns red. Otherwise, if the step succeeds, the cell turns green.
We can execute the test case in IDE in Run, Walk and Step modes. When we run a test, the test is executed from start to finish without pause. When we walk a test, the test is executed from start to finish with a pause between each step. Finally, when we step through a test,we must click the Step button to advance to each new step in the test.
Data Externalization
Data-Externalization is done for insulating the code from data changes .Test Scripts are driven by data from a spreadsheet we maintain for this purpose .For externalizing the data, we should have one ‘.xls’ file and one ‘.html’ file. The .html file would be generated from .xls file using the Excel-to-HTML-converter java program. Data required for the testcase are picked from this html file based on the logical name given.
Consider one scenario in which we are entering the stock symbol as ‘GOOG’. This data may change at some time in the future, or we may like to run the test case for another stock. So in this case we will externalize this data such that the locator name in externalization sheet would be ‘GOOG’ and the logical name would be something like ‘PlaceOptionOrder_txt_OptionSymbol_value’ in accordance with the naming standards.In the test script we would replace the locator name with the logical name. So if the symbol changes that wouldn’t affect the script. We have to just go in to the .xls sheet and change the locator name.
Step1: Create one .xls file and specify the actual value in the Locator Name column and the Logical value (our choice) in the corresponding Logical Name column, as shown below. Create one .html file from this .xls sheet using the java program. We have to pass the location of the .xls file as the argument. ( java
Step2: Open the .html file from Selenium IDE using the ‘open’ command and map (using the storeText command) the corresponding actual values to Logical values as shown below.
We can externalize the login account numbers also; thus we can change the account numbers without affecting the script. These externalization files can be found at Regression_Testing/Data_Externalization/Common/
Similarly URLs are externalized too. The file which contains the URLs used is Regression_Testing/Data_Externalization/Misc/URLS.html
Step3: And in Selenium IDE, instead of the actual name specify the corresponding Logical Name as ${Logical Name}. So if in case the actual value changes that won’t affect the script because here we have specified only the Logical Names.
GUI Externalization
GUI-Externalization is for insulating the code from GUI changes. The process is similar to Data-Externalization. Instead of data, here we will externalize the value of text boxes, buttons, table locations, images and links so that when Webdev changes are made, we need not change the script.
Eg. , The above screen shot, the webdev name for the quantity text box is “quantity”. If in the future it is changed to say “stockquantity” our test script would fail.
To avoid this, we can give a logical name for this text box say PlaceStockOrder_txt_quantity and store the actual name in the .xls file against this logical name. In the testscript we can use ${ PlaceStockOrder_txt_quantity } instead of the webdev name.
Library
A set of commands may be common to more than one test case. We can use Libraries to achieve code re-use.
Libraries are also saved with a .html extension and they can be included in a test using the syntax
Include
In the below screen shot, we have included one login library BOPS_login.html . This library does the login functionality that is common for many testcases.
Note: If we have included a library in a test script, we can’t run that test script using Selenium IDE. To run test cases which use libraries, we should use test runner (See sec 5.2 for details).
Test Suites
A test suite is simply a list of Selenium tests. We can create a test suite by creating an HTML page with a list of links to individual tests. For example, the following page is a test suite that contains four tests.
head
title Test Suite title
head
body
table
tbody
Test Suite tr td
a href="./TestOpen.html"TestOpen
a href="./TestClick.html"TestClicktr td
a href="./TestType.html"TestType trtd
a href="./TestSelect.html"TestSelecttbody
table
body
User Extension
We can add additional functionality other than those provided by Selenium commands by writing and using User extensions.
User Extensions are written purely in Java Script.
Eg. To include libraries, the user extension user-extensions.js is used.
Step1. Save the user extension with .js extension in the Regression_testing/User_Extensions folder.
Step2. Open IDE. Select from the menu Options -> Options. Select the General tab.
Specific the location of the user extension in the Selenium Core extensions text box. If there is more than one extension, they can be delimited by a comma.
Step3. Apply Changes and restart IDE.
Executing Test scripts
Selenium RC
We run a test suite in RC by executing the below command
cmd=runHTMLSuite&1=*chrome&2=""&3=test suite filename&4=true&5=resultfilename
Executing the above command will start the Test Runner Browser and prompt the tester to select the test scripts to run. The tester can ask for the selective test scripts to run or can also select all the test scripts to run by selecting Run All option.
In all the cases the scripts will be run in the same order in which it is being referenced in the Test Suite and will generate a test report in the html format specifying the number of passes & failures along with their simple comments on failure.
Test will proceed uninterrupted by default in Selenium RC, i.e. even if one test case in the Test Suite fails due to assertion or any other reason, rest of the test cases will continue to get executed uninterruptedly.
Test Runner
From IDE if we press the test runner button (next to the Record button) Test runner would be opened. The Selenium TestRunner page enables us to execute any suite of Selenium tests.
The test runner page is divided into 3 frames. The left frame lists the test cases in the suite which we have opened. The Middle frame shows the current test case being run. Similar to IDE, the execution of the steps can be seen. The frame on the right is the control panel.
We can set the pace of execution using the slider in the control panel. If we click on the All button, all the test cases in the suite would be executed. We can also selectively run test cases by selecting them and clicking on the Selected button.
The result of running the test case (Pass or Fail) is also displayed in the control panel.
The actual application in which the test script is being executed is shown in a window below the test runner window.
URL for running suites through Test Runner:
chrome://selenium-ide/content/selenium/TestRunner.html?test=
Open command is used to open a file located at a particular location, in value option of IDE you have to specify the correct path where the file is located.
storeText
Locator Name0
BOPSAccountManagement_lnk_AccountSearch
Storetext command is used to store location of actual name. In value column we have to store the variable name given by us.
Use variable name in place of actual name in your script as ${variable name} for each element that you have recorded.
Include command is used to include libraries in your automation script. As shown above it is using a library named as BOPS_login-agupta5-genie13.html, this library will contain url and also login ID and password files .Libraries are means of achieving code reuse.(Commonly used set of commands can be made a library).
Here we are using a textbox where we have to provide the value Account No. In target we have used the variable name as ${BOPSHome_txt_AccNO} and value is provided as ${AccountNum}.
clickAndWait
${BOPSHome_btn_AccNoSubmit}
ClickAndWait is the command to click on a button and wait for the subsequent event to happen.
We have externalized the button name as ${BOPSHome_btn_AccNoSubmit}.
assertText
//form/table/tbody/tr[1]/td/table/tbody/tr/td/table/tbody/tr/td[2]
The start date is before the end date. Please re-enter.
AssertText is used when we have to verify some information while playing back. Suppose we have to verify the presence of a link, we can use asserttext or assertextpresent to do that.
If whatever we have asserted is present then it will pass otherwise the script will fail.
Few more commonly used commands:
1) waitforpopup: This command is used when we are opening a popup window, it will include some wait time so that popup window will open before any other command is executed. Format of the command will be as shown below. Target is the name of popupwindow and value is wait time in milli seconds.
Command Target Value
waitForPopUp wf 30000
2) assertLocation:This command is used to varify a url.Format is as below. Here we are asserting a url to verify that the page going to the correct url.
Command Target Value
assertLocation https://uu.com/e/t/onlineenroll/unifiedenrollment
3) waitForElementPresent:We use this command when we want to wait till the target is properly loaded in the webpage.
Command Target Value
waitForElementPresent ${Home_tab_OpenAccnt}
4) store:This command is used to store some value that we want to use later in our script, at that point we will give a variable name use to store that value. This variable can be used later on in the test case for any calculation etc.
Command Target Value
store IRA - Contributory OnlineAcctAppl_AccountType_Value
5) close:This command is used to close the popup window. In target column give name of the popup window you want to close.
Command Target Value
close wf
No comments:
Post a Comment