Download - Selenium (2)

Transcript
Page 1: Selenium (2)

Case Selenium

www.Seleniumonlinetraining.info

Page 2: Selenium (2)

1.Acceptance testing1.What you should test?

2.Robot Framework3.Selenium

1.Syntax2.Xpath3.Command types4.Common commands5.Terms

4.Features5.Demo6.Tips’n’tricks7.Selenium RS

www.Seleniumonlinetraining.info

Page 3: Selenium (2)

• vs. unit testing• Acceptance testing = UI testing• Suunto requires us to write tests

o Good• Suunto requires

o use of Seleniumo use of Robot Framework

www.Seleniumonlinetraining.info

Page 4: Selenium (2)

Test expected contentTest linksTest functionsTest dynamic elements…http://seleniumhq.org/docs/

06_test_design_considerations.html#what-to-test

www.Seleniumonlinetraining.info

Page 5: Selenium (2)

• Environment to run Selenium tests• Automated• I know nothing of Robot Framework, but it must be cool

www.Seleniumonlinetraining.info

Page 6: Selenium (2)

• 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

www.Seleniumonlinetraining.info

Page 7: Selenium (2)

• XML query language• Features

o Selecting nodes by path by predicates with wildcards

o Axeso Operators

o Examples: • //div[@id='cartable']/table/tbody/tr/td[1]• //input[@value='Jatka']• RTFM: http://www.w3schools.com/XPath/xpath_syntax.asp

www.Seleniumonlinetraining.info

Page 8: Selenium (2)

Syntax

command                target                value

eg.

verifyTextPresent    id=phone        0700123123

www.Seleniumonlinetraining.info

Page 9: Selenium (2)

• 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”.

www.Seleniumonlinetraining.info

Page 10: Selenium (2)

Test are divided to • Test suites• Test cases

Test suites are built from test cases.

Both test cases AND test suites should be parameterised.

www.Seleniumonlinetraining.info

Page 11: Selenium (2)

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.

www.Seleniumonlinetraining.info

Page 12: Selenium (2)

Firefox extensionVery easy to get to know Selenium

and to play with itAlso supports recording and running

test cases / suiteshttp://seleniumhq.org/download/Features

Recording tests, running tests, test cases, test suites, breakpoints, pausing execution, export as code

www.Seleniumonlinetraining.info

Page 13: Selenium (2)

B – set breakpointX – execute commandS – set starting point

Good for debugging!

www.Seleniumonlinetraining.info

Page 14: Selenium (2)

Test Samuli’s application Transitions Adding cars, parameters

▪ Test constraints List cars

▪ Added cars are actually listened

www.Seleniumonlinetraining.info

Page 15: Selenium (2)

• 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

www.Seleniumonlinetraining.info

Page 16: Selenium (2)

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

www.Seleniumonlinetraining.info

Page 17: Selenium (2)

http://seleniumhq.org/docs/index.html

http://code.google.com/p/robotframework/

www.Seleniumonlinetraining.info