Nagaraj Hebbar
Nagaraj Hebbar

Reputation: 39

How to validate each test case in Robot Framework

How to validate each test case in Robot Framework. Like if i have 3 fields Name,Number and Join Date and Save button, all are mandatory fields.

First Case--> I will enter the Number and Join Date and click on the Save button then validation message will appear "Please enter the Name"

Second Case-->I will enter the Name and Join Date and click on the Save button then validation message will appear "Please enter the Number"

Third Case-->I will enter the Name and Number and click on the Save button then validation message will appear "Please enter the Join Date "

Fourth Case-->1000 is already added then if i enter the Name,Number,Join Date click on the Save button validation message will appear "Duplicate Employee Number"

How to handle this case need to use "Test Template " if i use the Test Template

*** Settings ***
Documentation     A test suite containing tests related to invalid login.
...
...                     These tests are data-driven by they nature. They use a single
...                   keyword, specified with Test Template setting, that is called
...                    with different arguments to cover different scenarios.
...
...                    This suite also demonstrates using setups and teardowns in
...                    different levels.
Test Template     Invalid Data
Resource           resource.txt

*** Test Cases ***                           Number                     Name                    Join Date       
Empty Employee Number               ${EMPTY}                  Foo                       01 Apr 2015         
Empty Employee Name                  1000                         ${EMPTY}               01 Apr 2015
Empty Join Date                            1000                          Foo                        ${EMPTY}

*** Keywords ***
Invalid Data
      [Arguments]    ${employeenumber}    ${name}    ${doj}
      Enter Employee Number        ${employeenumber}
      Enter Employee Name           ${name}
      Enter Join Date                     ${doj}
      Validation check for Invalid Data

Validation check for Invalid Data
       Page Should Contain        Please enter the Name
       Page Should Contain        Please enter the Number
       Page Should Contain        Please enter the Join Date  

If i use like this then first test case is Pass and rest of the test case will be Fail because for the second test case it will check for "Page Should Contain Please enter the Name" but for the second test case we are already adding the Number. How to handle these kind of cases in Robot Framwork can any one help me.

Upvotes: 1

Views: 5030

Answers (2)

Sharvik Patel
Sharvik Patel

Reputation: 31

In robot framework, with the help of if statement validators can be in used LIKE EXAMPLE -

***variables***
${code_snippets}   print("Hello I am Sharvik")


***Test Cases***
        Input text   Locater_here   ${code_snippets}
    
        IF    ${code_snippets} == ${code_snippets}
                     Log    This line IS executed.
        END

Now if in this code something gets change in variable section then the Automation script will be failed.

Upvotes: 0

Bryan Oakley
Bryan Oakley

Reputation: 385830

Add another argument for what you want to validate

*** Keywords ***
Invalid data
[Arguments]    ${employeenumber}    ${name}    ${doj}    ${expected}
...
Page should contain    ${expected}

*** Test Cases ***      Number    Name      Join Date     Expected       
Empty Employee Number   ${EMPTY}  Foo       01 Apr 2015   Please enter the name
Empty Employee Name     1000      ${EMPTY}  01 Apr 2015   Please enter the number
Empty Join Date         1000      Foo       ${EMPTY}      Please enter the Join Date

Upvotes: 1

Related Questions