My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Demo  
Simple Robot Framework and SeleniumLibrary demo
Featured
Updated Jan 31, 2011 by pekka.klarck

Introduction

Robot Framework is a generic test automation framework and SeleniumLibrary is one of the many test libraries that can be used with it. In addition to showing how the SeleniumLibrary works, this demo introduces the basic Robot Framework test data syntax, how tests are executed, and how logs and reports look like.

The SeleniumLibrary architecture gives an high level overview of the different components.

Preconditions

To be able to execute the demo, both Robot Framework and SeleniumLibrary need to be installed. Notice that in addition to Python required by Robot Framework, you need to have Java 1.5 or newer to run Selenium Server.

If you do not have time or interest to install everything, you can still take a look at the test cases and generated logs and reports online.

Downloading and executing the demo

The demo is available on the download page. Latest version is robotframework-seleniumlibrary-demo-20110131.zip. It requires Robot Framework 2.5 and running the included Flex demo requires SeleniumLibrary 2.6. The earlier robotframework-seleniumlibrary-demo-20100428.zip works also with Robot Framework 2.1.x versions.

After downloading and unzipping the package, you should have all the files in a directory robotframework-seleniumlibrary-demo. The rundemo.py script is used for executing tests, demoapp directory contains two versions of the system under test, and actual test cases are in the login_tests directory.

To run the test cases execute the following command in the extracted directory:

    python rundemo.py login_tests

This should work in most environments if you have Firefox installed. See chapter executing tests for more information about running the tests with different browsers.

Systems under test

The system under test in the demo is a very simple application that only has login functionality. There are two versions of this application, one implemented as HTML pages and the other an Adobe Flex application. Both of these should run without special preconditions, but see these instructions if you want to test your own Flex application.

The different versions of the application are shown in the below screenshots. The correct user name and password combination to both applications is demo/mode and using them will show you a welcome page. Otherwise an error page or dialog is shown.

The demo applications are normally started and stopped automatically by the rundemo.py script when tests are executed. The same script can also be used to start and stop the applications so that those can be investigated manually:

    python rundemo.py demoapp start
    python rundemo.py demoapp stop

After starting the demo application, the HTML version can be accessed from URL http://localhost:7272/html and the Flex version from http://localhost:7272/flex.

The application source codes are located in the demoapp/html and demoapp/flex directories inside the extracted zip file.

Selenium Server

Running tests using the SeleniumLibrary requires Selenium Server to be running. A version of the server is bundled with the library, and starting and stopping it is handled by the rundemo.py script automatically when it is used for executing tests. It is possible to also start/stop the server separately:

    python rundemo.py selenium start
    python rundemo.py selenium stop

Test cases

The test cases distributed with the demo are in the login_tests directory and visible also online. They are in plain text format (Robot Framework support also HTML and TSV formats), and can be edited using any text editor. There exists also a special Robot Framework test data editor RIDE.

The simplest test case file is valid_login.txt, which contains only one test case Valid Login. This test case has a simple workflow, created using keywords, that starts from opening the browser and ends with verifying that the welcome page has been opened.

The other test case file, invalid_login.txt, has several test cases that verify different invalid login scenarios such as invalid or empty user name. These tests are data-driven in their nature and each of them only has one keyword that encapsulates the needed workflow.

Both of these test case files use domain specific high-level keywords, such as Open Browser To Login Page. These keywords use lower level keywords internally, such as Title Should Be and Open Browser. In this demo the higher level keywords are created in technology specific resource files html_resource.txt and flex_resource.txt. In addition, there is a common resource file common_resource.txt, which defines some variables, for example to determine which version of the application to test against. The lowest level keywords always come from test libraries, in this case from the SeleniumLibrary that provides generic keywords for web testing.

Executing test cases

Using rundemo.py

The easiest way to run the test cases is using the already mentioned rundemo.py script, which automatically starts and stops both the system under test and the Selenium Server. Tests are executed by giving a path to tests to run as an argument to rundemo.py. It is possible to run either a single test case file by giving a path to that file, or all test case files in a directory by giving a path to the directory:

    python rundemo.py login_tests/valid_login.txt
    python rundemo.py login_tests

When tests are executed, rundemo.py passes arguments it gets directly to the pybot command that is normally used for running Robot Framework test cases. The pybot command supports various command line options (run pybot --help for a full list), and when they are needed they must be given before the test data path as in these examples:

    python rundemo.py --name New_name login_tests/
    python rundemo.py --outputdir results --loglevel DEBUG login_tests/

Using different browsers

By default tests are executed using the Firefox browser. The browser to use is defined as a ${BROWSER} variable in the common_resource.txt file, and it can be easily overridden from the command line:

    python rundemo.py --variable BROWSER:IE login_tests/
    python rundemo.py --variable BROWSER:GoogleChrome login_tests/

What browsers are supported and how to use them is explained in the documentation of the Open Browser keyword.

Selecting application to test

By default, the test cases are run against the HTML version of the test application. This can be changed by overriding ${SUT} variable from the command line:

    python rundemo.py --variable SUT:flex login_tests/

Slowing down executing speed

Typically the tests run so fast (except for opening the browser) that it is impossible to see what is happening. The execution speed can be slowed down by overriding the ${DELAY} variable:

    python rundemo.py --variable DELAY:0.5 login_tests/

Running tests using pybot

It is possible to run the tests also using the normal pybot start-up script, but that requires that the demo application and the Selenium Server are started before. This might be a good idea if starting the demo application and Selenium Server takes a lot of time and you want to run tests multiple times.

This example shows a possible workflow:

    python rundemo.py selenium start
    python rundemo.py demoapp start
    pybot --variable BROWSER:Firefox --outputdir firefox login_tests
    pybot --variable BROWSER:IE --outputdir ie login_tests
    python rundemo.py demoapp stop
    python rundemo.py selenium stop

Viewing logs and reports

After tests have been executed, Robot Framework creates a detailed log file listing all the executed keywords with their possible log messages. Another important output is the test report that has a higher level summary of the test execution. By default these files are created into the directory where tests are executed from, and exact locations are shown on the console after the execution.

Example outputs generated when these tests are run are available online:

Where to find more information

Robot Framework documentation is available on the project pages at http://robotframework.org. If you are new to the framework you may want to start from the introduction slides and then look at the Quick Start Guide, which also acts as another executable demo. All the Robot Framework features are documented in the comprehensive User Guide.

More information about the SeleniumLibrary is available here in the library's wiki. Most importantly the library documentation documents all the available keywords.

Comment by hqh...@gmail.com, Apr 9, 2009

I get the following error:

C:\Python25\Lib\site-packages>python rundemo.py login_tests Traceback (most recent call last):

File "rundemo.py", line 35, in <module>
from Selenium import selenium
ImportError?: No module named Selenium

C:\Python25\Lib\site-packages>

Comment by project member pekka.klarck, Apr 30, 2009

hqhash, are you sure you have installed SeleniumLibrary?? Did you get any errors while doing it?

Comment by icoci...@gmail.com, Jul 21, 2009

I get the following error:

C:\Python26\Lib\site-packages\SeleniumLibrary?\robotframework-seleniumlibrary-dem o>python rundemo.py login_tests Traceback (most recent call last):

File "rundemo.py", line 34, in <module>
import SeleniumLibrary?
File "C:\python26\lib\site-packages\SeleniumLibrary?\init.py", line 27, in
<module>
from robot.errors import DataError?
ImportError?: No module named robot.errors

Comment by project member pekka.klarck, Jul 22, 2009

icocitto, it seems that you don't have Robot Framework itself installed or the installation has failed somehow. You can find installation instructions from http://robotframework.org

Comment by icoci...@gmail.com, Jul 22, 2009

you are right !! i forget to install roboframework. thank!

Comment by icoci...@gmail.com, Jul 23, 2009

Installed roboframework....I get the following error:

C:\Python26\Lib\site-packages\SeleniumLibrary?\robotframework-seleniumlibrary-dem o>python rundemo.py login_tests 'pybot' is not recognized as an internal or external command, operable program or batch file.

Comment by project member pekka.klarck, Jul 23, 2009

icocitto, did you set PATH on Windows so that you can execute 'pybot' from the command line? You should be able to run, for example, 'pybot --version'. You can find detailed installation instructions from the User Guide: http://code.google.com/p/robotframework/wiki/UserGuide

Comment by icoci...@gmail.com, Jul 23, 2009

Thanks a lot !!!! pekka.klarck ....I set up the PATH <directory Python 2.6>\Scripts\ and RESTART my windows, and works perfectly.

Comment by palani.s...@gmail.com, Feb 23, 2010

Guys,

Thanks for the good work. In automation, testcases and reporting are equally important. Still I'm exploring it...

- Palani.

Comment by alexander.vanderberg, Jun 21, 2010

If you get the error message:

Traceback (most recent call last):

File "rundemo.py", line 86, in <module>
run_tests(sys.argv[1:])
File "rundemo.py", line 49, in run_tests
call(['pybot'] + args, shell=(os.sep == '\\'))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 480, in call
return Popen(popenargs, kwargs).wait()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 633, in init
errread, errwrite)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1139, in execute_child
raise child_exception
OSError: 2? No such file or directory

Then you have to write: pybot-2.6 rundemo.py login_tests instead of: python rundemo.py login_tests

Comment by project member pekka.klarck, Jun 21, 2010

alexander.vanderberg, do you mean python-2.6. Did this happen on OSX?

Comment by alexander.vanderberg, Jun 25, 2010

pekka: yes, it was on Mac OSX Snow Leopard.

python2.6 rundemo.py login_tests shows the error message above,

pybot-2.6 rundemo.py login_tests works fine.

Comment by project member pekka.klarck, Jun 28, 2010

alexander.vanderberg, pybot is the start-up script that runs Robot Framework on Python. I'm confused by pybot-2.6 because no such script is distributed with the framework. Anyway, great that you got the demo working somehow.

Comment by santu....@gmail.com, Oct 22, 2010

i downloaded and installed all .. now i have one doubt .. where i need to run-------- python rundemo.py login_tests ? this command in dos or python..

Comment by project member pekka.klarck, Oct 22, 2010

@santu.qtp: Yes, run python rundemo.py login_tests in the command prompt on the directory that you extracted.

Comment by swetha.v...@gmail.com, Nov 12, 2010

getting error as "error? Timed out after 80000ms" when giving click and wait command.

Comment by pspra...@gmail.com, Dec 29, 2010

pls answer this qs .. i need sm update for tom's stand up meeting

Comment by zhangjia...@gmail.com, Sep 2, 2011

When I am running the command : "python rundemo.py login_tests"

I get the following error msg:

Importing SeleniumLibrary? module failed. Please make sure you have SeleniumLibrary? installed.

The Selenium is successfully installed at "D:\Python27\Lib\site-packages\SeleniumLibrary?".

Do you have any suggestion on this ? I am sure SeleniumLibrary? is installed but I think currently it needs some configuration with python lib path ??? to let the python know where to find the location of the SeleniumLibrary?.

Please help me with this.

Comment by paru...@gmail.com, Sep 22, 2011

Iam getting this error.

'pybot' is not recognized as internal or external command, Operable program or batch file.

Comment by xul...@gmail.com, Sep 28, 2011

try pybot.bat and ensure PythonPATH\Scripts has been added to PATH environment.

Comment by k.khande...@gmail.com, Dec 5, 2011

Query related to Logs and Reports - 1. By default these files are created into the directory where tests are executed from. How can I change the directory path to get reports on specified location. ?

2. Can I save my reports for each run at some new location or with some timestamp?

Thanks in advance.

Comment by knuf.re...@gmail.com, Mar 2, 2012

I've just downloaded robotframework-seleniumlibrary-2.8.1 onto my laptop running Ubuntu 10.04 and made my first steps by executing the demo. Everything works. Wonderful! Thank you to all.

Comment by bharathk...@gmail.com, Apr 4, 2012

Hi,

I am new to robot framework and I need some help with Selenium Library. I have installed selenium library in path C:\Python27\Lib\site-packages\SeleniumLibrary? using windows installer and trying to run the demo app. My demo app is extracted in location C:\RobotFramework?\robotframework-seleniumlibrary-demo-20110131\robotframework-seleniumlibrary-demo.

When I try to start selenium server, I am getting below error message

C:\RobotFramework?\robotframework-seleniumlibrary-demo-20110131\robotframework-se leniumlibrary-demo>python rundemo.py selenium start Traceback (most recent call last):

