Selenium - Tutorialspoint

3y ago
86 Views
4 Downloads
6.40 MB
190 Pages
Last View : 2m ago
Last Download : 3m ago
Upload by : Angela Sonnier
Transcription

Seleniumi

SeleniumAbout the TutorialSelenium is an open-source tool that is used for test automation. It is licensedunder Apache License 2.0. Selenium is a suite of tools that helps in automatingonly web applications.This tutorial will give you an in-depth understanding of Selenium and its relatedtools and their usage.AudienceThis tutorial is designed for software testing professionals who would like tolearn the basics of Selenium through practical examples. The tutorial containsenough ingredients to get you started with Selenium from where you can takeyourself to higher levels of expertise.PrerequisitesBefore proceeding with this tutorial, you should have a basic understanding ofJava or any other object-oriented programming language. In addition, youshould be well-versed with the fundamentals of testing concepts.Copyright & Disclaimer Copyright 2014 by Tutorials Point (I) Pvt. Ltd.All the content and graphics published in this e-book are the property of Tutorials Point(I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute orrepublish any contents or a part of contents of this e-book in any manner without writtenconsent of the publisher.We strive to update the contents of our website and tutorials as timely and as preciselyas possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I)Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness ofour website or its contents including this tutorial. If you discover any errors on ourwebsite or in this tutorial, please notify us at contact@tutorialspoint.comi

SeleniumTable of ContentsAbout the Tutorial ·······iAudience isites ···············iCopyright & Disclaimer iTable of Contents ··········· 1Introduction ···············1Advantages of Selenium vantages of Selenium ·················32.SELENIUM – IDE ·············· 4Selenium – IDE ···········4Download Selenium IDE res of Selenium IDE ····················7Creating Selenium IDE Tests ················8Script Debugging ······13Inserting Verification Points ··············17Pattern Matching ·····20Selenium User Extensions ·················22Different Browser Execution ·············253.ENVIRONMENT �····· 28Download and Install Java ·················28Download and Configure Eclipse ·······34Configure FireBug and FirePath ·········36Configure Selenium RC ······················40ii

SeleniumConfigure Selenium WebDriver ·········424.SELENIUM RC ················ 44What is Selenium �44Selenium RC Architecture ··················44RC – Scripting ···········455.SELENESE ······ 54Actions ors ·················58Assertions ················616.WEBDRIVER ··················· 65Architecture ·············65Selenium RC Vs WebDriver ················66Scripting using WebDriver ·················66Most Used Commands CATORS ····················· 76Locators Usage ······· 84User Interactions ······84Text Box Interaction ·84Radio Button Interaction ···················87Check Box Interaction opdown Interaction nchronization ·······93Drag & Drop ·············95Keyboard Actions ·····97iii

SeleniumMouse Actions ·········97Multi Select Action ···98Find All Links ·········· 1019.TEST DESIGN TECHNIQUES ··················· 103Page Object Model · 103POM Flow Diagram ························· 103Data Driven using Excel ··················· 107Parameterization ··· 112Log4j �············· 118Exception Handling ························· 127Multi Browser Testing ····················· 128Capture Screenshots ······················· 135Capturing Videos ···· 14110. ·· 148What is TestNG? ····· 148Installing TestNG for Eclipse ············ 148Annotations in TestNG ···················· 152TestNG-Eclipse Setup ······················ 155First Test in TestNG ························· 16211. SELENIUM ············· 166Architecture ··········· 167Working with Grid ·· 167Configuring the Hub ························ 168Configuring the Nodes ····················· 169Develop the Script and Prepare the XML File ··········· 174Test Execution ········ 181iv

SeleniumResult Analysis ······· 183v

