Version 1 (modified by 11 years ago) ( diff ) | ,
---|
Advanced Test Design
Continuing from the tutorial on How to write a testcase?, this article focuses on the advanced aspects of EdenTest.
If you have implemented Login with invalid email and passwd should fail, your testsuite login_funtionality.txt should look like this.
*** Settings *** Documentation Test case to check the login functionality of Eden Library Selenium2Library Variables ../../execution/config.py Test Teardown Close Browser *** Test Cases *** Login with valid email and valid passwd should be successful Open Browser http://${SERVER}/eden/default/user/login Input Text auth_user_email admin@example.com Input Text auth_user_password testing Click Button xpath=//input[@class='btn' and @value='Login'] Page Should Contain Logged in Login with invalid email and valid passwd should fail Open Browser http://${SERVER}/eden/default/user/login Input Text auth_user_email nottheadmin@example.com Input Text auth_user_password testing Click Button xpath=//input[@class='btn' and @value='Login'] Page Should Contain Invalid login
Variables
What are Variables?
Variables are an integral feature of Robot Framework, and they can be used in most places in test data. Most commonly, they are used in arguments for keywords and settings. Eg: config.py contains variables like SERVER
, APPNAME
etc.
Types of Variables
There are three types of variables in Robot Framework:
- Scalars - ${SCALAR}
- Lists - @{LIST}
- Environment Variables - %{Environment Variable}
When to use Variables?
The use of variables is recommended in the following cases:
- When strings change often in the test data. With variables you only need to make these changes in one place.
- When different keywords, even in different test libraries, need to communicate. You can assign a return value from one keyword to a variable and give that as an argument to another.
- When values in the test data are long or otherwise complicated.
Using Variables
*** Variables *** ${LOGIN URL} http://${SERVER}/eden/default/user/login ${SUBMIT} xpath=//input[@class='btn' and @value='Login'] ${EMAIL ID} auth_user_email ${PASSWORD ID} auth_user_password *** Test Cases *** Login with valid email and valid passwd should be successful Open Browser ${LOGIN URL} Input Text ${EMAIL} admin@example.com Input Text ${PASSWORD} testing Click Button ${SUBMIT} Page Should Contain Logged in Login with invalid email and valid passwd should be successful Open Browser ${LOGIN URL} Input Text ${EMAIL} nottheadmin@example.com Input Text ${PASSWORD} testing Click Button ${SUBMIT} Page Should Contain Invalid login
Note: The *** Settings ***
would remain as it is.
User Keywords
What are User Keywords?
Keywords are the functions of Robot Framework.
User Keywords are new higher-level keywords by combining existing keywords together. These keywords are called user keywords to differentiate them from lowest level library keywords that are implemented in test libraries. The syntax for creating user keywords is very close to the syntax for creating test cases, which makes it easy to learn.
Implementing User Keywords
In the example we have been following, we had to repeat few steps in both the testcases. We can take out those common steps into a higher level user keyword. Lets call it Login with email and passwd. It takes the email and passwd as the arguments.
*** Keywords *** Login with email and passwd [Documentation] Opens a browser to login url, inputs username and password [Arguments] ${email} ${passwd} Open Browser ${LOGIN URL} Input Text ${EMAIL ID} ${email} Input Text ${PASSWORD ID} ${passwd} Click Button ${SUBMIT} *** Test Cases *** Login with valid email and valid passwd should be successful Login with email and passwd admin@example.com testing Page Should Contain Logged in Login with invalid email and valid passwd should be successful Login with email and passwd iamnottheadmin@example.com testing Page Should Contain Invalid login
Note: *** Settings ***
, *** Variables ***
sections stay as it is.