File "rundemo.py", line 89, in <module>
action()
File "rundemo.py", line 66, in start_selenium_server
SeleniumLibrary?.start_selenium_server(logfile)
File "C:\Python27\lib\site-packages\SeleniumLibrary?\init.py", line 78, in
start_selenium_server
subprocess.Popen(cmd, stdout=logfile, stderr=subprocess.STDOUT)
File "C:\Python27\lib\subprocess.py", line 679, in init
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 893, in execute_child
startupinfo)
WindowsError?: 2? The system cannot find the file specified

Not able to figure out what is wrong.Please help

Bharath

Comment by bharathk...@gmail.com, Apr 4, 2012

Never mind, fixed the issue with installation of JRE

Comment by mallik9...@gmail.com, Apr 19, 2012

hi i have installed robot framework and selinium libraries on windows. but i did nt get how to write a sample testcase even after seeing the examples.can u be more specific that how to write a test case basing one scenario.

thanks in advance

Comment by mallik9...@gmail.com, Apr 19, 2012

and if iam running the sample file .. iam getting the follwing error on my command prompt as

D:\softwares\robot framework>dir

Volume in drive D has no label. Volume Serial Number is D6CD-EAEB

Directory of D:\softwares\robot framework

04/19/2012 03:55 PM <DIR> . 04/19/2012 03:55 PM <DIR> .. 04/18/2012 12:46 PM 3,064,610 curl-7.25.0.tar.gz 04/19/2012 01:16 PM <DIR> LoginTest? 04/19/2012 01:16 PM 1,498 LoginTest?.zip 04/19/2012 10:48 AM 69 New Text Document.txt 03/29/2012 02:39 PM 15,970,304 python-2.7.2.msi 04/18/2012 03:26 PM 15,923,120 robotframework-2.7.1.jar 04/19/2012 10:24 AM 716,377 robotframework-2.7.1.win32.exe 04/19/2012 01:12 PM 26,583,129 robotframework-seleniumlibrary-2.8.1.win3 2.exe 04/19/2012 11:22 AM <DIR> robotframework-userguide-2.7.1 03/27/2012 02:47 PM 1,381,744 robotframework-userguide-2.7.1.zip 04/19/2012 03:54 PM 398 simple.txt

9 File(s) 63,641,249 bytes 4 Dir(s) 12,716,953,600 bytes free

D:\softwares\robot framework>java -jar robotframework-2.7.1.jar simple.txt ERROR Error in file 'D:\softwares\robot framework\simple.txt' in table 'Sett ings': Importing test library 'SeleniumLibrary?' failed: ImportError?: No module n amed SeleniumLibrary? Traceback (most recent call last):

None
PYTHONPATH:
D:\softwares\robot framework\robotframework-2.7.1.jar\Lib\robot\libraries D:\softwares\robot framework\robotframework-2.7.1.jar\Lib D:\softwares\robot framework\Lib classpath pyclasspath/ . D:\softwares\robot framework
CLASSPATH:
robotframework-2.7.1.jar

Simple

Login Should Succeed When the Correct Username and Password are En... | FAIL | No keyword with name 'Start Selenium Server' found.


Simple | FAIL | 1 critical test, 0 passed, 1 failed 1 test total, 0 passed, 1 failed

Comment by mallik9...@gmail.com, Apr 19, 2012

hi , this is the first problem i am facing

C:\Python27>pybot myfristtext.txt 'pybot' is not recognized as an internal or external command, operable program or batch file.

Comment by mallik9...@gmail.com, Apr 19, 2012

and the second problem is

C:\Python27>java -jar robotframework-2.7.1.jar myfristtext.txt Exception in thread "main" Traceback (most recent call last):

File "<string>", line 1, in <module> File "C:\Python27\robotframework-2.7.1.jar\Lib\robot\init$py.class", line
18, in <module>
File "C:\Python27\robotframework-2.7.1.jar\Lib\robot\pythonpathsetter$py.class
", line 17, in <module>
File "C:\Python27\Lib\os.py", line 754
bs = b""
^
SyntaxError?: no viable alternative at input '""'

Comment by su...@ensarm.com, Apr 23, 2012

nice


Sign in to add a comment
Powered by Google Project Hosting