1.SeleniumOVERVIEWIntroductionSelenium is an open-source and a portable automated software testing tool fortesting web applications. It has capabilities to operate across different browsersand operating systems. Selenium is not just a single tool but a set of tools thathelps testers to automate web-based applications more efficiently.Let us now understand each one of the tools available in the Selenium suite andtheir usage.ToolDescriptionSelenium IDESelenium Integrated Development Environment(IDE) is a Firefox plugin that lets testers to recordtheir actions as they follow the workflow that theyneed to test.Selenium RCSelenium Remote Control (RC) was the flagshiptesting framework that allowed more than simplebrowser actions and linear execution. It makesuse of the full power of programming languagessuch as Java, C#, PHP, Python, Ruby, and PERL tocreate more complex tests.Selenium WebDriverSelenium WebDriver is the successor to SeleniumRC which sends commands directly to the browserand retrieves results.Selenium GridSelenium Grid is a tool used to run parallel testsacross different machines and different browserssimultaneously which results in minimizedexecution time.1

SeleniumAdvantages of SeleniumQTP and Selenium are the most used tools in the market for softwareautomation testing. Hence it makes sense to compare the pros of Selenium overQTP.SeleniumQTPSelenium is an open-source tool.QTP is a commercial tool and there is a costinvolved in each one of the licenses.Can be extended for varioustechnologies that expose DOM.Limited add-ons and needs add-ons foreach one of the technologies.Has capabilities to executescripts across differentbrowsers.Can run tests in specific versions of Firefox,IE, and Chrome.Can execute scripts on variousoperating systems.Works only with Windows.Supports mobile devices.Supports mobile devices with the help ofthird-party tools.Executes tests within thebrowser, so focus is NOTrequired while script execution isin progress.Needs Focus during script execution, as thetool acts on the browser (mimics useractions).Can execute tests in parallelwith the use of Selenium Grids.QTP cannot execute tests in parallel,however integrating QTP with QC allowstesters to execute in parallel. QC is also acommercial tool.2

SeleniumDisadvantages of SeleniumLet us now discuss the pitfalls of Selenium over QTP.SeleniumQTPSupports only web-basedapplications.Can test both web and desktopapplications.No feature such as ObjectRepository/Recovery ScenarioQTP has built-in object repositories andrecovery scenarios.No IDE, so the script developmentwon't be as fast as QTP.More intuitive IDE; automation can beachieved faster.Cannot access controls within thebrowser.Can access controls within the browsersuch as favorites bar, backward, andforward buttons.No default test report generation.Default test result generation within thetool.For parameterization, users has torely on the programming language.Parameterization is built-in and easy toimplement.3

2.SeleniumSELENIUM – IDESelenium – IDEThe Selenium-IDE (Integrated Development Environment) is an easy-to-useFirefox plug-in to develop Selenium test cases. It provides a Graphical UserInterface for recording user actions using Firefox which is used to learn and useSelenium, but it can only be used with Firefox browser as other browsers are notsupported.However, the recorded scripts can be converted into various programminglanguages supported by Selenium and the scripts can be executed on otherbrowsers as well.The following table lists the sections that we are going to cover in this chapter. .TitleDescriptionDownload SeleniumIDEThis section deals with how to download and configureSelenium IDE.Selenium IDEFeaturesThis section deals with the features available inSelenium IDE.Creating SeleniumIDE TestsThis section deals with how to create IDE tests usingrecording feature.Selenium IDE ScriptDebuggingThis section deals with debugging the Selenium IDEscript.InsertingVerification PointsThis section describes how to insert verification points inSelenium IDE.4

SeleniumSelenium PatternMatchingThis section deals with how to work with regularexpressions using IDE.Selenium UserExtensionsThe Java script that allows users to customize or addnew functionality.Different BrowserExecutionThis section deals with how to execute Selenium IDEscripts on different browsers.Download Selenium IDEStep 1 : Launch Firefox and navigate to the following URL –http://seleniumhq.org/download/.Under the Selenium IDE section, click on the link that shows the current versionnumber as shown below.Step 2 : Firefox add-ons notifier pops up with allow and disallow options. Userhas to allow the installation.5

SeleniumStep 3 : The add-ons installer warns the user about untrusted add-ons. Click'Install Now'.Step 4 : The Selenium IDE can now be accessed by navigating to Tools Selenium IDE.Step 5 : The Selenium IDE can also be accessed directly from the quick accessmenu bar as shown below.6

SeleniumFeatures of Selenium IDEThe following image shows the features of Selenium IDE with the help of asimple tooltip.The features of the record tool bar are explained below.7

