Robot Framework setup using Python on mac

Python Robot framework setup on Mac:

Know about Robot framework:

Robot framework is a test automation framework which is used for acceptance testing and ATDD (Acceptance test driven development). It is a keyword driven testing approach. There are many predefined keywords which are implemented using Python and Java. We can write our own new keywords using the existing predefined keywords.

A good documentation is on Github ,
https://github.com/robotframework/robotframework

Robot framework has many keywords which will be useful when writing test automation either for desktop web application or a mobile application. You just need to import the respective library before using it.

Here is the guide for seleniumLibrary keywords :
GitHub Selenium Library
SeleniumLibrary

Here is the guide for appiumLibrary keywords which can be used for mobile app automation:
Appium Library

The above 2 guides are super useful when writing the test automation, those urls are very clear on using different keywords with good examples.

So, How write test automation using Robot Framework and Python:
You can use Robot framework either using Python or Java. Im familiar with using Python, So I put the things in Python based environment.
Tip : Always try to be updated so that you can get access to most updated features, So always try to use latest release versions.

Tools used:
Pycharm Community Edition (Which you can download for free) , download it here based on your computer OS : https://www.jetbrains.com/pycharm/download


First step is to have the environment setup:
  • Install Python on your machine, If not done please do the installation.
  • Then proceed to Robot framework related installation using pip command
  • pip install robotframework
  • Check installation using
  • robot --version
  • Install selenium library using
  • pip install robotframework-seleniumlibrary
  • install appium library using (If you want to write mobile automation)
  • pip install robotframework-appiumlibrary

........Boom..!! there you go its done. You are ready to rock.


Second step is How to create a new Robot framework project in pycharm:

Ok, In pycharm Create a new project using following steps
  • Give the project Name as you like
  • Select the python interpreter
  • Then Click on create.


  • So, A new Project will be created like this, with selected python environment 

    Okay, We have the new project created. Whats next?
  • Create a new python directory (Do the necessary directory creation based on your requirement)
  • Create a new robot file. A robot file will have an extension of .robot
  •  
    So, Now you know how to create a new project with necessary installations.

    Okay, let me explain more about .robot file. What robot file contains?

    Robot file contains:
    Test cases:
    • Test cases are written under the representation of *** Test Cases ***
    • A robot file contains many test cases, All should be written under *** Test Cases ***
    • Each test case contains a title called Test title (Test title is a sentence or a word which tells about the test scenario/user journey or a behaviour)
    • Each test case have test steps (Keywords) written under test title
    Keywords:
    • A robot file may or may not have keywords section. If we use the predefined keywords. Then no need to implement user defined keywords, In such case there will not be use of keywords section.
    • Keywords can be written under *** Keywords ***
    • Keyword has a keyword name. which we will use in test cases or in another keyword definition
    • user defined Keyword can use a predefined keywords or a user defined keyword
    Settings
    • Settings section is used to import the libraries.
    • A library can be a python predefined library, user defined robot file or a python file.
    Variables
    • Variables is a section, where we can define some variables which can be used across the robot file.
    • Variables should be written under *** variables ***
    • examples:
      *** Variables ***
      ${Var1} value
      ${Var2} 2
      ${Var3} https://www.google.com
    ** In robot file, test cases can be written using Gherkin words like Given, When and Then. Robot file ignores those words when referring to keywords. Here is a simple example on how you can write simple test automation using Robot framework and python. 
    If you observe the snippet,
    Settings section:
    • I have imported the `SeleniumLibrary` using `Library` command
    • You can use `Resource` to import another robot file which has user defined keywords
    • You can use `Variables` to import other python files of your project which contains variables
    Test cases section:
    • There is only one test case in this file.
    • Test cases are written in Gherkin format, Robot framework can understand those words so it ignores those Gherkin wordings
    • All the yellow coloured sentences are keywords. 3 keywords from SeleniumLibrary and 1 is user defined keyword
    • I have used a variable which is defined in variables section
    • Some keywords take arguments.
    • example : `Input Text` keyword takes locator (name:q —> this is the identifier of google search box) and value (hello —> to input)
    • [Tags] are used when you want to run the test cases based on some grouping, so please give proper tag names
    • [Documentation] is like doc
    Keywords section:
    • I have implemented one user defined keyword, which I have used in the test case
    • My user defined keyword uses predefined keyword. It can also use another user defined keyword.
    • Keywords can accept arguments

    **The test cases, keywords and its parameters/arguments can be separated using pipe symbol (|) or minimum 2 spaces. In this blog I used tab.

    Okay, How to run a robot framework test case,
    pybot tests/test_first.robot

    Robot framework generates beautiful html reports. The reports are very detailed reports.

    This is just from my learning. There is a lot to explore. Hope this helps you start your learning. Thanks for reading, Happy learning.

    Comments

    1. Really an informative blog...Thanks for sharing an informative article with us.

      What is blockchain?
      Why blockchain is important

      ReplyDelete
    2. Great Content. Thanks for sharing this valuable information. It will be useful for knowledge seekers.
      Scrum Master Certification In Chennai
      CSM Training In Bangalore
      Scrum Master Certification Online

      ReplyDelete
    3. This post is so interactive and informative.keep update more information...
      dot net training in T Nagar
      Dot net training in Chennai

      ReplyDelete
    4. This post is so interactive and informative.keep update more information...
      Java Training in Tambaram
      Java training in chennai

      ReplyDelete

    Post a Comment