Writing first test Case using Robot Framework?

After our successful installation of Robot Framework and its required components or say dependencies, we would be writing our basic test case to taste the flavor of our newly learned framework.

Learn RobotFramework


Do follow us on  Fb,G+,Twitter, it encourages us to learn and share more.


Manual Test Case:-
[TC-001]-Launching the browser and search and launch the “uftHelp” Application on Google.com

Test Steps:-

  • Launch Browser
  • Search Application On Google
  • Launch Application

Now let’s give structure to our above Test Case as per RobotFramework (RF).

Note:- For running the test cases in chrome browser we need to chromedriver(downlaod this), For Linux OS place it under /usr/bin, windows use python/Scripts

Things to Learn:-
Everything in RF is given in the form of 4 tables which are called as “Setting”,”Variables”,”Test Cases” and “Keywords” table.You can learn about the detailed explanation on the RF official link, but here we can talk about them in layman terms.

Settings: – It’s equivalent to global dependencies like if we talk about Java language it’s like import statement written before coding begins or like stdio.h header in C language. Idea is it contains the settings like link to resources file, variable file, external libraries (say Selenium Library for web application).

Variables: – As the name indicates it contains our declaration of variables used in the flow of RF say like URL = www.google.com

Test Cases:- It is where we are going to define our manual test case flow in business like language thus it easily understood by non technical team members.

Keywords:- This is the place where real actions happens, meaning we give implementation to our above defined test case, like we say “Launch Browser” in our test cases table, than how RF know that its suppose to launch the browser. For that we need to define the meaning of “Launch Browser” in our keywords table. Generally we use pre-defined keywords from our external libraries but to enhance the testing capabilities we need to write our keywords definition using programming languages like python, java, .net.

Enough of theory lets create our first executable test case. We would be using any simple editor say notepad, notepad++ to create our RF tables. In future we would implement the same using RIDE or other editors like sublime/pyCharm.

Steps to follow:-

Step1:-

  • Open the editor and create the 4 tables preceded with asterisk (*) symbol, this is internally used by RF to distinguish the tables as anything outside these tables is redundant for RF.
  • Put one space and then add the name of the table,Say *** Settings ***

*** Settings ***
*** Variables ***
*** Test Cases ***
*** Keywords ***


Note:- 

  • For consistency purposes it is advisable to use 3, *** symbols in front of table name (as same would be created in RIDE).We can use * or ** or *** as all are same for RF. So don’t be confused lets have 3 *** symbols.
  • ‘*’ at the end are not required, but again for consistency purposed we are implementing them.

Step2:-

Copy the business steps of manual test case above and add to “Test Cases” table

*** Settings ***
*** Variables ***

*** Test Cases ***
[TC-001]-Launching the browser and search and launch the uftHelp Application on Google.com
Launch Browser
Search Application On Google
Launch Application

*** Keywords ***


Note:-

  • First row of the Test Cases table is used for Test Case name say for documentation.

Step3:-
Define the required variables in Variables table. Each variable is defined as ${variable name}

*** Settings ***

*** Variables ***
${APP} uftHelp
${URL} https://www.google.ca
${BROWSER} CHROME

*** Test Cases ***
[TC-001]-Launching the browser and search and launch the uftHelp Application on Google.com
Launch Browser
Search Application On Google
Launch Application
*** Keywords ***


Step4:-
Add the required libraries in “Settings” table, we would be using Selenium2Library as we would be working with browser application thus we need the keywords defined in this library.

*** Settings ***
Library Selenium2Library

*** Variables ***
${APP} uftHelp
${URL} https://www.google.ca
${BROWSER} CHROME

*** Test Cases ***
[TC-001]-Launching the browser and search and launch the “uftHelp” Application on Google.com
Launch Browser
Search Application On Google
Launch Application
*** Keywords ***


Step5:-
Main step to define the meaning of Keywords used in the Test Cases table. We would utilize the predefined keywords of “Selenium2Library”.

*** Settings ***
Library Selenium2Library

*** Variables ***
${APP} uftHelp
${URL} https://www.google.ca
${BROWSER} CHROME

*** Test Cases ***
[TC-001]-Launching the browser and search and launch the 'uftHelp' Application on Google.com
Launch Browser
Search Application On Google
Launch Application

*** Keywords ***
Launch Browser
Open Browser ${URL} ${BROWSER}
Maximize Browser Window
Search Application On Google
Input Text id=lst-ib ${APP}
Click Button name=btnG
Launch Application
Wait Until Element Is Visible link=User-Friendly Techy-Help 20 Seconds
Click Element link=User-Friendly Techy-Help


Step6:-
Save the file with .robot extension (it is same as .txt).

Note:- 

  • RF supports .html format, TSV format, Plain text and reStructuredText formats. In our example we have used plain text format which is widely implemented across the industry.
  • For identifying the locator properties of the object above, you can use firebug, or simply use selenium -IDE, record a script and extract properties.

Step7:-

