Post on 13-Apr-2018
7/27/2019 Selenium-Basics by Quontra Solutions
1/49
Prepared By
Quontra SolutionsIT Courses Online Training USAFor DemoCall Us : 1 404-900-9988Email: info@quontrasolutions.com
7/27/2019 Selenium-Basics by Quontra Solutions
2/49
Introduction Where to get Selenium?
Selenium Vs QTP,Silktest
Limitations
Features of Selenium
Components Selenium CORE
Configuring SeleniumCORE
Selenium IDE
Selenium IDE-SampleScript
Recording and Executinga Script
Selenium RC(RemoteControl)
Starting Selenium Server
Default Selenium Class
Locators
Sample Script Selenium Command
Reference
Selenium RC Configurationwith Eclipse
Object Identification Selenium Grid
7/27/2019 Selenium-Basics by Quontra Solutions
3/49
Selenium is set of different software tools each with a
different approach to supporting test automation.
Selenium is an open source tool.
Selenium supports as many as 8 programming languages
such as HTML , Ruby , PHP, Python, C#, Java, Perl etc.
Latest side of Selenium is Grid, which allows the running of
multiple Selenium tests on different browsers and different
platforms.
7/27/2019 Selenium-Basics by Quontra Solutions
4/49
We can everything from the Selenium site
www.seleniumhq.org
Software's:
All the selenium software's can be downloaded by using thebelow link
http://seleniumhq.org/download/
Documentation:
Documentation can be downloaded by using the below link
http://seleniumhq.org/docs/
http://www.seleniumhq.org/http://seleniumhq.org/download/http://seleniumhq.org/docs/http://seleniumhq.org/docs/http://seleniumhq.org/download/http://www.seleniumhq.org/7/27/2019 Selenium-Basics by Quontra Solutions
5/49
Object Identification: Faster: Selenium can identify objects using xpath, So it can
directly go to a specific object Slow: Silk test and QTP follows a hierarchy for locating
objects.
Scripting Language: QTP allow users to write script in VB script only. Silk test has proprietary scripting language 4TL. ( 4 Test
Language ) But Selenium allows writing script in Java, Ruby, Perl, PHP,
C# and Python.
Price : Selenium is an open source tool. Silk and QTP are not free tools
QTP license cost is around $7500 , Silk test license cost is around$8500 USD
7/27/2019 Selenium-Basics by Quontra Solutions
6/49
Desktop applications:
We cant automate desktop applications using Selenium.
We can automate using QTP and Silk test.
Object Repository:
Capturing objects properties is a tough task as we need toprepare the object repository.
7/27/2019 Selenium-Basics by Quontra Solutions
7/49
It has support for multiple operating systems like Windows, Linux and
Mac
Cross browser testing can be done easily on browsers like IE, Firefox,
Safari, Netscape etc.
It supports multiple programming Languages like C#, Java, Ruby,
Python .. etc
It can be used for automating Ajax and swift web pages.
It is easy to use, if are familiar with any one of supported programming
language
It is easy to learn
It is free-open source tool
It has matured community forums to get clarifications
7/27/2019 Selenium-Basics by Quontra Solutions
8/49
Selenium is majorly divided into four components
Selenium CORE
Selenium IDE
Selenium RC(Remote Control)
Selenium Grid
7/27/2019 Selenium-Basics by Quontra Solutions
9/49
Selenium Core is a test tool for web applications.
Selenium Core tests run directly in a browser.
And they run in Internet Explorer, Mozilla Firefox on Windows, Linux, and Macintosh.
This is deprecated with the advent of Selenium IDE and Selenium RC.
Initially IDE has capability for recording test cases only.
In earlier stages executed recorded script using Test runner.
Later IDE introduced with the execution facility.
Disadvantages:
We cannot record scripts using this.
We can run scripts in only HTML format using Test runner.html
7/27/2019 Selenium-Basics by Quontra Solutions
10/49
Download the Selenium Core zip file (selenium-core-
1.0.1.zip) and extract the files into a folder.
Open Command Prompt and then navigate to thepath where the files are extracted
7/27/2019 Selenium-Basics by Quontra Solutions
11/49
7/27/2019 Selenium-Basics by Quontra Solutions
12/49
A new Selenium Functional Test Runner window will be opened.
We need to enter the test suite path in Test Suite edit box on the left hand side .
Click on Go and then the screen window changes with the commands.
7/27/2019 Selenium-Basics by Quontra Solutions
13/49
Now click on Run option on the right hand side of the window
so that the test case executes successfully.
7/27/2019 Selenium-Basics by Quontra Solutions
14/49
IDE means integrated development environment, which is used for record and run the scripts.
Selenium IDE is add-on for Mozilla Firefox.
The recorded scripts in Selenium IDE can be viewed in the following supported languages:
1) HTML 2) Java 3) C# 4) PERL 5) Python 6) Ruby 7) PHP
The recorded scripts in Selenium IDE can be run against other browsers like IE, Safari,
Google, Chrome and Opera by using Selenium RC.
By default the script that is recorded should be saved with the .html extension.
It will keep the user actions as they are performed and store them as a reusable script to play
back.
It supports only for Firefox.
Using Selenium IDE we can record, save, execute and debug the scripts
It cant support for Database verifications Error handling and Customize reporting.
7/27/2019 Selenium-Basics by Quontra Solutions
15/49
The script is saved as .html file so the run options are
active
Observations:
Table is active here because the extension is .html
Run Options are active and we can run the test casenow.
7/27/2019 Selenium-Basics by Quontra Solutions
16/49
These are the statements
generated during record from
IDE
7/27/2019 Selenium-Basics by Quontra Solutions
17/49
Observations:
Table is not available because the format of the
script is changed to Java.
Run options are graded out because the default
format for Selenium IDE is HTML.
7/27/2019 Selenium-Basics by Quontra Solutions
18/49
7/27/2019 Selenium-Basics by Quontra Solutions
19/49
Open Firefox and application you want to test Launch Selenium IDE using tools-Selenium IDE By default, you should be in the recording mode, but confirm it by observing the Red button. By default it will be in the HTML format. Otherwise, go to Options-Format-Select HTML Format. Record some actions and make sure that these are coming on Selenium IDE. 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. The recorded script can be viewed in two options: 1) Table 2) Source In Table, we can see the script in tabular format. In Source, we can see the script in html code.
If we want to see the recorded script in other selenium supported languages, Go to Options,thenselect Format select the desired language.
Drawback
Biggest drawback of Selenium IDE is its limitation in terms of the browser support (only MozillaFirefox).
7/27/2019 Selenium-Basics by Quontra Solutions
20/49
Selenium RC comes in two parts i.e. Server and Client libraries
Selenium-RC software comes with seven folders and we need
to use these files to configure RC with the language chosen.
1) selenium-server-1.0.3 -Configuration files for launching the RC server
2) selenium-java-client-driver-1.0.1- Java supported RC files
3) selenium-perl-client-driver-1.0.1-Perl supported RC files
4) selenium-php-client-driver-1.0.1-PHP supported RC files
5) selenium-python-client-driver-1.0.1-Python supported RC files
6) selenium-ruby-client-driver-1.0.1-Ruby supported RC files
7) selenium-dotnet-client-driver-1.0.1-C# supported RC files
Selenium RC uses a server called Jetty Server for launching browsers
7/27/2019 Selenium-Basics by Quontra Solutions
21/49
Selenium RC is an Open Source platform and supports only web-
applications for automation.
We can develop scripts using any popular programming languages
Using Selenium RC with a high-level programming language allows
us to query database, email test results and use iteration statements
to navigate through the result set
Using RC we can execute scripts in different browsers and platforms
7/27/2019 Selenium-Basics by Quontra Solutions
22/49
Before starting any tests you must start the server.
Go to the directory where Selenium-RCs server is located
and run the following from a command-line console.
Command to start server is java -jar selenium-server.jar
Command to stop selenium server http://localhost:4444/selenium-server/driver/?cmd=shutDown
7/27/2019 Selenium-Basics by Quontra Solutions
23/49
We can do this in our test code using the SeleniumServer class We need to follow below steps
Create an object for SeleniumServer class
Use Start method for starting server.
User Stop method for stopping server.
Sample code for Starting and Stopping selenium server.SeleniumServer server = new SeleniumServer();server.start();..
server.stop(); With the server running, we may now use a client also.
Selenium selenium = new DefaultSelenium( String seleniumServerHost,int seleniumServerPort,String browserType,String baseURL);
selenium.open("http://www.somesite.com/somePage.html");selenium.stop();
7/27/2019 Selenium-Basics by Quontra Solutions
24/49
7/27/2019 Selenium-Basics by Quontra Solutions
25/49
Default Seleniumis class for creating browser reference
Variables used in the Default Selenium constructor are:
seleniumServerHostis the where the Selenium Server is running. i.e. hostname
seleniumServerPortis the port on which the Selenium Server is listening. The default port is 4444.
browserTypeis the type of browser you want to use for testing.
Common browser types are *firefox, *iexplore, *opera and etc.
baseURLis the base URL for the site you are testing.
Now, just opening a page isnt all that useful. We need to interact with the page. To
do this, we use our selenium clients methods withlocators. For example:
selnium.click("link=Text For Some Link");
The string link=Text For Some Link is a locator.
7/27/2019 Selenium-Basics by Quontra Solutions
26/49
In Selenium, the objects are called as locators and they can be identified using Xpath, DOM or CSS.
Locators take the form of
locatorType=argument
A locator type can be an element id, an element name, an xpath expression, link text, and
more.
A few examples:
selenium.click(id=idOfThing); //an id locator
selenium.click(name=nameOfThing); //a name locator
selenium.click(xpath=//img[@alt='The image alt text']); //an xpath locators
slenium.click(dom=document.images[56] ); //a DOM locator
selenium.click(link=Test Page For Selenium); //a link locator
selenium.click(css=span#firstChild); //a css locator
Locators will be covered in detail in the next session on Objects Construction.
7/27/2019 Selenium-Basics by Quontra Solutions
27/49
import com.thoughtworks.selenium.*; // This is a package need to be include for using Selenium API
public class SampleScript // This is Class name
{
public static void main( String args[] ) throws Exception // This is main function
{
// This is the statement for Creating Browser Object
DefaultSelenium Brw= new DefaultSelenium ("localhost",4444,"*chrome", "http://");
Brw.start(); // This statement starts the Browser
Brw.open("www.google.com"); // This statement loads google.com urlBrw.waitForPageToLoad("30000"); // This stmt waits till loading complete web page
Brw.windowMaximize(); // This stmt maximizes browser window
Brw.type("//input[@name='q']", "valuelabs"); // This stmt enters Valuelabs text in search field
Brw.click("//input[@name='btnG']"); // This stmt clicks on google search button
}
}
//input[@name='q] Object Identifier for Search Field
//input[@name='btnG']Object locator for Search Btn
7/27/2019 Selenium-Basics by Quontra Solutions
28/49
Below are usefull commands in selenium open - opens a page using a URL captureScreenshot - Captures a PNG screenshot to the specified file Check- Check a toggle-button (checkbox/radio) Click - Clicks on a link, button, checkbox or radio button CloseClicks on the "close" button in the titlebar of a popup window or tab
doubleClick - Double clicks on a link, button, checkbox or radio button getEval - Gets the result of evaluating the specified JavaScript code getHtmlSource- Returns the entire HTML source getLocation- Gets the absolute URL of the current page getText - Gets the text of an element getTitle - Gets the title of the current page getValue- Gets the value of an input field goBack - clicks on the "back" button on their browser isChecked- Gets whether a toggle-button (checkbox/radio) is checked isElementPresent- Verifies that the specified element is somewhere on the page isTextPresent- Determines if the specified element is visible RefreshClicks on the "Refresh" button on their browser
7/27/2019 Selenium-Basics by Quontra Solutions
29/49
Select- Select an option from a drop-down
selectFrame - Selects a frame within the current window
selectWindow - Selects a popup window
Start - Launches the browser with a new Seleniumsession
Stop- Ends the test session, killing the browser
Type- Sets the value of an input field
Uncheck- Uncheck a toggle-button (checkbox/radio)
windowMaximize - Resize currently selected windowto take up the entire screen
7/27/2019 Selenium-Basics by Quontra Solutions
30/49
Prerequisites If we want to configure Selenium RC with
Eclipse, following files are required
Eclipse JDK 1.5 or Later versions.
Selenium JAR files
a) selenium-server.jar
b) selenium-java-client-driver.jar c) junit.jar
d) Poi related jar files (For handling excel)
7/27/2019 Selenium-Basics by Quontra Solutions
31/49
Open the Eclipse by double clicking oneclipse.exe, Click on OK for workspace
launcher. Click on workbench, it will allow you to move
inside the eclipse.
Click on File->New->Select Java
Project. Enter the Project name and then click on
Configure JREs
7/27/2019 Selenium-Basics by Quontra Solutions
32/49
Click on Add and givethe path upto the jdkdirectory so that all the
JRE files will be added
and click on Finish.
7/27/2019 Selenium-Basics by Quontra Solutions
33/49
Now the JRE issuccessfullyconfigured withour project rootdirectory
Right click on JRESystem Library->Build Path->Configure Build
Path
7/27/2019 Selenium-Basics by Quontra Solutions
34/49
Click on AddExternal JARs andthen select the four
jar files and add
them to ourproject.
7/27/2019 Selenium-Basics by Quontra Solutions
35/49
Now the jar files are alsosuccessfully configured with ourproject. Click on Run from the Menu--> External Tools-->SelectExternal Tools Configuration--
> Double Clickon Program and then enter thefollowing details as shown inthe screen. Click on Apply and then click
on Run.
7/27/2019 Selenium-Basics by Quontra Solutions
36/49
Now the Selenium RC issuccessfully configured withEclipse and you are ready towrite the scripts and executethem successfully.
On successful running ofSelenium server, the eclipseIDE gives an message that theserver started successfully onport number 4444(default)
7/27/2019 Selenium-Basics by Quontra Solutions
37/49
7/27/2019 Selenium-Basics by Quontra Solutions
38/49
For identifying the properties in Selenium, we use thebelow tools:
Debug bar for Internet Explorer.
Firebug for Mozilla Firefox.
Debug bar Installation Download the debug bar software by using the below
link:
http://www.debugbar.com/
Click on the exe file and then install the software. Once the software is installed, you will find the debug
bar on the left side of the window.
7/27/2019 Selenium-Basics by Quontra Solutions
39/49
Drag thecircle andplace it on the
object whichwe want toidentify theobject.
7/27/2019 Selenium-Basics by Quontra Solutions
40/49
The properties willbe identified in theAttrs field. Usingthese fields, we can
identify theobjects.
7/27/2019 Selenium-Basics by Quontra Solutions
41/49
Firebug InstallationDownload the debug bar software by using
the below link:
https://addons.mozilla.org/en-
US/firefox/addon/1843/Click on the exe file and then install the
software.
Once the software is installed, you will find the
firebug on the bottom of the window.
7/27/2019 Selenium-Basics by Quontra Solutions
42/49
Once we selectthe object,automaticallythe objects
properties willbe displayed inthe bottom:
7/27/2019 Selenium-Basics by Quontra Solutions
43/49
7/27/2019 Selenium-Basics by Quontra Solutions
44/49
Selenium Grid is used for launching the multiple browsers
with supported operating system in parallel.
We can run the scripts on different browsers in parallel.
Selenium Grid is a tool that dramatically speeds upfunctional testing of web-apps.
It allows you to easily run multiple tests in parallel, onmultiple machines, in a heterogeneous environment.
Selenium Grid consists of a component called Selenium
Hub which is the unique entry point for all the testsrunning by using Selenium Grid.
7/27/2019 Selenium-Basics by Quontra Solutions
45/49
To ease the maintenance of a Selenium-Griddeployment:
Selenium Grid Hub sends periodic heartbeatmessages to all registered Remote Controls tomake sure that they are still up and running.
Selenium Grid Remote Controls send periodicheartbeat messages to the Hub to check that itstill considers them as registered.
7/27/2019 Selenium-Basics by Quontra Solutions
46/49
7/27/2019 Selenium-Basics by Quontra Solutions
47/49
7/27/2019 Selenium-Basics by Quontra Solutions
48/49
Lets have a Demo!! With
Quontra Solutions
Call Us : +1(404)-900-9988Email:info@quontrasolutions.com
7/27/2019 Selenium-Basics by Quontra Solutions
49/49