Selenium - Tutorialspoint

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 Se

Selenium RC Selenium Remote Control (RC) was the flagship testing framework that allowed more than simple browser actions and linear execution. It makes use of the full power of programming languages such as Java, C#, PHP, Python, Ruby, and PERL to create more complex tests. Selenium WebDriver Selenium WebDriver is the successor to Selenium