Friday, 28 December 2012

Now we will see how to write test case in robot framework.
We are taking following scenerio:
1. Given that user will be on gmail login page
2. When user will enter correct credentials
3. Then required account will open

Here lets create this in RIDE :)

 1. Right click on folder and click on New Resource. Enter "Keword_resource" in name field then click ok. Similarly create a new resource as "Parameters_resources".
There will be two files Keword_resource.txt and Parameters_resources.txt
Add library(Selenium2Library) in Keword_resource.txt file(see previous post to see how to add library). Add resource(Keyword_resource.txt) in TestSuite.txt file.

 2. Click on folder (say Demo in our case) then add resources by clicking resource button
 add both resource file like this. Then these files will be shows a blue link.

 3.  Click on test case (say TestCase1 in our case)
 4.  Write these line as in screen shot (You can modify as per your convenience)


 5. Then click on first step of test case right click -> create keyword. Keyword will be in TestSuite.
    Drag it and drop in Keword_resource.txt. Do it for all steps.
6. Click on first cell and enter Open Browser(press Ctrl + Space key to see detail of command)
    for url we are creating variable so that we can change it if required.

          Open Browser    www.gmail.com    ff

Right click on http://www.gmail.com cell then click Extract variable.
 Enter ${url} in name field then click Ok.
Drag this keyword into Parameters_resource.txt file and add it as resource in Keyword_resource.txt file.

Smilary create keywords and parameters for other two steps like following screen shots:
Code for "user enter correct credentials" keyword
*** Settings ***
Library           Selenium2Library
Resource          parameters_resources.txt

*** Keywords ***
user is on Gmail page
    Open Browser    ${url}    ff

user enter correct credentials
    Input Text    Email    ${username}
    Input Password    Passwd    ${password}
    Click Button    signIn

user will be on desired account
    [Timeout]
    comment     verify that page has been loaded


screen shot:


And code for "user will be on desired account" :
*** Settings ***
Library           Selenium2Library
Resource          parameters_resources.txt

*** Keywords ***
user is on Gmail page
    Open Browser    ${url}    ff

user enter correct credentials
    Input Text    Email    ${username}
    Input Password    Passwd    ${password}
    Click Button    signIn

user will be on desired account
    [Timeout]
    comment     verify that page has been loaded
 
Screen shot:


7. You can run suite by two ways:
    - Run from UI directly(click on robot icon)(problem: output files will be created in tmp folder)
    - Run from Command Prompt go to that folder and type
          pybot Demo_robo
If we use Command prompt to run suite then ouput files will be created in test folder itself, so no need to search tmp folder.

By these ways you can create first test script...
:) Happy learning..

Fell free for any query...

1 comment:

  1. "Add resource(Keyword_resource.txt) in TestSuite.txt file."

    I'm a bit confused. Where did you get 'TestSuite.txt' file?

    ReplyDelete