1. Overview of Robot Framework
Robot Framework is a testing framework. It provides everything needed to build and develop a test script, including input / end conditions, reporting results, etc. The appeal of Robot Framework with testers is that we don't need to worry about it. consider the most basic programming algorithms. Everything we need to do is write a test script based on keywords (keyword) only.
More specifically, the Robot Framework is:
- Framework for testing, provides testing platform for tester based on Python programming language. The approach of this testing platform is keyword driven and data driven for testing for end-to-end acceptance testing.
- To approach this testing platform, the tester only needs to write a test script with the keyword driven and data driven data.
- Tester can create new high-level keywords from existing ones using the same syntax used to create test cases.
The outstanding features of Robot Framework:
- Robot Framework helps us to perform automated testing with script in table form easily. The Robot Framework delivers the results of executing test scripts and logs in html format, helping us to read and analyze the results more quickly and easily.
- The Robot Framework supports the functionality of marking test scripts, allowing us to choose quick and convenient test scripts.
- The biggest strength of the Robot Framework is its ability to run on many different operating systems without modifying test scripts or downstairs keywords.
2. Supported libraries in Robot Framework
The Robot Framework has many libraries that support automated testing, can refer to the library for Robot Framwwork at http://robotframework.org/#test-libraries .
However, in this article, we will focus on introducing the two most popular libraries: Selenium2Library and Calculator Library.
- Selenium2Library is used for Web-based testing, and is forked from SeleniumLibrary and added to use Selenium 2 and WebDriver.
- Selenium2Library works in most popular browsers like IE, Firefox, Safari, Chrome, etc. and can be used with both Python and Jython.
To run the testcase using Selenium2Library, you first need to:
- Install Selenium2Library,
- Import Selenium2Library into testsuite Robots.
- Use the Open Browser keyword to enable the browser you want to use for testing.
Why should use Selenium2Library library?
Selenium2Library is a language that is very close to the user's actual language, what kind of action do you want, just type the corresponding keyword.
- input text: enter a string of characters
- click button: click
- double click element: double click the element
- get alert message: get the value of the notification
- open context menu: open submenus
- etc …
Learn more at:
Next we will learn about a library that is available in the Robot Framework, a simple computing library that contains only business logic and not the UI part.
Let's go through an example of CalculatorLibrary and run a simple test case to better understand the Robot Framework.
You can download the demo here: https://bitbucket.org/robotframework/robotdemo/downloads .
The above example includes 5 Testcases: Of which there are 4 TCs for example PASSED, and 1 TC example of FAILED:
- Push button PASSED
- Push multiple buttons FAILED
- Simple calculation PASSED
- Longer calculation PASSED
- Clear PASSED
The keyword is quite simple and easy to understand so I do not explain anything more. Now we will run these 5 TCs with Terminal on Linux as follows:
- Download the library and available at: https://bitbucket.org/robotframework/robotdemo/downloads .
- Open the terminal and point to the folder containing the downloaded file.
- Run test case "keyword_driven.robot" with the following command: $ robot keyword_driven.robot .
The result is 4 TCs Pass and 1 TC Failed.
Conclusion: For Robot Framework we don't need to know programming to write testcase and script like other tools. For simple and quick requirements, the Robot Framework is a suitable choice.
This section explains how to install RF together with Selenium on Linux and Windows.
1. Install Robot Framework
Step 1. Install Python.
First of all, because the Robot Framework is a testing platform based on Python, it is necessary to first install Python (Python 2.5 or later should be installed – recommended to install Python 2.7).
Linux: Python often comes with Ubuntu / Linux installation. To check if Python is installed, as well as its version, use the following command on Terminal (you can use the keyboard shortcut Ctrl + Alt + T to enable Terminal: $ python -version . If Python is already installed, You will see its version, such as Python 2.7.6.
Windows: Similar to Linux, turn on the cmd and check if python is installed with: python -version command. If not, go to https://www.python.org/ and download the corresponding Python version and install it.
Step 2. Install PIP (Python Package Manager).
Linux: PIP is a package manager for setting up Python packages. To install PIP, use the following command:
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
Windows: PIP has been installed if you are using Python 2> = 2.7.9 or Python 3> = 3.4 downloaded from https://www.python.org/ , however you will need to upgrade the PIP with the command after:
python -m pip install -U pip
Step 3. Install the Robot Framework package using PIP.
Linux: Use the following command to install Robot Framework:
$ sudo pip install robotframework
The latest version of Robot Framework will be installed automatically. If you want to install a specific version, just add it, for example:
$ sudo pip install robotframework == 2.8.4
After the installation is complete, use the following command to see if the installation was successful: $ pybot -version . You will see information about the Robot Framework version if successfully set up.
Windows: In the Command promt window, go to the Python installation directory and use the following command to install RF:
pip install robotframework
After successful installation, use pybot -version to check:
2. Install Selenium2Library
To work with Webdriver (Selenium2) and Robot Framework, you need to install Selenium2Library using PIP:
Linux: Use the following command: $ sudo pip install robotframework-selenium2library
This command will automatically install its dependencies, including decorators, and Selenium packages. As soon as the installation is complete, use the $ python command to navigate to the python window:
In this window, type the following command to import Selenium2 Library: >> import Selenium2Library .
If no error is detected, the Selenium2 library has been successfully installed. If you want to exit the Python window, use the exit () command .
Windows: In the Command promt window, use the command: pip install robotframework-selenium2library . After successful installation will have the following message:
3. RIDE Installation (Standalone RobotFramework Test Data Editor)
RIDE is an IDE for building tests using the Robot Framework. In addition to RIDE, you can replace it with SublimeText, IntelliJ or Eclipse, … Because RIDE was developed using wxPython, you need to install the wxPython 2.8 toolkit that supports unicode to run RIDE. As follows:
Linux: Use the following command to install wxPython:
$ sudo apt-get install python-wxgtk2.8
$ sudo apt-get install python-wxversion
Next, use the following command to install RIDE:
$ sudo pip install robotframework-ride
To verify whether the installation was OK yet, run the following command: $ ride.py. The RIDE application will pop up as follows:
- First, you need to go to https://sourceforge.net/projects/wxpython/files/wxPython/ to select and download the appropriate version of wxpython to your computer. Then, start the installation:
- In the Command promt window, use the command: pip install robotframework-ride to install RIDE.
- After successful installation will have the following message
- Use the command: ride.py to start RIDE.
III. How to catch the interface element
1. XPath overview
- XPath is a way to analyze HTML code to identify elements of a web driver.
- A language that supports searching information in XML documents using XPath expressions to orient the search for data on XML instead of performing a recursive search to browse the XML tree.
- XPath defines 7 types of nodes according to the model shown below from root, element, attribute, text, namespace, processing-instruction and comment.
- In addition, XPath defines some special nodes to show the relationship between the nodes in the model in the process of processing as follows:
- Parent Node: the direct upper node of the current node.
- Child Node: the direct node of the lower-level current node.
- Sibling: peer node or the same parent as the current node.
- Ancestors: all child nodes above the current node are in the same branch.
- Descendants: all sub-nodes below the current node are in the same branch.
- For an absolute path query to go from the root of the XML document to the components to access, the XPath specified with the syntax starts with a /
- For a query with a relative path to be able to access any part of the condition, the XPath specifies the syntax to use with the //
- To query for any element without knowing its name, the XPath specifies the character to be used *.
- To access the properties of a node, the XPath specifies that the query attribute must have a syntax starting with @.
- Condition when query is placed in 
- Query select nodes
Select all child nodes of the node name.
Select all nodes from root.
Select all nodes counted from the current node.
Select the current node.
Select the parent node of the current node.
Math operations used in XPath:
- Algebra: +, -, * (multiply), div (decimal division), mod (divide by balance)
- Compare or relate: =,! = (Other), <, <=,>,> =
- Reason: true, false, and, or, not
- Combination: | (Assembly)
2. How to catch XPath with Firebug and FirePath
Firebug and FirePath are two add-ons that support fast and easier XPath capture in Firefox browsers.
Install Firebug and FirePath:
- In Firefox browser, select the icon [Open Menu] -> Add-ons.
- Find and install Firebug, FirePath.
After successful installation, Firebug and FirePath appear in Extensions section and their icons will appear in Firefox's toolbar.
Use Firebug and FirePath:
- Click the bug icon -> select the FirePath card.
- Click the arrow symbol next to the bug -> click on the element to get the xpath. The xpath of that element will show:
- XPath obtained from FirePath is for reference only and helps users identify elements more easily.
- XPath obtained from FirePath is the simplest way, but does not guarantee stability and only when the version of the web page changes. Therefore, users can use several ways to support the following query to capture XPath to increase stability and availability when they want to use elements that relate to each other more accurately:
Select all the nodes on the current node.
Select all nodes on the current node and itself.
Select all properties of the current node.
Select the child node of the current node.
Select all the nodes below of the current node.
Select all the nodes under the current node and itself.
Select all nodes after the closing tag of the current node.
Select all horizontal nodes after the closing tag of the current node.
Select all namespaces of the current node.
Select all parent nodes of the current node.
Select all components before starting the current node's open tag.
Select all peer nodes before starting the open tag of the current node.
Select the current node.
- Show all parent tags that contain div tags id = <"identifier-shown">, not including the div tag id = <"identifer-shown"> checked from the Login Gmail page.
- If only want to display the specified parent tag.
Displays the parent tags and the div tags id = <"identifier-shown">, including the div id = "<identifier-shown>" tags checked from the Login Gmail page.
Select all the current attributes of the Next button on the Login Gmail page.
Select all child tags of div class = "input-wrapper focused" tags.
Select all child and grandchildren tags of id = "input-wrapper focused" div, not including the id = "input-wrapper focused div" tags.
Select all child and grandchildren tags of id = "input-wrapper focused" div, including id = "input-wrapper focused" div tags.
- Show all tags after the closing tag of class = "identifier-wrapper div".
- Display 1 card after the closing tag of class class = "identifier-wrapper div".
Display sibling tags after the closing tag of div class = "input-wrapper focused" tags.
Select all parent tags of div class = "input-wrapper focused" tags.
Select all tags before input id = "next", except for ancestors and attributes.
Vd11: contains ()
Select all elements containing text as "Create".
Context: Log in to http://www.chatwork.com/ successfully.
Step 1. Create a new Project.
- i. Click File -> New Profile .
- ii. Enter Name and select Type – Directory, Format – HTML.
Step 2. Create Interface.
- i. Right-click and select Project folder and select Test Suite.
ii. Name "Interface".
iii. Right-click and choose Interface -> New Resource folder.
iv. Right click on Interface resource -> New Scalar .
Step 3. Create New Action.
- i. Right-click and choose Project Name -> New Suite .
- ii. Create a new "Action" suite.
iii. Similar to Interface, create New Source for Action by right clicking on "Action".
iv. Add a New User Keyword.
v. Add Selenium2Library for each action.
vi. Import Interface of the corresponding page by clicking Resource and pointing to the folder containing Interface.
vii. Create test steps:
Step 4. Create Testsuite.
- i. Right-click and choose the project folder, select "New Suite". Create Test Suite with txt File.
ii. Add Library and Resource.
Step 5. Create a Testcase.
- i. Right-click on the newly created testsuite, select "New Test Case". Then fill in the name Test case.
- ii. Write scripts for testcase.
Step 6. Execute testsuite.
Step 7. Check the results.