Selenium
Upcoming SlideShare
Loading in...5
×
 

Selenium

on

  • 5,788 views

 

Statistics

Views

Total Views
5,788
Views on SlideShare
1,833
Embed Views
3,955

Actions

Likes
1
Downloads
45
Comments
0

12 Embeds 3,955

http://ajohnstone.com 3853
http://blog.ajohnstone.com 61
http://abtasty.com 20
http://www.ajohnstone.com 8
http://ec2-46-51-171-110.eu-west-1.compute.amazonaws.com 4
http://bitek.ajohnstone.com 2
http://46.51.171.110 2
http://blueliquidcdkeys.com 1
http://www.ajohnstone.cowww.ajohnstone.com 1
http://http.www.ajohnstone.com 1
http://prlog.ru 1
http://jenkins.ajohnstone.com 1
More...

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Selenium Selenium Presentation Transcript

  • Introduction Locators Waiting Examples Other Selenium Andrew Johnstone November 13, 2011Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherOutline 1 Introduction 2 Locators 3 Waiting 4 Examples 5 Other Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherOutline 1 Introduction 2 Locators 3 Waiting 4 Examples 5 Other Andrew Johnstone Selenium View slide
  • Introduction Locators Waiting Examples OtherOutline 1 Introduction 2 Locators 3 Waiting 4 Examples 5 Other Andrew Johnstone Selenium View slide
  • Introduction Locators Waiting Examples OtherOutline 1 Introduction 2 Locators 3 Waiting 4 Examples 5 Other Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherOutline 1 Introduction 2 Locators 3 Waiting 4 Examples 5 Other Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherWhat is functional testing Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functional testing typically involves five steps The identification of functions that the software is expected to perform The creation of input data based on the function’s specifications The determination of output based on the function’s specifications The execution of the test case The comparison of actual and expected outputs Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherWhat is functional testing Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functional testing typically involves five steps The identification of functions that the software is expected to perform The creation of input data based on the function’s specifications The determination of output based on the function’s specifications The execution of the test case The comparison of actual and expected outputs Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherWhat is functional testing Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functional testing typically involves five steps The identification of functions that the software is expected to perform The creation of input data based on the function’s specifications The determination of output based on the function’s specifications The execution of the test case The comparison of actual and expected outputs Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherWhat is functional testing Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functional testing typically involves five steps The identification of functions that the software is expected to perform The creation of input data based on the function’s specifications The determination of output based on the function’s specifications The execution of the test case The comparison of actual and expected outputs Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherWhat is functional testing Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functional testing typically involves five steps The identification of functions that the software is expected to perform The creation of input data based on the function’s specifications The determination of output based on the function’s specifications The execution of the test case The comparison of actual and expected outputs Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherWhat is functional testing Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functional testing typically involves five steps The identification of functions that the software is expected to perform The creation of input data based on the function’s specifications The determination of output based on the function’s specifications The execution of the test case The comparison of actual and expected outputs Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherWhat is functional testing Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functional testing typically involves five steps The identification of functions that the software is expected to perform The creation of input data based on the function’s specifications The determination of output based on the function’s specifications The execution of the test case The comparison of actual and expected outputs Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherSelenium Selenium is a tool to automate browsers. It consists of four projects Selenium IDE - Firefox add-on that makes it easy to record and playback tests Selenium Core - Runs the tests directly in the browser Selenium RC - Allows you to control web browsers locally or on other computers Selenium Grid - Runs tests on many servers at the same time Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherSelenium Selenium is a tool to automate browsers. It consists of four projects Selenium IDE - Firefox add-on that makes it easy to record and playback tests Selenium Core - Runs the tests directly in the browser Selenium RC - Allows you to control web browsers locally or on other computers Selenium Grid - Runs tests on many servers at the same time Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherSelenium Selenium is a tool to automate browsers. It consists of four projects Selenium IDE - Firefox add-on that makes it easy to record and playback tests Selenium Core - Runs the tests directly in the browser Selenium RC - Allows you to control web browsers locally or on other computers Selenium Grid - Runs tests on many servers at the same time Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherSelenium Selenium is a tool to automate browsers. It consists of four projects Selenium IDE - Firefox add-on that makes it easy to record and playback tests Selenium Core - Runs the tests directly in the browser Selenium RC - Allows you to control web browsers locally or on other computers Selenium Grid - Runs tests on many servers at the same time Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherWhy Selenium Selenium - functional testing for web and mobile based applications. (Drivers NOW exist for mobiles/tablets) Multi browser support Write test cases in many languages. Simply record interactions with a website from Firefox using an IDE Tests are repeatable Difficulties/issues with Selenium Handling ajax request/responses on pages IE test execution with locators Flash/Flex automation Rich text editors (CKEditor) Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators identifier=id - Locates @id and falls back to @name id=id - Locates @id only name=name - Locates @name only dom=javascriptExpression - document.getElementById(’el’); xpath=xpathExpression link=textPattern css=cssSelectorSyntax ui=uiSpecifierString - A map of aliases for common elements. Known as a GUI Map Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators identifier=id - Locates @id and falls back to @name id=id - Locates @id only name=name - Locates @name only dom=javascriptExpression - document.getElementById(’el’); xpath=xpathExpression link=textPattern css=cssSelectorSyntax ui=uiSpecifierString - A map of aliases for common elements. Known as a GUI Map Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators identifier=id - Locates @id and falls back to @name id=id - Locates @id only name=name - Locates @name only dom=javascriptExpression - document.getElementById(’el’); xpath=xpathExpression link=textPattern css=cssSelectorSyntax ui=uiSpecifierString - A map of aliases for common elements. Known as a GUI Map Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators identifier=id - Locates @id and falls back to @name id=id - Locates @id only name=name - Locates @name only dom=javascriptExpression - document.getElementById(’el’); xpath=xpathExpression link=textPattern css=cssSelectorSyntax ui=uiSpecifierString - A map of aliases for common elements. Known as a GUI Map Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators identifier=id - Locates @id and falls back to @name id=id - Locates @id only name=name - Locates @name only dom=javascriptExpression - document.getElementById(’el’); xpath=xpathExpression link=textPattern css=cssSelectorSyntax ui=uiSpecifierString - A map of aliases for common elements. Known as a GUI Map Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators identifier=id - Locates @id and falls back to @name id=id - Locates @id only name=name - Locates @name only dom=javascriptExpression - document.getElementById(’el’); xpath=xpathExpression link=textPattern css=cssSelectorSyntax ui=uiSpecifierString - A map of aliases for common elements. Known as a GUI Map Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators identifier=id - Locates @id and falls back to @name id=id - Locates @id only name=name - Locates @name only dom=javascriptExpression - document.getElementById(’el’); xpath=xpathExpression link=textPattern css=cssSelectorSyntax ui=uiSpecifierString - A map of aliases for common elements. Known as a GUI Map Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators identifier=id - Locates @id and falls back to @name id=id - Locates @id only name=name - Locates @name only dom=javascriptExpression - document.getElementById(’el’); xpath=xpathExpression link=textPattern css=cssSelectorSyntax ui=uiSpecifierString - A map of aliases for common elements. Known as a GUI Map Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators identifier=id - Locates @id and falls back to @name id=id - Locates @id only name=name - Locates @name only dom=javascriptExpression - document.getElementById(’el’); xpath=xpathExpression link=textPattern css=cssSelectorSyntax ui=uiSpecifierString - A map of aliases for common elements. Known as a GUI Map Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators - Xpath/CSS XPATH is SLOW on IE as such use CSS selectors for locating simple elements. They’re faster They’re more readable CSS is jQuery’s locating strategy No one else uses XPATH anyway Performance comparison of CSS vs XPATH Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators CSS - Direct child A direct child in XPATH is defined by the use of a "/", while on CSS, it’s defined using ">" Xpath //div/a CSS css=div > a Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators CSS - Child or subchild If an element could be inside another or one it’s childs, it’s defined in XPATH using "//" and in CSS just by a whitespace Xpath //div/a CSS div a Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators CSS - Id An element’s id in XPATH is defined using: "[@id=’example’]" and in CSS using: "#" Xpath //div[@id=’example’]//a CSS css=div#example a Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators CSS - Class For class, things are pretty similar in XPATH: "[@class=’example’]" while in CSS it’s just "." Xpath //div[@class=’example’]//a CSS css=div.example a Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators CSS - More examples Not all CSS 3 selectors are supported by Selenium 2. Next sibling - css=form input.username + input Attribute values - css=form input[name=’username’] Attribute values - css=input[name=’continue’][type=’button’] Matching by text - css=a:contains(’Log Out’) Match li by nth child - css=ul#recordlist li:nth-of-type(4) Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators XPATH - Examples XPATH Selectors can easily become horrible and unmanageable //div[text() = "Click here"] //div[contains(text(), "Click here")] xpath=//label[text()=’Full Name:’]/following-sibling::input //nobr[contains(text(), ’Message Sent’)] //div[contains(@class, ’x-combo-list’) and contains(@style, ’visibility: visible’)] Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherLocators XPATH - The Good, the bad and the ugly An example of a bad XPath - it will break as soon as the page layout changes /html/body/div[1]/div[5]/div/table/tbody/tr/td/p/a[3] An un-named input box that has a known label 2 table cells away from it //td[contains(text()),’My Label’]/following-sibling::td[2]/input Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherWaiting... WaitForElementPresent | css=h2:contains(’Manta’) | 60000 This waits for the title "Manta" to appear. If your app fails and the title’s text loaded is incorrect? It will wait for the time out to be exceeded before failing. A better way... WaitForElementPresent | css=h2.titles_class | 60000 assertText css=h2.titles_class | Manta All wait commands will use a delay within a loop until a condition is met. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherWaiting... WaitForElementPresent | css=h2:contains(’Manta’) | 60000 This waits for the title "Manta" to appear. If your app fails and the title’s text loaded is incorrect? It will wait for the time out to be exceeded before failing. A better way... WaitForElementPresent | css=h2.titles_class | 60000 assertText css=h2.titles_class | Manta All wait commands will use a delay within a loop until a condition is met. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherWaiting... Selenium 2.0 - Use implicit waits over explicit waits Explicit Waits An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. There are some convenience methods provided that help you write code that will wait only as long as required. WebDriverWait in combination with ExpectedCondition is one way this can be accomplished. Implicit Waits An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples Othersaucelabs Selenium RC in the cloud with support for all major browsers Sauceconnect allows access to internal firewalled infrastructure from saucelabs Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherInstallation of Selenium su apt-get update apt-get install php-pear pear upgrade pear pear channel-discover pear.phpunit.de pear channel-update pear.phpunit.de pear channel-discover components.ez.no pear channel-update components.ez.no pear channel-discover pear.symfony-project.com pear channel-update pear.symfony-project.com pear channel-discover saucelabs.github.com/pear pear channel-update saucelabs.github.com/pear pear install -a saucelabs/PHPUnit_Selenium_SauceOnDemand sauce configure <username> <key> Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherExample Selenium test case with PHPUnit <?php r e q u i r e _ o n c e ’ PHPUnit / E x te n s i o ns / SeleniumTestCase / ’ . ’ SauceOnDemandTestCase . php ’ ; c l a s s ExampleTest extends PHPUnit_Extensions_SeleniumTestCase_SauceOnDemandTestCase { f u n c t i o n setUp ( ) { $ t h i s −>setOs ( ’ Windows 2003 ’ ) ; $ t h i s −>setBrowser ( ’ f i r e f o x ’ ) ; $ t h i s −>se tB ro ws er Ve rs io n ( ’ 3 . 6 . ’ ) ; $ t h i s −>s e t B r o w s e r U r l ( ’ h t t p : / / example . saucelabs . com ’ ) ; } f u n c t i o n test_example ( ) { $ t h i s −>open ( ’ / ’ ) ; $ t h i s −>a s s e r t T i t l e ( ’ Cross browser t e s t i n g w i t h Selenium − Sauce Labs ’ ) ; } } Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherExample Selenium test case with PHPUnit Example running against 3 different browsers. Tests can be parallelized to speed execution. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherSelenium versions Selenium 1 Recommended timeouts 90000ms - the default is set to selenium.setTimeout(30000); Generate application states with test handles. As an example if a login fails certain paths of execution will not be acheivable, as such skip them. Ignore Open and waitForPageToLoad failures - common failures are css stylesheets not loading properly. In particular onIE6 + IE7 will cause random failures Selenium 2 Ignoring Open and waitForPageToLoad failures Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherStructuring tests... Always use Annotations to indicate the group of the tests to perform. Examples of these... always - Always executed sanity - The sanity group is used to annotate a select group of test methods that can be used as a sanity suite. smoke - Provide some assurance that the system under test will not catastrophically fail. functional - The functional group is used to annotate a group of test methods that can be used as a full regression suite. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherStructuring tests... Always use Annotations to indicate the group of the tests to perform. Examples of these... always - Always executed sanity - The sanity group is used to annotate a select group of test methods that can be used as a sanity suite. smoke - Provide some assurance that the system under test will not catastrophically fail. functional - The functional group is used to annotate a group of test methods that can be used as a full regression suite. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherStructuring tests... Always use Annotations to indicate the group of the tests to perform. Examples of these... always - Always executed sanity - The sanity group is used to annotate a select group of test methods that can be used as a sanity suite. smoke - Provide some assurance that the system under test will not catastrophically fail. functional - The functional group is used to annotate a group of test methods that can be used as a full regression suite. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherStructuring tests... Always use Annotations to indicate the group of the tests to perform. Examples of these... always - Always executed sanity - The sanity group is used to annotate a select group of test methods that can be used as a sanity suite. smoke - Provide some assurance that the system under test will not catastrophically fail. functional - The functional group is used to annotate a group of test methods that can be used as a full regression suite. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherStructuring tests... Always use Annotations to indicate the group of the tests to perform. Examples of these... always - Always executed sanity - The sanity group is used to annotate a select group of test methods that can be used as a sanity suite. smoke - Provide some assurance that the system under test will not catastrophically fail. functional - The functional group is used to annotate a group of test methods that can be used as a full regression suite. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherStructuring tests... Always use Annotations to indicate the group of the tests to perform. Examples of these... deprecated - The deprecated group is used to mark individual test cases that are no longer active, due to removed or changed functionality. unstable - The unstable group is used to mark individual test cases that are unstable. Some test cases may block the harness from executing, and these test methods must be removed from the active test suites to reduce false negative results. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherStructuring tests... Always use Annotations to indicate the group of the tests to perform. Examples of these... deprecated - The deprecated group is used to mark individual test cases that are no longer active, due to removed or changed functionality. unstable - The unstable group is used to mark individual test cases that are unstable. Some test cases may block the harness from executing, and these test methods must be removed from the active test suites to reduce false negative results. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherStructuring tests... Always use Annotations to indicate the group of the tests to perform. Examples of these... deprecated - The deprecated group is used to mark individual test cases that are no longer active, due to removed or changed functionality. unstable - The unstable group is used to mark individual test cases that are unstable. Some test cases may block the harness from executing, and these test methods must be removed from the active test suites to reduce false negative results. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherAlerts Alerts are a problem with Selenium 1.0, alerts and confirms are blocking. Selenium 2.0 overrides the alert, confirm functions within javascript. Version 1.0 could not handle them. AssertAlertPresent - to verify an alert is present AssertAlert - will add an extra step of verifyTextPresent "Alert is gone". Do not remove this condition. Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherAjax This will check whether ajax requests are presently active. Dojo Javascript Framework w a i t F o r C o n d i t i o n ( ’ selenium . browserbot . getCurrentWindow ( ) . d o j o . i o . XMLHTTPTransport . i n F l i g h t . l e n g t h == 0 ; ’ ) ; Prototype Javascript Framework w a i t F o r C o n d i t i o n ( ’ selenium . browserbot . getCurrentWindow ( ) . Ajax . activeRequestCount == 0 ; ’ ) ; Jquery Javascript Framework w a i t F o r C o n d i t i o n ( ’ selenium . browserbot . getUserWindow ( ) . $ . ajaxRequests == 0 ; ’ ) ; Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherAdvanced examples Testing navigation on Gorkana with dropdown menus $ t h i s −>w a i t F o r C o n d i t i o n ( ’ selenium . browserbot . getCurrentWindow ( ) . jQuery ( .sf-with- ul:visible ) . l e n g t h > 0 ’ , 5 0 0 0 ) ; $dom = DOMDocument : : loadHTML ( $html = $ t h i s −>getHtmlSource ( ) ) ; $xpath = new DOMXpath ( $dom ) ; $ r e t = $xpath−>e v a l u a t e ( ’ / / d i v [ @id=menuBar ] / u l / l i ’ ) ; $i = 0; f o r e a c h ( $ r e t as $ r ) { $xml = $dom−>saveXML ( $ r ) ; i f ( i s _ i n t ( s t r i p o s ( $xml , ’ s f−sub−i n d i c a t o r ’ ) ) ) { $xpath = xpath=id(’menuBar’)/ul/li[ . ( $ i +1) . ]/a ; $ t h i s −>mouseOver ( $xp ) ; usleep ( 3 0 0 0 0 0 ) ; $ t h i s −>a s s e r t V i s i b l e ( $xp ) ; } $ i ++; } Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherAdvanced examples I will send around separate examples of the following. Handling emails - such as forgotten passwords Handling rich text editors - such as CKEditor Handling Ajax Handling Excel as a data provider Andrew Johnstone Selenium
  • Introduction Locators Waiting Examples OtherSummary Questions? Andrew Johnstone Selenium