180 likes | 426 Views
Case Selenium. Acceptance testing. Summary. Acceptance testing What you should test? Robot Framework Selenium Syntax Xpath Command types Common commands Terms Features Demo Tips’n’tricks Selenium RS. Acceptance testing. vs. unit testing Acceptance testing = UI testing
E N D
Case Selenium Acceptance testing
Summary • Acceptance testing • What you should test? • Robot Framework • Selenium • Syntax • Xpath • Command types • Common commands • Terms • Features • Demo • Tips’n’tricks • Selenium RS
Acceptance testing • vs. unit testing • Acceptance testing = UI testing • Suunto requires us to write tests • Good • Suunto requires • use of Selenium • use of Robot Framework
What you should test? • Test expected content • Test links • Test functions • Test dynamic elements • … • http://seleniumhq.org/docs/06_test_design_considerations.html#what-to-test
Robot Framework • Environment to run Selenium tests • Automated • I know nothing of Robot Framework, but it must be cool
Selenium • Selenium is a suite of automated tool for testing web application front end – UI test framework • Selenium emulates browser user • Selenium commands are like "write text "Panu" to input which id is "name"" • Selenium's language supports simple scripting (operators, defining variables) • Selenium supports multiple methods to locate elements • Element ID • Element name attribute • Xpath • DOM • CSS
Xpath • XML query language • Features • Selecting nodes • by path • by predicates • with wildcards • Axes • Operators • Examples: • //div[@id='cartable']/table/tbody/tr/td[1] • //input[@value='Jatka'] • RTFM: http://www.w3schools.com/XPath/xpath_syntax.asp
Selenium - syntax Syntax command target value eg. verifyTextPresent id=phone 0700123123
Selenium - command types • Actions are 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. • Accessors examine the state of the application and store the results in variables, e.g. “storeTitle”. They are also used to automatically generate Assertions. • Assertions are like Accessors, but they verify that the state of the application conforms to what is expected. Examples include “make sure the page title is X” and “verify that this checkbox is checked”.
Selenium - terms Test are divided to • Test suites • Test cases Test suites are built from test cases. Both test cases AND test suites should be parameterised.
Selenium - Common commands open opens a page using a URL. click/clickAndWait performs a click operation, and optionally waits for a new page to load. verifyTitle/assertTitle verifies an expected page title. verifyTextPresent verifies expected text is somewhere on the page. verifyElementPresent verifies an expected UI element, as defined by its HTML tag, is present on the page. verifyText verifies expected text and it’s corresponding HTML tag are present on the page. verifyTable verifies a table’s expected contents. waitForPageToLoad pauses execution until an expected new page loads. Called automatically when clickAndWait is used. waitForElementPresent pauses execution until an expected UI element, as defined by its HTML tag, is present on the page.
Selenium IDE • Firefox extension • Very easy to get to know Selenium and to play with it • Also supports recording and running test cases / suites • http://seleniumhq.org/download/ • Features • Recording tests, running tests, test cases, test suites, breakpoints, pausing execution, export as code
Selenium IDE – Cheat sheet • B – set breakpoint • X – execute command • S – set starting point • Good for debugging!
Demo • Test Samuli’s application • Transitions • Adding cars, parameters • Test constraints • List cars • Added cars are actually listened
Selenium tips'n'tricks • DON’t trust Selenium IDE or it’s default Xpath! • You might have to change HTML code a bit to make it easier to test automatically, eg. Add id/name attributes • That’s completely OK! • “AndWait” commands wait until whole page has been loaded • Very useful, but they don’t work with Ajax • Difference between assert and verify • If asset fails => test stops • If verify fails => test continues • echo command is good for debugging
Selenium RS • Selenium IDE has a poor support for programming, it does NOT support • condition statements • iteration • logging and reporting of test results • error handling, particularly unexpected errors • database testing • test case grouping • re-execution of failed tests • test case dependency • screenshot capture of test failures • Selenium RS supports adding programming logic to tests • .NET supported => though • I have no experience
More? • http://seleniumhq.org/docs/index.html • http://code.google.com/p/robotframework/