How to validate each test case in Robot Framework

1,181 views
Skip to first unread message

Nagaraj Hebbar

unread,
Oct 12, 2015, 2:51:29 AM10/12/15
to robotframework-users
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.
          

Ben Fariello

unread,
Oct 12, 2015, 8:44:26 PM10/12/15
to robotframework-users
Make your validation keyword accept a parameter called ${error_msg} and then say "Page Should Contain ${error_msg}", and pass the error message in as another parameter for your test template. Pretty straightforward, that way.

Ben Fariello

unread,
Oct 12, 2015, 8:46:11 PM10/12/15
to robotframework-users
On second thought you should do what I said, but leave out the validation keyword entirely. Just call Page Should Contain directly in your Test Template. No need for a wrapper in that case

Nagaraj Hebbar

unread,
Oct 13, 2015, 8:15:42 AM10/13/15
to robotframework-users


On Tuesday, 13 October 2015 06:16:11 UTC+5:30, Ben Fariello wrote:
On second thought you should do what I said, but leave out the validation keyword entirely. Just call Page Should Contain directly in your Test Template. No need for a wrapper in that case

Thanks for the Reply Ben is it possible to give the script how it should look like...

Hélio Guilherme

unread,
Oct 13, 2015, 8:30:24 AM10/13/15
to robotframework-users
Hi,

I have posted this in LinkedIn:

This is my proposal (using 4 spaces format, but not tested):

* Test Cases *** Number Name Join Date Validation

Empty Employee Number ${EMPTY} Foo 01 Apr 2015 Please enter the Number
Empty Employee Name 1000 ${EMPTY} 01 Apr 2015 Please enter the Name
Empty Join Date 1000 Foo ${EMPTY} Please enter the Join Date
Duplicate Employee Number 1000 Foo 01 Apr 2015 Duplicate Employee Number


* Keywords ***

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


Validation check for Invalid Data
[Arguments] ${validation}
Page Should Contain ${validation}

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages