Robot Framework scripts are relatively easy. In this video, see the process.
- [Instructor] Okay, so now that we've got Robot Framework installed and configured, it's time to create our first script. So, the agenda for this unit is that we'll do an overview, we'll talk about organizing project files, we'll talk about the sections of a script file, then we'll choose a library and write some steps, and finally we'll run the script and examine the excellent Robot Framework results file. So when you're creating scripts, you're going to use some kind of an editor. In this course, we're going to be using the Pycharm IDE, but if you're more comfortable using something like Sublime Text or Brackets or Eclipse, you're more than welcome to do so.
Some people choose to go with the hardcore text route using Emacs, Vim, or Notepad++. And I'd like to mention there's also a Robot Framework specific IDE called RIDE and you can go ahead and Google that, but I've heard mixed reviews about how effective that is, and the resulting files are HTML files which may not work with source code version-control systems like Git as well as plain text might. The script formats available to you are Tab Separated Values, which is basically a plain text file, HTML, like I said that's specific to the RIDE editor that was created along with Robot Framework, and you've also got a Pipe delimited format as well.
For this course, we'll be using the TSV files. Robot Framework scripts are mostly keyword driven and what that means is we can type in some simple, plain English words to invoke pre-written logic in some pre-existing libraries, that has been made available to us. This gives us the ability to create our scripts in a Natural Language, essentially Business Domain vernacular, and the end result is simpler, more readable test scripts. Here's a diagram that makes it easier to visualize this. Inside of our chosen IDE, we will create a Script file, which is simply a text file with a dot robot extension.
And at the top of that script file, we will attach one or more of these libraries, which like I said will do the heavy lifting for us. Each of these libraries has documentation that exposes various keywords that you can use to get work done. Now, this right here is an overly simple example. We typically won't actually include the libraries in our script file. What we will usually do looks more like this. We'll create script files which are .robot and those script files will reference workflow files which are lower level keywords, also text.robot files and those workflows themselves would be making calls to the various libraries.
So, you can see the libraries we have access to include Built-In libraries that come with Robot Framework itself and also external libraries which can be installed by using pip install and then the name of the library. So, in Built-In we have things like the operating system for creating folders and files, process for launching and interacting with applications. We've got dialogues and collections and strings and date times and even a screenshot library to capture what's happening on the screen. There are many external libraries, I'm only showin' a few here. Selenium2 for web browser testing, Appium for native mobile application testing, FTP is of course useful, SSH.
There's a database library for doing database testing. Diff, for comparing files, Swing, for testing Java, Swing gooey applications and an archive library for testing zip files and other types of archives. So, going back to our most simple example. We could have a script.robot file talking to some library commands. This is what that would look like. You can see inside my project here which is in my base directory of C development robot scripts. I've got a project in a directory called demo and inside there I've got a script called amazon.robot and there's really nothing else in my project.
In my script you can see I've pulled in the Selenium2 library and down here I've created a test case which makes use of Selenium2 library keywords. Each of these lines begins with a Selenium2 library keyword. So, that's what a Robot Framework script looks like in its purest, simplest form. Like I said before, this is a blatantly simple example and in future videos we're going to be refactoring this so it's more readable, more modular and more object oriented. When you want to explore what's available in these libraries simply visit the RobotFramework.org website, click on test libraries and here you see we have a listing of the standard libraries, if you click on external, you see the external libraries.
And when you click on any one of these links, there's going to be some reference to the keyword documentation which often takes you to an excellent documentation page. So, in this scripting example, we're going to start off very, very simple. We're going to create a script.robot file which is going to talk to the Selenium2 library which in turn is going to invoke Selenium Webdriver to drive some browsers. In future videos I'll show you how to organize and create scripts in a more realistic fashion which would include a script file which talks to various keyword files which then interacts with page objects.
The page objects will then talk to libraries and that library would interact with a system under test. But for now, we're going to start simple.
- What's a test automation framework?
- Robot Framework vs. Selenium
- Creating and running your first script
- Options for running scripts, including PyCharm and Jenkins
- Making a script more readable
- Using variables to centralize data
- Incorporating the Page Object Model
- Robot Framework libraries