Changes between Initial Version and Version 1 of DeveloperGuidelines/Testing/EdenTest/WriteTestcase/Advanced


Ignore:
Timestamp:
06/06/14 11:52:46 (8 years ago)
Author:
Arnav Sharma
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/Testing/EdenTest/WriteTestcase/Advanced

    v1 v1  
     1= Advanced Test Design =
     2
     3Continuing from the tutorial on [http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/EdenTest/WriteTestcase How to write a testcase?], this article focuses on the advanced aspects of !EdenTest.
     4
     5If you have implemented '''Login with invalid email and passwd should fail''', your testsuite login_funtionality.txt should look like this.
     6{{{
     7*** Settings ***
     8Documentation       Test case to check the login functionality of Eden
     9Library     Selenium2Library
     10Variables         ../../execution/config.py
     11Test Teardown       Close Browser
     12
     13*** Test Cases ***
     14Login with valid email and valid passwd should be successful
     15    Open Browser        http://${SERVER}/eden/default/user/login   
     16    Input Text      auth_user_email     admin@example.com
     17    Input Text      auth_user_password      testing
     18    Click Button        xpath=//input[@class='btn' and @value='Login']
     19    Page Should Contain     Logged in
     20
     21Login with invalid email and valid passwd should fail
     22    Open Browser        http://${SERVER}/eden/default/user/login
     23    Input Text      auth_user_email     nottheadmin@example.com
     24    Input Text      auth_user_password      testing
     25    Click Button        xpath=//input[@class='btn' and @value='Login']
     26    Page Should Contain     Invalid login
     27}}}
     28
     29== Variables ==
     30
     31=== What are Variables? ===
     32Variables 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.
     33
     34=== Types of Variables ===
     35There are three types of variables in Robot Framework:
     36* Scalars - ${SCALAR}
     37* Lists - @{LIST}
     38* Environment Variables - %{Environment Variable}
     39
     40=== When to use Variables? ===
     41The use of variables is recommended in the following cases:
     42* When strings change often in the test data. With variables you only need to make these changes in one place.
     43* 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.
     44* When values in the test data are long or otherwise complicated.
     45
     46=== Using Variables ===
     47
     48{{{
     49*** Variables ***
     50${LOGIN URL}        http://${SERVER}/eden/default/user/login
     51${SUBMIT}       xpath=//input[@class='btn' and @value='Login']
     52${EMAIL ID}        auth_user_email
     53${PASSWORD ID}     auth_user_password
     54
     55
     56*** Test Cases ***
     57Login with valid email and valid passwd should be successful
     58    Open Browser        ${LOGIN URL}
     59    Input Text      ${EMAIL}     admin@example.com
     60    Input Text      ${PASSWORD}      testing
     61    Click Button        ${SUBMIT}
     62    Page Should Contain     Logged in
     63
     64Login with invalid email and valid passwd should be successful
     65    Open Browser        ${LOGIN URL}
     66    Input Text      ${EMAIL}     nottheadmin@example.com
     67    Input Text      ${PASSWORD}      testing
     68    Click Button        ${SUBMIT}
     69    Page Should Contain     Invalid login
     70}}}
     71
     72Note: The `*** Settings ***` would remain as it is.
     73
     74== User Keywords ==
     75
     76=== What are User Keywords? ===
     77
     78Keywords are the functions of Robot Framework.
     79
     80User 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.
     81
     82=== Implementing User Keywords ===
     83
     84In 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.
     85
     86{{{
     87
     88*** Keywords ***
     89Login with email and passwd
     90    [Documentation]      Opens a browser to login url, inputs username and password
     91    [Arguments]     ${email}    ${passwd}
     92    Open Browser        ${LOGIN URL}
     93    Input Text      ${EMAIL ID}     ${email}
     94    Input Text      ${PASSWORD ID}      ${passwd}
     95    Click Button        ${SUBMIT}
     96
     97*** Test Cases ***
     98Login with valid email and valid passwd should be successful
     99    Login with email and passwd     admin@example.com   testing
     100    Page Should Contain     Logged in
     101
     102Login with invalid email and valid passwd should be successful
     103    Login with email and passwd     iamnottheadmin@example.com   testing
     104    Page Should Contain     Invalid login
     105}}}
     106
     107Note: `*** Settings ***`, `*** Variables ***` sections stay as it is.
     108