SeleniumCreating Selenium IDE TestsThe following steps are involved in creating Selenium tests using IDE: Recording and adding commands in a test Saving the recorded test Saving the test suite Executing the recorded testRecording and Adding Commands in a TestWe will use www.ncalculators.com to demonstrate the features of Selenium.Step 1 : Launch the Firefox browserhttp://www.ncalculators.com/and navigate tothewebsite–Step 2 : Open Selenium IDE from the Tools menu and press the record buttonthat is on the top-right corner.8

SeleniumStep 3 : Navigate to "Math Calculator" "Percent Calculator enter "10" asnumber1 and 50 as number2 and click "calculate".Step 4 : User can then insert a checkpoint by right clicking on the webelementand select "Show all available commands" select "assert text css b 5"9

SeleniumStep 5 : The recorded script is generated and the script is displayed as shownbelow.Saving the Recorded TestStep 1 : Save the Test Case by navigating to "File" "Save Test" and save thefile in the location of your choice. The file is saved as .HTML as default.The test can also be saved with an extension htm, shtml, and xhtml.10

SeleniumSaving the Test SuiteA test suite is a collection of tests that can be executed as a single entity.Step 1 : Create a test suite by navigating to "File" "New Test Suite" asshown below.Step 2 : The tests can be recorded one by one by choosing the option "New TestCase" from the "File" Menu.Step 3 : The individual tests are saved with a name along with saving a "TestSuite".11

SeleniumExecuting the Recorded TestThe recorded scripts can then be executed either by clicking "Play entire suite"or "Play current test" button in the toolbar.Step 1 : The Run status can be seen in the status pane that displays thenumber of tests passed and failed.Step 2 : Once a step is executed, the user can see the result in the "Log" Pane.Step 3 : After executing each step, the background of the test step turns"Green" if passed and "Red" if failed as shown b

Selenium is an open-source and a portable automated software testing tool for testing web applications. It has capabilities to operate across different browsers and operating systems. Selenium is not just a single tool but a set of tools that helps testers to automate web-based applications more efficiently.

Related Documents:

Using the selenium.start() command initializes and starts the Selenium RC service. The Selenium RC client module (import selenium in Python) provides methods to operate the Selenium DSL commands (click, type, etc.) in the Browserbot running in the browser. For example, selenium.click("open") tells the

Selenium Grid Selenium Grid is a tool used to run parallel tests across different machines and different browsers simultaneously which results in minimized execution time. Advantages of Selenium QTP and Selenium are the most used tools in the market for software automation testing. Hence it makes sense to compare the pros of Selenium over QTP.

donated Selenium IDE to the Selenium project in the year 2006 Patrick Lightbody creates Selenium Grid to support parallel testing Birth of Selenium RC by Paul Hammant to counter same orginin policy (Selenium 1) Simon Stewart created Selenium WebDriver circa 2006 In 2008, RC and WebDriver are merged in

Selenium webdriver supports multiple web browsers and also support for Ajax applications. The main goal of the selenium webdriver is to improve support for modern web application testing problems. Selenium webdriver supports multiple languages to write the test scripts. Selenium webdriver's API is simpler than the selenium RC's [5].

What is Selenium ? Selenium is an open source test automation framework that support cross browser test automation Selenium 2 also known as WebDriver Selenium supports perl, php, python, objective-c, java, Microsoft.net, ruby, and more. It is not a tool with a UI –it uses a programming language to use it specifically

Differences between Selenium and QTP Selenium Components How to use validations Locatrors in Webdriver Selenium IDE Debugging the script Selenium RC Maintaining synchronization Points Selenium We

Selenium is a portable software-testing framework for web applications Selenium IDE is a complete integrated development environment Implemented as a Firefox extension Selenium IDE includes the entire Selenium Core, can allow recording Editing and debugging tests You can choose to use its recording capability,

than seven years. His primary interest is towards manual testing and he equally enjoys using Selenium for automated testing of web applications. He has been using Selenium from the days of Selenium Remote Control. He has co-authored the official Selenium doc available at SeleniumHQ. He is working as a Test Engineer at Pontiflex.