Download presentation
Presentation is loading. Please wait.
Published byCornelia Barker Modified over 8 years ago
1
Selenium Date:06/10/2009
2
May 13, 2009 2 Agenda Testing – Test Automation Selenium – Introduction – Features – Supported platforms Selenium Commands – Selenese – Script syntax Selenium Components – Selenium IDE – Selenium RC – Selenium Grid – Selenium Core Selenium IDE – Building test cases – Running test cases – Converting to other languages – Editing test cases and running with Selenium RC Selenium RC – Running HTML test suite
3
May 13, 2009 3 Testing: Test Automation Test automation is a process of writing a computer program to do testing that would otherwise need to be done manually Alternative to the tedious manual testing Overcomes the defects of manual testing Cost effective method Two approaches of test automation – Code Driven Testing – Graphical User Interface (GUI) Testing
4
May 13, 2009 4 Testing: Test Automation contd... Test automation supports: – Frequent regression testing – Rapid feedback to developers during the development process – Virtually unlimited iterations of test case execution – Customized reporting of application defects – Support for Agile and eXtreme development methodologies – Disciplined documentation of test casesCustomized reporting of application defects – Finding defects missed by manual testing
5
May 13, 2009 5 Selenium: Introduction Selenium is one of the most powerful open source automation tools for web application testing Primarily developed in Java Script and browser technologies such as DHTML and Frames and hence supports all the major browsers on all the platforms. In terms of coverage for platform and browser, Selenium is probably one of the best tool available in the market for web applications User can customize the selenium tool based on their requirement (code is available for the user).
6
May 13, 2009 6 Selenium: Introduction contd... Highly flexible Highly extensible Selenium Components – Selenium-IDE – Selenium-Remote Control (RC) – Selenium-Grid – Selenium Core
7
May 13, 2009 7 Selenium: Features Open Source tool for Web applications Tests Browser Compatibility and system functionality No licensing cost associated with it Customize according to our requirements Easy to use: – a) Test Cases are written in pure HTML – b) Clean and Impressive User Interface Selenium supports multi platform and multi browser in terms of coverage.
8
May 13, 2009 8 Selenium: Supported Platforms Windows: – Internet Explorer 6.0+ – Firefox 0.8 to 2 – Seamonkey 1.0 – Opera 8 Mac OS X: – Safari 1.3+ – Firefox 0.8 to 1.5 – Seamonkey 1.0 Linux: – Firefox – Konqueror
9
May 13, 2009 9 Selenium Commands: Selenese Selenium provides a rich set of commands for fully testing the web-application in virtually any way. The command set is often called selenese. These commands essentially create a testing language. A command tells selenium what exactly to do. There are three types of Selenium commands – Actions – Accessors – Assertions
10
May 13, 2009 10 Selenium Commands: Selenese contd... The selenese commands can test: – existence of UI elements based on their HTML tags – test for specific content – test for broken links, input fields, selection list options, submitting forms, and table data among other things – window size, mouse position, alerts – Ajax functionality – pop up windows and event handling
11
May 13, 2009 11 Selenium Commands: Selenese contd... Actions – Selenium Actions represent something a user would do – Commands that generally manipulate the state of the application – They do things like “click this link” and “select that option”. – If an Action fails, or has an error, the execution of the current test is stopped. – Many Actions can be called with the “AndWait” suffix, e.g. “clickAndWait”. – This command makes the browser to wait till the page loads
12
May 13, 2009 12 Selenium Commands: Selenese contd... Accessors: – Examine the state of application and store the results in variables – Any of the selenium accessors can be used to store value – Internally Selenium uses a map called storedVars keyed to the variable names. – They are also used to automatically generate Assertions – E.g. Use ${intAmount} to put the value stored in intAmount – Some of the key accessors are storeText, storeValue, storeCookie, storeAlert and storeEval
13
May 13, 2009 13 Selenium Commands: Selenese contd... Assertions: – Allows user to verify state of the application – All Selenium Assertions can be used in 3 modes Assert – Upon failure test is aborted Verify – Upon failure error is logged and test continues WaitFor – Waits for a conditions truth lines for given timeout – Assertions are like Accessors, but they verify that the state of the application conforms to what is expected E.g. “make sure the page title is X” and “verify that this checkbox is checked”
14
May 13, 2009 14 Selenium Commands: Script Syntax Selenium Commands consist of the command and two parameters. For eg: – verifyText //div//a[2] Login The parameters are not always required. It depends on the command In some cases both parameters are required, in others one parameter is required, and still in others the command may take no parameters at all. For eg.: – goBackAndWait command requires no parameter GoBackAndWait – verifyTextPresent command requires only one parameter verifyTextPresent Welcome to My Home Page – type command requires both the parameters type id=phone (555) 666-7066
15
May 13, 2009 15 Selenium Commands: Script Syntax contd... Commonly used Selenium Commands – click/clickAndWait performs a click operation, and waits for a new page to load – verifyTitle/assertTitle verifies an expected page title – verifyTextPresent verifies expected text is somewhere on the page – waitForPageToLoad pauses execution until an expected new page loads. Called automatically when clickAndWait is used
16
May 13, 2009 16 Selenium Components There are four variants or components of Selenium They can be used in isolation or in combination to create complete automation suite for the web applications. These components are – Selenium IDE – Selenium Remote Control (RC) – Selenium Grid – Selenium Core
17
May 13, 2009 17 Selenium Components: Selenium IDE Selenium IDE is a Firefox plug in, which includes the entire Selenium Core, allows to record, play back, edit, and debug tests in browser Selenium IDE is the only flavor of Selenium which allows to record user actions on browser window It can also record user actions in most of the popular languages like Java, C#, Perl, Ruby etc. This eliminates the need of learning new vendor scripting language. Selenium default scripts are html (added JavaScript)
18
May 13, 2009 18 Selenium Components: Selenium IDE contd... Selenium IDE – Installation – The installation is very simple. – It comes as the firefox plug in and it directly gets installed at the time of downloading itself, provided that firefox is installed – After installation it can be started directly from firefox Tools menu
19
May 13, 2009 19 Selenium Components: Selenium IDE contd...
20
May 13, 2009 20 Selenium Components: Selenium IDE contd... Selenium IDE contains toolbar including various buttons which are helpful in recording and running the tests Speed Control controls how fast the test case runs Run All runs the entire test suite when a test suite with multiple test cases is loaded Run runs the currently selected test Pause/Resume allows stopping and re-starting of a running test case Step allows one to “step” through a test case by running it one command at a time Record records the user's browser action
21
May 13, 2009 21 Selenium Components: Selenium IDE contd... TestRunner Mode allows to run the test case in a browser loaded with the Selenium-Core TestRunner. The TestRunner is not commonly used now and is likely to be deprecated. Test case pane displays the script. It has two tabs, one for displaying the command and their parameters in a readable “table” format. – Source tab displays the test case in the native format in which the file will be stored. By default, this is HTML – The Command, Target, and Value entry fields display the currently selected command along with its parameters.
22
May 13, 2009 22 Selenium Components: Selenium IDE contd... Log/Reference/UI-Element/Rollup Pane is used for four different functions–Log, Reference, UI-Element, and Rollup–depending on which tab is selected. – Log tab displays error messages and information messages showing the progress – Reference tab will display documentation on the current command. – The information for UI-Element and Rollup tab can be found in Help menu of Selenium IDE
23
May 13, 2009 23 Selenium Components: Selenium IDE contd... Test case pane Speed Control Run All Run Pause/Resume Step Test Runner Log/Reference/UI-Element/Rollup Pane Record
24
May 13, 2009 24 Selenium Components: Selenium IDE contd... Selenium IDE features – Easy record and playback – Debug and set breakpoints – Conversion of test cases to multiple programming languages – Option to automatically assert the title of every page – Support for Selenium user-extensions.js file – Very useful for beginners to understand the test cases and commands
25
May 13, 2009 25 Selenium Components: Selenium IDE contd... Selenium IDE is useful for less technical people, as it supports only simple programming and not the tests with complex programming functions Selenium does not directly support: – condition statements – Iteration – logging and reporting of test results – database testing – test case grouping – test case dependency
26
May 13, 2009 26 Selenium Components: Selenium RC Selenium Remote Control is a test tool that allows to write automated web application in any programming language (Java,.NET, Perl, Python, and Ruby, PHP) Selenium-RC is the solution for tests that need more than simple browser actions and linear execution. It uses full power of programming language. It overcomes the disadvantages of IDE Selenium RC can create more complex tests like reading and writing files, querying a database, emailing test results.
27
May 13, 2009 27 Selenium Components: Selenium RC contd... Although tasks that are not supported by IDE, are not supported by Selenium directly, all of them can be achieved by using programming techniques with a language-specific Selenium-RC client library. There are two components of Selenium RC, which play an important role in the running of the test cases. The components of Selenium RC are: – Selenium Server – Client Libraries
28
May 13, 2009 28 Selenium Components: Selenium RC contd... Selenium Server – Launches and kills browsers – Interprets and runs the Selenese commands passed from the test program – Acts as an HTTP proxy, intercepting and verifying HTTP messages passed between the browser and the AUT. Client libraries – Provide the interface between each programming language and the Selenium-RC Server.
29
May 13, 2009 29 Selenium Components: Selenium Grid Selenium Grid allows to run Selenium tests in parallel Cuts down the time required for running acceptance tests to a fraction of the total time it currently takes Selenium Grid runs on top of Selenium Remote Control It is primarily used in case of large test suites or the test suites that need to be run in multiple environment To run Selenium Grid, Ant 1.7+ needs to be installed on the system.
30
May 13, 2009 30 Selenium Components: Selenium Core Selenium Core is a Test Tool for web applications Selenium core tests runs directly in a Browser Written in Pure JavaScript and DHTML Selenium RC server uses Selenium Core while sending the requests to the browser Selenium Core interprets and executes Selenese commands using the browser’s built-in JavaScript interpreter
31
May 13, 2009 31 Selenium IDE: Building Test Cases There are three methods which are used in order to build the test cases. The developer, while building the test cases with Selenium IDE, requires all the three methods frequently. These methods are – Recording – Adding Verifications and Asserts With the Context Menu – Editing
32
May 13, 2009 32 Selenium IDE: Building Test Cases contd... Recording – This method records the user actions with the application under test. – To record the tests, start selenium IDE. – The record button on Selenium IDE toolbar is ON by default. – During recording, Selenium-IDE will automatically insert commands into the test case based on actions including, clicking a link entering values selecting options from a drop-down listbox clicking checkboxes or radio buttons
33
May 13, 2009 33 Selenium IDE: Building Test Cases contd... Adding Verifications and Asserts With the Context Menu – In order to do this, with Selenium-IDE recording, open the web page – Select some text and right click on the selected text – A context menu showing verify and/or assert commands gets displayed – Also, the Show All Available Commands menu option also gets displayed – This shows many, many more commands, again, along with suggested parameters, for testing currently selected UI element
34
May 13, 2009 34 Selenium IDE: Building Test Cases contd... Editing – Editing commands include inserting a new command or comment and editing the existing command or comment in the table view or source view – Insert Command To insert a command in table view, select the point in the test case where the command has to be inserted. Right-click and select Insert Command. Now use the command editing text fields to enter the new command and its parameters. To insert a command in source view, select the point in the test case where the command has to be inserted, and enter the HTML tags needed to create a 3-column row containing the Command. Be sure to save the test before switching back to Table view.
35
May 13, 2009 35 Selenium IDE: Building Test Cases contd... – Insert Comment To insert a comment in the table view, select the point in the test case where the comment has to be inserted. Right-click and select Insert Comment. Now use the Command field to enter the comment. The comment appears in purple font To insert a comment in the source view, select the point in the test case where the comment has to be inserted. Add an HTML-style comment, i.e.,
36
May 13, 2009 36 Selenium IDE: Building Test Cases contd... Edit a Command or Comment – To edit an existing command or comment in table view, simply select the line to be changed and edit it using the Command, Target, and Value fields – To edit an existing command or comment in source view, simply modify which line wished–command, parameter, or comment, since source view provides the equivalent of a WYSIWYG editor The File=>Open, Save and Save As menu commands behave similarly to opening and saving files in most other programs. When an existing test case is opened, Selenium-IDE displays its Selenium commands in the test case pane.
37
May 13, 2009 37 Selenium IDE: Running Test Cases IDE allows many options to run the test cases. With IDE, lot of things are possible. For instance, running the whole test case, starting and stopping it, running it one line at a time, and a batch run of entire test suite. Execution of test cases is very flexible Run a Test Case – Click the Run button to run the currently displayed test case Run a Test Suite – Click the Run All button to run all the test cases in the currently loaded test suite
38
May 13, 2009 38 Selenium IDE: Running Test Cases contd... Stop and Start – The Pause button can be used to stop the test case while it is running. The icon of this button then changes to indicate the Resume button. To continue click Resume Stop in the Middle – A breakpoint can be set in the test case to cause it to stop on a particular command. This is useful for debugging the test case. To set a breakpoint, select a command, right-click, and from the context menu select Toggle Breakpoint
39
May 13, 2009 39 Selenium IDE: Running Test Cases contd... Start from the Middle – The IDE can be told to begin running from a specific command in the middle of the test case. This also is used for debugging. To set a start- point, select a command, right-click, and from the context menu select Set/Clear Start Point Run Any Single Command – Double-click any single command to run it by itself. This is useful when writing a single command. This is very useful on having a doubt while writing the command
40
May 13, 2009 40 Selenium IDE: Running Test Cases contd... Using Base URL – The base URL field at the top of IDE is very useful in running the test cases in different domains – This is useful when the site has some in-house beta site. – Any test cases for a those particular sites that begin with an open statement should specify a relative URL as the argument to open rather than an absolute URL (one starting with a protocol such as http: or https:).
41
May 13, 2009 41 Selenium IDE: Running Test Cases contd... For eg: – The test case is running against - http://news.portal.com/about.html http://news.portal.com/about.html – This same test case with a modified Base URL setting would be run against http://beta.news.portal.com/about.html
42
May 13, 2009 42 Selenium IDE: Converting to other language One of the best feature of Selenium IDE is that it can convert the recorded test cases to different languages, such as Java, Ruby, Python, C# etc. With this conversion, the test cases can be run with selenium RC with the help of the language specific client libraries To convert the recorded test cases, Go to Options menu and click Format. On clicking Format a drop-down appears. Select the preferred language and the test cases get converted to the selected language.
43
May 13, 2009 43 Selenium IDE: Converting to other language contd... The converted test cases appear in the Source tab of Test pane. Selenium IDE cannot run these converted test cases
44
May 13, 2009 44 Selenium IDE: Converting to other language contd... These tests does not contain any programming logic such as conditions, testing database etc. These test cases can be executed with the help of the client libraries available for respective language in Selenium RC Optionally, test engine platform like Nunit and TestNG be adopted TestNG and Junit are the test engines very commonly used for Java Some development environments like eclipse has direct support for these test engines via plugin
45
May 13, 2009 45 Selenium IDE: Editing test cases and running with Selenium RC As discussed, Selenium IDE can record the test cases and can convert them to any of the languages of Java, Ruby, Python, Perl, C#,.Net etc To run these test cases, Selenium RC is used, as Selenium IDE can not run the test cases apart from those written in HTML Selenium RC uses language specific client drivers to run these test cases. For example, for running test cases in Java Selenium RC has Selenium-Java-client- driver
46
May 13, 2009 46 Selenium IDE: Editing test cases and running with Selenium RC contd... In order to run the test cases with Selenium RC, they have to be saved with respective extensions. For example, in order to run the test case that is converted to Java from Selenium IDE, it has to saved with extension.java Selenium RC, with the help of language specific client drivers, executes the test cases from different languages. The test cases that are exported from Selenium IDE may not be run directly with Selenium IDE. These test cases may require some editing in order to run them with Selenium RC.
47
May 13, 2009 47 Selenium IDE: Editing test cases and running with Selenium RC contd... The editing of the test cases, depend on the language the test case is converted in. For example, in order to run the test cases in Java, the class containing main method should be added. Likewise few lines of code may need to be added in the test cases, depending on the language Here are the sample main class that completes the test case and makes it ready to run as a Java test case using Java client driver. public static Test Suite(){ return new TestSuite(Classname.class); } public static void main(String args[]){ junit.textui.TestRunner.run(Suite()); }
48
May 13, 2009 48 Selenium RC: Running HTML test suite The Selenium RC server comes as an executable jar file This executable jar file comes with all the language specific client libraries Running the jar file allows to run the various test suites designed in the various languages with the help of the client libraries of respective languages The selenium RC can be downloaded from – http://seleniumhq.org/download/
49
May 13, 2009 49 Selenium RC: Running HTML test suite contd... Selenium IDE records the user actions and stores these user actions in the source tab of the test pane. The user actions are recorded and the test cases that are stored by selenium IDE are primarily stored in HTML. These HTML test cases can also be run with Selenium RC To run the test cases with Selenium RC, the test cases should be copied to some file with.html extension say Test.html Selenium RC cannot run test cases directly
50
May 13, 2009 50 Selenium RC: Running HTML test suite contd... To run the test cases with Selenium RC, these test cases should be embedded in a test suite say Suite.html The suite can contain one or more test cases In order to run the HTML test suite, the Selenium RC server should be run. After downloading Selenium RC, extract it in some directory After extracting Selenium RC go to the Selenium RC Server folder where the executable jar - selenium-server.jar To run the jar, the system must contain Java jre version 1.4 or above.
51
May 13, 2009 51 Selenium RC: Running HTML test suite contd... The results of the execution of test gets store in some HTML file say results.html To run the HTML test suite with Selenium RC, type the command – java -jar selenium-server.jar -htmlsuite *iexplore http://www.google.co.in /path/to/suite.html /path/to/results.htmlhttp://www.google.co.in This command runs all the test cases mentioned in suite.html and stores the results in results.html
52
May 13, 2009 52 Selenium: Disadvantages The Selenium remote control is quite slow at driving the browser It is possible to run only a limited number of concurrent tests on the same remote control server Selenium RC has a limitation in running tests in parallel If selenium fails to recognize objects, it cannot be assured of any add-ins which would be required Also Support provided for Selenium would be very less ( like in case of QTP, HP provides standard solutions and supports to issues)
53
May 13, 2009 53 Selenium: License All Selenium projects are licensed under the Apache 2.0 License. Apache license allows developer to contribute to the code This license also allows contributor to choose to distribute the Program in object code form under its own license agreement, with conditions. The complete license for Selenium can be found here: – http://www.apache.org/licenses/LICENSE-2.0
54
May 13, 2009 54 References http://seleniumhq.org/ Selenium Forums – http://clearspace.openqa.org/community/selenium http://clearspace.openqa.org/community/selenium – http://www.sqaforums.com/ http://www.sqaforums.com/ Selenium Commercial Support – http://thoughtworks.com/ http://thoughtworks.com/
55
Thank You !
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.