Run the file using “pybot” interpreter.
Write the command pybot testcaseName.robot on command prompt and we are ready with results.

Running robotFramework Test


Note:- 
Don’t worry incase the code is not running in first go, there can be issues like spell mistakes or extra spaces, just copy the above code, save and execute it.
For any help and issues please share your comments below.
Learn further How to execute the above test case in RIDE (IDE for robot framework)

Keep learning and keep sharing 🙂

Learn RobotFramework
Learn Selenium

ufthelp

10 thoughts on “Writing first test Case using Robot Framework?

  1. when I run from command line this is what i see:
    C:Python27>robot –test Valid Login Test_Case_1.txt
    [ ERROR ] Parsing 'Login' failed: Data source does not exist.

    Try –help for usage information.

    C:Python27>cd Scripts

    C:Python27Scripts>pybot Test_Case_1.robot
    [ ERROR ] Error in file 'C:Python27ScriptsTest_Case_1.robot': Importing test
    library 'Selenium2Library' failed: ImportError: No module named Selenium2Library

    Traceback (most recent call last):
    None
    PYTHONPATH:
    C:WINDOWSsystem32python27.zip
    C:Python27DLLs
    C:Python27lib
    C:Python27libplat-win
    C:Python27liblib-tk
    C:Python27
    C:Python27libsite-packages
    ==============================================================================
    Test Case 1
    ==============================================================================
    [TC-001]-Launching the browser and search and launch the 'uftHelp'… | FAIL |
    No keyword with name 'Open Browser' found.
    ——————————————————————————
    Test Case 1 | FAIL |
    1 critical test, 0 passed, 1 failed
    1 test total, 0 passed, 1 failed
    ==============================================================================
    Output: C:Python27Scriptsoutput.xml
    Log: C:Python27Scriptslog.html
    Report: C:Python27Scriptsreport.html

    C:Python27Scripts>

  2. getting error while running the test

    [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
    [TC-001]-Launching the browser and search and launch the 'uftHelp'… Exception AttributeError: "'Service' object has no attribute 'process'" in > ignored
    [TC-001]-Launching the browser and search and launch the 'uftHelp'… | FAIL |
    WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

  3. The error i continue to get when trying to move chromedriver over to /usr/bin is – The operation can’t be completed because an unexpected error occurred (error code -8058).

  4. i have installed RIDE in my windows 10 environment..After that how to write test cases and what keywords should we mainly learn for network automation…Can u please help me in that….Thanks in advance…please help me….

  5. Getting the ERROR:UnicodeDecodEerror: 'utf8' codec can't decode byte 0x93 in position 57: invalid start byte when trying to run the test case. Can someone help me?

  6. [8780:6180:0906/103343.143:ERROR:configuration_policy_handler_list.cc(92)] Unknown policy: DisableSSLRecordSplitting
    [8780:6180:0906/103343.143:ERROR:configuration_policy_handler_list.cc(92)] Unknown policy: PasswordManagerAllowShowPasswords
    [8780:6180:0906/103343.144:ERROR:configuration_policy_handler_list.cc(92)] Unknown policy: SSLVersionMin
    Traceback (most recent call last):
    File "C:Python27libsite-packagesrobotidecontribtestrunnertestrunnerplugin.py", line 370, in OnTimer
    self._test_runner.get_output_and_errors(self.get_current_profile())
    File "C:Python27libsite-packagesrobotidecontribtestrunnertestrunner.py", line 250, in get_output_and_errors
    stdout, stderr, returncode = self._process.get_output(),
    File "C:Python27libsite-packagesrobotidecontribtestrunnertestrunner.py", line 305, in get_output
    return self._output_stream.pop()
    File "C:Python27libsite-packagesrobotidecontribtestrunnertestrunner.py", line 400, in pop
    return result.decode('UTF-8')
    File "C:Python27libencodingsutf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
    UnicodeDecodeError: 'utf8' codec can't decode byte 0x93 in position 57: invalid start byte
    ERROR: IDS_SCANFORVIRUSES not found in string file.
    ERROR: IDS_SCANFORVIRUSES not found in string file.

    Test Log-
    20170906 10:33:59.496 : FAIL :
    ElementNotVisibleException: Message: element not visible
    (Session info: chrome=61.0.3163.79)
    (Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 6.1.7601 SP1 x86_64)

    Ending test: Browser.[TC-001]-Launching the browser and search and launch the “uftHelp” Application on Google.com

  7. Hi,
    I am not able to insert the value into the text filed which is on the table format.

    Notes:
    1) I tried to enter value using
    Input Text id=xyz
    2) I tried to input the value using,
    Input Text = xpath=""

    But getting an error that "ValueError: Element locator '//*[@id="setupTable"]' did not match any elements."
    Any suggestion are most welcome.
    Thank you in advance!

  8. I am getting following error::
    C:UsersPC>pybot RBTestcase.robot
    [ ERROR ] Parsing 'RBTestcase.robot' failed: Data source does not exist.

    Any help please,

Leave a Reply

Your email address will not be published. Required fields are marked *