|
| 1 | +===================================================== |
1 | 2 | Web testing with Robot Framework and Selenium2Library
|
2 | 3 | =====================================================
|
3 | 4 |
|
4 |
| -`Robot Framework`__ is a generic open source test automation framework and |
5 |
| -`Selenium2Library`__ is one of the many test libraries that can be used with |
| 5 | +`Robot Framework`_ is a generic open source test automation framework and |
| 6 | +Selenium2Library_ is one of the many test libraries that can be used with |
6 | 7 | it. In addition to showing how they can be used together for web testing,
|
7 | 8 | this demo introduces the basic Robot Framework test data syntax, how tests
|
8 | 9 | are executed, and how logs and reports look like.
|
9 | 10 |
|
10 |
| -See `project wiki`__ for more information about running the demo, viewing |
11 |
| -results, etc. You can also view the tests and generated results through the |
12 |
| -wiki without running the demo yourself. |
| 11 | +.. contents:: **Contents:** |
| 12 | + :depth: 1 |
| 13 | + :local: |
| 14 | + |
| 15 | +Downloading demo package |
| 16 | +======================== |
| 17 | + |
| 18 | +To get the demo, you can either download and extract the latest |
| 19 | +``WebDemo-<date>.zip`` package from the `download page`_ or checkout the |
| 20 | +`source code`_ directly. As a result you get ``WebDemo`` directory with |
| 21 | +``demoapp`` and ``login_tests`` sub directories. |
| 22 | + |
| 23 | +Example `test cases`_ and `generated results`_ are available also online. |
| 24 | +There is thus no need to get the demo if are not interested in `running it`__ |
| 25 | +yourself. |
| 26 | + |
| 27 | +__ `running demo`_ |
| 28 | + |
| 29 | +Demo application |
| 30 | +================ |
| 31 | + |
| 32 | +The demo application is a very simple login page shown below. With |
| 33 | +user name ``demo`` and password ``mode`` you get into a welcome page, and |
| 34 | +otherwise you end up to an error page. How to start and stop the |
| 35 | +application yourself is explained in the `Starting demo application`_ |
| 36 | +section. |
| 37 | + |
| 38 | +.. figure:: demoapp.png |
| 39 | + |
| 40 | +Test cases |
| 41 | +========== |
| 42 | + |
| 43 | +Test case files as well as a resource file used by them are located in |
| 44 | +the ``login_test`` directory. Click file names below to see the latest versions |
| 45 | +online. |
| 46 | + |
| 47 | +`valid_login.robot`_ |
| 48 | + A test suite with a single test for valid login. |
| 49 | + |
| 50 | + This test has a workflow that is created using keywords in |
| 51 | + the imported resource file. |
| 52 | + |
| 53 | +`invalid_login.robot`_ |
| 54 | + A test suite containing tests related to invalid login. |
| 55 | + |
| 56 | + These tests are data-driven by their nature. They use a single |
| 57 | + keyword, specified with the ``Test Template`` setting, that is called |
| 58 | + with different arguments to cover different scenarios. |
| 59 | + |
| 60 | + This suite also demonstrates using setups and teardowns in |
| 61 | + different levels. |
| 62 | + |
| 63 | +`gherkin_login.robot`_ |
| 64 | + A test suite with a single Gherkin style test. |
| 65 | + |
| 66 | + This test is functionally identical to the example in the |
| 67 | + `valid_login.robot`_ file. |
| 68 | + |
| 69 | +`resource.robot`_ |
| 70 | + A resource file with reusable keywords and variables. |
| 71 | + |
| 72 | + The system specific keywords created here form our own |
| 73 | + domain specific language. They utilize keywords provided |
| 74 | + by the imported Selenium2Library_. |
| 75 | + |
| 76 | +See `Robot Framework User Guide`_ for more details about the test data syntax. |
| 77 | + |
| 78 | +Generated results |
| 79 | +================= |
| 80 | + |
| 81 | +After `running tests`_ you will get report and log in HTML format. Example |
| 82 | +files are also visible online in case you are not interested in running |
| 83 | +the demo yourself: |
| 84 | + |
| 85 | +- `report.html`_ |
| 86 | +- `log.html`_ |
| 87 | + |
| 88 | +Running demo |
| 89 | +============ |
| 90 | + |
| 91 | +Preconditions |
| 92 | +------------- |
| 93 | + |
| 94 | +A precondition for running the tests is having `Robot Framework`_ and |
| 95 | +Selenium2Library_ installed, and they in turn require |
| 96 | +Python_. Robot Framework `installation instructions`__ cover both |
| 97 | +Robot and Python installations, and Selenium2Library has its own |
| 98 | +`installation instructions`__. |
| 99 | + |
| 100 | +In practice it is easiest to install Robot Framework and |
| 101 | +Selenium2Library along with its dependencies using `pip`_ package |
| 102 | +manager. Once you have pip installed, all you need to do is running |
| 103 | +these commands:: |
| 104 | + |
| 105 | + pip install robotframework |
| 106 | + pip install robotframework-selenium2library |
| 107 | + |
| 108 | +__ https://github.com/robotframework/robotframework/blob/master/INSTALL.rst |
| 109 | +__ https://github.com/robotframework/Selenium2Library/blob/master/INSTALL.rst |
| 110 | + |
| 111 | +Starting demo application |
| 112 | +------------------------- |
| 113 | + |
| 114 | +Running tests requires the `demo application`_ located under ``demoapp`` |
| 115 | +directory to be running. It can be started either by double clicking |
| 116 | +``demoapp/server.py`` file in a file manager or by executing it from the |
| 117 | +command line:: |
| 118 | + |
| 119 | + python demoapp/server.py |
| 120 | + |
| 121 | +After the demo application is started, it is be available in URL |
| 122 | +http://localhost:7272. You can test it manually, valid credentials are |
| 123 | +``demo/mode``, and it needs to be running while executing the automated |
| 124 | +tests. |
| 125 | + |
| 126 | +If the application was started by double-clicking ``demoapp/server.py`` |
| 127 | +file, it can be shut down by closing the opened window. If it was |
| 128 | +executed from the command line, using ``Ctrl-C`` is enough. |
| 129 | + |
| 130 | +Running tests |
| 131 | +------------- |
| 132 | + |
| 133 | +The `test cases`_ are located in the ``login_tests`` directory. They can be |
| 134 | +executed using the ``robot`` command:: |
| 135 | + |
| 136 | + robot login_tests |
| 137 | + |
| 138 | +.. note:: If you are using Robot Framework 2.9 or earlier, you need to |
| 139 | + use the ``pybot`` command instead. |
| 140 | + |
| 141 | +You can also run an individual test case file and use various command line |
| 142 | +options supported by Robot Framework:: |
| 143 | + |
| 144 | + robot login_tests/valid_login.robot |
| 145 | + robot --test InvalidUserName --loglevel DEBUG login_tests |
| 146 | + |
| 147 | +Run ``robot --help`` for more information about the command line usage and see |
| 148 | +`Robot Framework User Guide`_ for more details about test execution in general. |
| 149 | + |
| 150 | +Using different browsers |
| 151 | +------------------------ |
| 152 | + |
| 153 | +The browser that is used is controlled by ``${BROWSER}`` variable defined in |
| 154 | +`resource.robot`_ resource file. Firefox browser is used by default, but that |
| 155 | +can be easily overridden from the command line:: |
| 156 | + |
| 157 | + robot --variable BROWSER:Chrome login_tests |
| 158 | + robot --variable BROWSER:IE login_tests |
| 159 | + |
| 160 | +Consult Selenium2Library_ documentation about supported browsers. Notice also |
| 161 | +that other browsers than Firefox require separate browser drivers to be |
| 162 | +installed before they can be used with Selenium and Selenium2Library. |
13 | 163 |
|
14 |
| -__ http://robotframework.org |
15 |
| -__ https://github.com/robotframework/Selenium2Library |
16 |
| -__ https://bitbucket.org/robotframework/webdemo/wiki/Home |
| 164 | +.. _Robot Framework: http://robotframework.org |
| 165 | +.. _Selenium2Library: https://github.com/robotframework/Selenium2Library |
| 166 | +.. _Python: http://python.org |
| 167 | +.. _pip: http://pip-installer.org |
| 168 | +.. _download page: https://bitbucket.org/robotframework/webdemo/downloads |
| 169 | +.. _source code: https://bitbucket.org/robotframework/webdemo/src |
| 170 | +.. _valid_login.robot: https://bitbucket.org/robotframework/webdemo/src/master/login_tests/valid_login.robot |
| 171 | +.. _invalid_login.robot: https://bitbucket.org/robotframework/webdemo/src/master/login_tests/invalid_login.robot |
| 172 | +.. _gherkin_login.robot: https://bitbucket.org/robotframework/webdemo/src/master/login_tests/gherkin_login.robot |
| 173 | +.. _resource.robot: https://bitbucket.org/robotframework/webdemo/src/master/login_tests/resource.robot |
| 174 | +.. _report.html: http://robotframework.bitbucket.org/WebDemo/report.html |
| 175 | +.. _log.html: http://robotframework.bitbucket.org/WebDemo/log.html |
| 176 | +.. _Robot Framework User Guide: http://robotframework.org/robotframework/#user-guide |
0 commit comments