Changes between Version 2 and Version 3 of DeveloperGuidelines/Testing/EdenTest/WriteTestcase/Advanced


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

--

Legend:

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

    v2 v3  
    66{{{
    77*** Settings ***
    8 Documentation       Test case to check the login functionality of Eden
    9 Library     Selenium2Library
    10 Variables         ../../execution/config.py
    11 Test Teardown       Close Browser
     8Documentation  Test case to check the login functionality of Eden
     9Library  Selenium2Library
     10Variables  ../../execution/config.py
     11Test Teardown  Close Browser
    1212
    1313*** Test Cases ***
    1414Login 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
     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
    2020
    2121Login 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
     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
    2727}}}
    2828
     
    4848{{{
    4949*** 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
     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
    5454
    5555
    5656*** Test Cases ***
    5757Login 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
     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
    6363
    6464Login 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
     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
    7070}}}
    7171
     
    8888*** Keywords ***
    8989Login 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}
     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}
    9696
    9797*** Test Cases ***
    9898Login 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
     99    Login with email and passwd  admin@example.com  testing
     100    Page Should Contain  Logged in
    101101
    102102Login 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
     103    Login with email and passwd  nottheadmin@example.com  testing
     104    Page Should Contain  Invalid login
    105105}}}
    106106
     
    110110
    111111=== What is Data-Driven testing? ===
    112 Data-driven approach to testing is where test cases use only one higher-level keyword, normally created as a user keyword (as shown above), that hides the actual test workflow. These tests are very useful when there is a need to test the same scenario with different input and/or output data. It would be possible to repeat the same keyword with every test, but the test template functionality allows specifying the keyword to use only once. Thus, a testsuite file will run the same Test template with a lot of test data, each of which will be a testcase. Example follows.
     112Data-driven approach to testing is where test cases use only one higher-level keyword, normally created as a user keyword (as shown above), that hides the actual test workflow.
    113113
     114These tests are very useful when there is a need to test the same scenario with different input and/or output data. It would be possible to repeat the same keyword with every test, but the test template functionality allows specifying the keyword to use only once. Thus, a testsuite file will run the same Test template with a lot of test data, each of which will be a separate testcase. Example follows.
    114115
    115116=== Using Data-Driven Testing ===
     
    118119{{{
    119120*** Settings ***
    120 Documentation       Test case to check the login functionality of Eden
    121 Library     Selenium2Library
    122 Variables         ../../execution/config.py
    123 Test Teardown       Close Browser
    124 Test Template   Login should fail
     121Documentation  Test case to check the login functionality of Eden
     122Library  Selenium2Library
     123Variables  ../../execution/config.py
     124Test Teardown  Close Browser
     125Test Template  Login should fail
    125126
    126127
    127128*** Variables ***
    128 ${LOGIN URL}        http://${SERVER}/eden/default/user/login
    129 ${SUBMIT}       xpath=//input[@class='btn' and @value='Login']
    130 ${EMAIL ID}        auth_user_email
    131 ${PASSWORD ID}     auth_user_password
     129${LOGIN URL}  http://${SERVER}/eden/default/user/login
     130${SUBMIT}  xpath=//input[@class='btn' and @value='Login']
     131${EMAIL ID}  auth_user_email
     132${PASSWORD ID}  auth_user_password
    132133
    133134
    134135*** Keywords ***
    135136Login with email and passwd
    136     [Documentation]      Opens a browser to login url, inputs username and password
    137     [Arguments]     ${email}    ${passwd}
    138     Open Browser        ${LOGIN URL}
    139     Input Text      ${EMAIL ID}     ${email}
    140     Input Text      ${PASSWORD ID}      ${passwd}
    141     Click Button        ${SUBMIT}
     137    [Documentation]  Opens a browser to login url, inputs username and password
     138    [Arguments]  ${email}  ${passwd}
     139    Open Browser  ${LOGIN URL}
     140    Input Text  ${EMAIL ID}  ${email}
     141    Input Text  ${PASSWORD ID}  ${passwd}
     142    Click Button  ${SUBMIT}
    142143
    143144Login should fail
    144     [Documentation]      Opens a browser to login url, inputs invalid username or password and checks for failure
    145     [Arguments]     ${email}    ${passwd}
    146     Login with email and passwd         ${email}    ${passwd}
    147     Page Should Contain     Invalid login
     145    [Documentation]  Opens a browser to login url, inputs invalid username or password and checks for failure
     146    [Arguments]  ${email}  ${passwd}
     147    Login with email and passwd  ${email}  ${passwd}
     148    Page Should Contain  Invalid login
    148149
    149150
    150 *** Test Cases ***                          email                         password
    151 The email is invalid        nottheadmin@example.com        testing
    152 The password is Invalid     admin@example.com              incorrect
    153 Both are Invalid                nottheadmin@example.com     incorrect
     151*** Test Cases ***
     152The email is invalid  nottheadmin@example.com  testing
     153The password is Invalid  admin@example.com  incorrect
     154Both are Invalid  nottheadmin@example.com  incorrect
    154155}}}
    155156
    156 There are three test cases above, all of which implement the keyword `Login should fail` given against the setting `Test Template`. All the testcases implement the keyword with the arguments given against it.  The keyword `Login should fail` takes two arguments and asserts that the login should fail for that case. Run the tests and
     157There are three test cases above, all of which implement the keyword `Login should fail` given against the setting `Test Template`. All the testcases implement the keyword with the arguments given against it.  The keyword `Login should fail` takes two arguments and asserts that the login should fail for that case.
    157158
    158159=== Further exercise ===
     
    160161* Login form validation
    161162* Login should pass [email] [password]
     163Also, try and improve the Teardown and Setup of the above tests. Refer to this [http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html#test-setup-and-teardown documentation] for help.