1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
%global _empty_manifest_terminate_build 0
Name: python-robotframework-pageobjectlibrary
Version: 1.1
Release: 1
Summary: RobotFramework library that implements the Page Object pattern
License: Apache License 2.0
URL: https://github.com/boakley/robotframework-pageobjectlibrary/
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/95/f3/d3576764b4fc9fd75cdd472aa90815aa549fac55400a7974fc739ae01a66/robotframework-pageobjectlibrary-1.1.tar.gz
BuildArch: noarch
Requires: python3-robotframework
Requires: python3-robotframework-seleniumlibrary
Requires: python3-selenium
Requires: python3-six
%description
# PageObjectLibrary
## Overview
PageObjectLibrary is a lightweight [Robot Framework] keyword library that makes it possible to use the Page Object pattern when testing web pages with the keyword based approach of robot framework.
## Installing
```bash
pip install --upgrade robotframework-pageobjectlibrary
```
## Source Code
The source code is hosted on GitHub at the following url:
* https://github.com/boakley/robotframework-pageobjectlibrary.git
## Running the Demo
In the GitHub repository is a small demonstration suite that includes a self-contained webserver and web site.
For the demo to run, you must have [robotframework](https://pypi.org/project/robotframework/) 2.9+ and [robotframework-seleniumlibrary](https://pypi.org/project/robotframework-seleniumlibrary/) installed. You must also have cloned the GitHub repository to have access to the demo files.
To run the demo, clone the GitHub repository, cd to the folder that contains this file, and then run the following command: :
```bash
robot -d demo/results demo
```
### A Simple Tutorial
For a simple tutorial, see <https://github.com/boakley/robotframework-pageobjectlibrary/wiki/Tutorial>
## How it Works
The Page Object library is quite simple. Page Object classes are implemented as standard robot keyword libraries, and relies on robot frameworks built-in [Set library search order keyword].
The core concept is that when you use PageObjectLibrary keywords to go to a page or assert you are on a specific page, the keyword will automatically load the library for that page and put it at the front of the library search order, guaranteeing that the Page Object keywords are available to your test case.
## Why Page Objects Makes Writing Tests Easier
The purpose of the Page Object pattern is to encapsulate the knowledge of how a web page is constructed into an object. Your test uses the object as an interface to the application, isolating your test cases from the details of the implementation of a page.
With Page Objects, developers are free to modify web pages as much as they want, and the only thing they need to do to keep existing tests from failing is to update the Page Object class. Because test cases arenât directly tied to the implementation, they become more stable and more resistant to change as the website matures.
## A Typical Test _Without_ Page Objects
With traditional testing using Selenium, a simple login test might look something like the following: (using the pipe-separated format for clarity):
```robotframework
*** Test Cases ***
| Login with valid credentials
| | Go to | ${ROOT}/Login.html
| | Wait for page to contain | id=id_username
| | Input text | id=id_username | ${USERNAME}
| | Input text | id=id_password | ${PASSWORD}
| | Click button | id=id_form_submit
| | Wait for page to contain | Your Dashboard
| | Location should be | ${ROOT}/dashboard.html
```
Notice how this test is tightly coupled to the implementation of the page. It has to know that the input field has an id of `id_username`, and the password field has an id of `id_password`. It also has to know the URL of the page being tested.
Of course, you can put those hard-coded values into variables and import them from a resource file or environment variables, which makes it easier to update tests when locators change. However, thereâs still the overhead of additional keywords that are often required to make a test robust, such as waiting for a page to be reloaded. The provided PageObject superclass handles some of those details for you.
## The Same Test, Using Page Objects
Using Page Objects, the same test could be written like this:
```robotframework
*** Test Cases ***
| Login with valid credentials
| | Go to page | LoginPage
| | Login as a normal user
| | The current page should be | DashboardPage
```
Notice how there are no URLs or element locators in the test whatsoever, and that weâve been able to eliminate some keywords that typically are necessary for selenium to work but which arenât part of the test logic *per se*. What we end up with is test case that is nearly indistinguishable from typical acceptance criteria of an agile story.
## Writing a Page Object class
Page Objects are simple python classes that inherit from `PageObjectLibrary.PageObject`. There are only a couple of requirements for the class:
- The class should define a variable named `PAGE_TITLE`
- The class should define a variable named `PAGE_URL` which is a URI relative to the site root.
By inheriting from `PageObjectLibrary.PageObject`, methods have access to the following special object attributes:
- `self.selib` - a reference to an instance of SeleniumLibrary. With this you can call any of the SeleniumLibrary keywords via their python method names (eg: self.selib.input\_text)
- `self.browser` - a reference to the webdriver object created when a browser was opened by SeleniumLibrary. With this you can bypass SeleniumLibrary and directly call all of the functions provided by the core selenium library.
- `self.locator` - a wrapper around the `_locators` dictionary of the page. This dictionary can contain all of the locators used by the Page Object keywords. `self.locators` adds the ability to access the locators with dot notation rather than the slightly more verbose dictionary syntax (eg: `self.locator.username` vs `self._locators["username"]`.
## An example Page Object
A Page Object representing a login page might look like this:
```python
from PageObjectLibrary import PageObject
class LoginPage(PageObject):
PAGE_TITLE = "Login - PageObjectLibrary Demo"
PAGE_URL = "/login.html"
_locators = {
"username": "id=id_username",
"password": "id=id_password",
"submit_button": "id=id_submit",
}
def enter_username(self, username):
"""Enter the given string into the username field"""
self.selib.input_text(self.locator.username, username)
def enter_password(self,password):
"""Enter the given string into the password field"""
self.selib.input_text(self.locator.password, password)
def click_the_submit_button(self):
"""Click the submit button, and wait for the page to reload"""
with self._wait_for_page_refresh():
self.selib.click_button(self.locator.submit_button)
```
[robot framework]: http://www.robotframework.org
[Set library search order keyword]: http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Library%20Search%20Order
%package -n python3-robotframework-pageobjectlibrary
Summary: RobotFramework library that implements the Page Object pattern
Provides: python-robotframework-pageobjectlibrary
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-robotframework-pageobjectlibrary
# PageObjectLibrary
## Overview
PageObjectLibrary is a lightweight [Robot Framework] keyword library that makes it possible to use the Page Object pattern when testing web pages with the keyword based approach of robot framework.
## Installing
```bash
pip install --upgrade robotframework-pageobjectlibrary
```
## Source Code
The source code is hosted on GitHub at the following url:
* https://github.com/boakley/robotframework-pageobjectlibrary.git
## Running the Demo
In the GitHub repository is a small demonstration suite that includes a self-contained webserver and web site.
For the demo to run, you must have [robotframework](https://pypi.org/project/robotframework/) 2.9+ and [robotframework-seleniumlibrary](https://pypi.org/project/robotframework-seleniumlibrary/) installed. You must also have cloned the GitHub repository to have access to the demo files.
To run the demo, clone the GitHub repository, cd to the folder that contains this file, and then run the following command: :
```bash
robot -d demo/results demo
```
### A Simple Tutorial
For a simple tutorial, see <https://github.com/boakley/robotframework-pageobjectlibrary/wiki/Tutorial>
## How it Works
The Page Object library is quite simple. Page Object classes are implemented as standard robot keyword libraries, and relies on robot frameworks built-in [Set library search order keyword].
The core concept is that when you use PageObjectLibrary keywords to go to a page or assert you are on a specific page, the keyword will automatically load the library for that page and put it at the front of the library search order, guaranteeing that the Page Object keywords are available to your test case.
## Why Page Objects Makes Writing Tests Easier
The purpose of the Page Object pattern is to encapsulate the knowledge of how a web page is constructed into an object. Your test uses the object as an interface to the application, isolating your test cases from the details of the implementation of a page.
With Page Objects, developers are free to modify web pages as much as they want, and the only thing they need to do to keep existing tests from failing is to update the Page Object class. Because test cases arenât directly tied to the implementation, they become more stable and more resistant to change as the website matures.
## A Typical Test _Without_ Page Objects
With traditional testing using Selenium, a simple login test might look something like the following: (using the pipe-separated format for clarity):
```robotframework
*** Test Cases ***
| Login with valid credentials
| | Go to | ${ROOT}/Login.html
| | Wait for page to contain | id=id_username
| | Input text | id=id_username | ${USERNAME}
| | Input text | id=id_password | ${PASSWORD}
| | Click button | id=id_form_submit
| | Wait for page to contain | Your Dashboard
| | Location should be | ${ROOT}/dashboard.html
```
Notice how this test is tightly coupled to the implementation of the page. It has to know that the input field has an id of `id_username`, and the password field has an id of `id_password`. It also has to know the URL of the page being tested.
Of course, you can put those hard-coded values into variables and import them from a resource file or environment variables, which makes it easier to update tests when locators change. However, thereâs still the overhead of additional keywords that are often required to make a test robust, such as waiting for a page to be reloaded. The provided PageObject superclass handles some of those details for you.
## The Same Test, Using Page Objects
Using Page Objects, the same test could be written like this:
```robotframework
*** Test Cases ***
| Login with valid credentials
| | Go to page | LoginPage
| | Login as a normal user
| | The current page should be | DashboardPage
```
Notice how there are no URLs or element locators in the test whatsoever, and that weâve been able to eliminate some keywords that typically are necessary for selenium to work but which arenât part of the test logic *per se*. What we end up with is test case that is nearly indistinguishable from typical acceptance criteria of an agile story.
## Writing a Page Object class
Page Objects are simple python classes that inherit from `PageObjectLibrary.PageObject`. There are only a couple of requirements for the class:
- The class should define a variable named `PAGE_TITLE`
- The class should define a variable named `PAGE_URL` which is a URI relative to the site root.
By inheriting from `PageObjectLibrary.PageObject`, methods have access to the following special object attributes:
- `self.selib` - a reference to an instance of SeleniumLibrary. With this you can call any of the SeleniumLibrary keywords via their python method names (eg: self.selib.input\_text)
- `self.browser` - a reference to the webdriver object created when a browser was opened by SeleniumLibrary. With this you can bypass SeleniumLibrary and directly call all of the functions provided by the core selenium library.
- `self.locator` - a wrapper around the `_locators` dictionary of the page. This dictionary can contain all of the locators used by the Page Object keywords. `self.locators` adds the ability to access the locators with dot notation rather than the slightly more verbose dictionary syntax (eg: `self.locator.username` vs `self._locators["username"]`.
## An example Page Object
A Page Object representing a login page might look like this:
```python
from PageObjectLibrary import PageObject
class LoginPage(PageObject):
PAGE_TITLE = "Login - PageObjectLibrary Demo"
PAGE_URL = "/login.html"
_locators = {
"username": "id=id_username",
"password": "id=id_password",
"submit_button": "id=id_submit",
}
def enter_username(self, username):
"""Enter the given string into the username field"""
self.selib.input_text(self.locator.username, username)
def enter_password(self,password):
"""Enter the given string into the password field"""
self.selib.input_text(self.locator.password, password)
def click_the_submit_button(self):
"""Click the submit button, and wait for the page to reload"""
with self._wait_for_page_refresh():
self.selib.click_button(self.locator.submit_button)
```
[robot framework]: http://www.robotframework.org
[Set library search order keyword]: http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Library%20Search%20Order
%package help
Summary: Development documents and examples for robotframework-pageobjectlibrary
Provides: python3-robotframework-pageobjectlibrary-doc
%description help
# PageObjectLibrary
## Overview
PageObjectLibrary is a lightweight [Robot Framework] keyword library that makes it possible to use the Page Object pattern when testing web pages with the keyword based approach of robot framework.
## Installing
```bash
pip install --upgrade robotframework-pageobjectlibrary
```
## Source Code
The source code is hosted on GitHub at the following url:
* https://github.com/boakley/robotframework-pageobjectlibrary.git
## Running the Demo
In the GitHub repository is a small demonstration suite that includes a self-contained webserver and web site.
For the demo to run, you must have [robotframework](https://pypi.org/project/robotframework/) 2.9+ and [robotframework-seleniumlibrary](https://pypi.org/project/robotframework-seleniumlibrary/) installed. You must also have cloned the GitHub repository to have access to the demo files.
To run the demo, clone the GitHub repository, cd to the folder that contains this file, and then run the following command: :
```bash
robot -d demo/results demo
```
### A Simple Tutorial
For a simple tutorial, see <https://github.com/boakley/robotframework-pageobjectlibrary/wiki/Tutorial>
## How it Works
The Page Object library is quite simple. Page Object classes are implemented as standard robot keyword libraries, and relies on robot frameworks built-in [Set library search order keyword].
The core concept is that when you use PageObjectLibrary keywords to go to a page or assert you are on a specific page, the keyword will automatically load the library for that page and put it at the front of the library search order, guaranteeing that the Page Object keywords are available to your test case.
## Why Page Objects Makes Writing Tests Easier
The purpose of the Page Object pattern is to encapsulate the knowledge of how a web page is constructed into an object. Your test uses the object as an interface to the application, isolating your test cases from the details of the implementation of a page.
With Page Objects, developers are free to modify web pages as much as they want, and the only thing they need to do to keep existing tests from failing is to update the Page Object class. Because test cases arenât directly tied to the implementation, they become more stable and more resistant to change as the website matures.
## A Typical Test _Without_ Page Objects
With traditional testing using Selenium, a simple login test might look something like the following: (using the pipe-separated format for clarity):
```robotframework
*** Test Cases ***
| Login with valid credentials
| | Go to | ${ROOT}/Login.html
| | Wait for page to contain | id=id_username
| | Input text | id=id_username | ${USERNAME}
| | Input text | id=id_password | ${PASSWORD}
| | Click button | id=id_form_submit
| | Wait for page to contain | Your Dashboard
| | Location should be | ${ROOT}/dashboard.html
```
Notice how this test is tightly coupled to the implementation of the page. It has to know that the input field has an id of `id_username`, and the password field has an id of `id_password`. It also has to know the URL of the page being tested.
Of course, you can put those hard-coded values into variables and import them from a resource file or environment variables, which makes it easier to update tests when locators change. However, thereâs still the overhead of additional keywords that are often required to make a test robust, such as waiting for a page to be reloaded. The provided PageObject superclass handles some of those details for you.
## The Same Test, Using Page Objects
Using Page Objects, the same test could be written like this:
```robotframework
*** Test Cases ***
| Login with valid credentials
| | Go to page | LoginPage
| | Login as a normal user
| | The current page should be | DashboardPage
```
Notice how there are no URLs or element locators in the test whatsoever, and that weâve been able to eliminate some keywords that typically are necessary for selenium to work but which arenât part of the test logic *per se*. What we end up with is test case that is nearly indistinguishable from typical acceptance criteria of an agile story.
## Writing a Page Object class
Page Objects are simple python classes that inherit from `PageObjectLibrary.PageObject`. There are only a couple of requirements for the class:
- The class should define a variable named `PAGE_TITLE`
- The class should define a variable named `PAGE_URL` which is a URI relative to the site root.
By inheriting from `PageObjectLibrary.PageObject`, methods have access to the following special object attributes:
- `self.selib` - a reference to an instance of SeleniumLibrary. With this you can call any of the SeleniumLibrary keywords via their python method names (eg: self.selib.input\_text)
- `self.browser` - a reference to the webdriver object created when a browser was opened by SeleniumLibrary. With this you can bypass SeleniumLibrary and directly call all of the functions provided by the core selenium library.
- `self.locator` - a wrapper around the `_locators` dictionary of the page. This dictionary can contain all of the locators used by the Page Object keywords. `self.locators` adds the ability to access the locators with dot notation rather than the slightly more verbose dictionary syntax (eg: `self.locator.username` vs `self._locators["username"]`.
## An example Page Object
A Page Object representing a login page might look like this:
```python
from PageObjectLibrary import PageObject
class LoginPage(PageObject):
PAGE_TITLE = "Login - PageObjectLibrary Demo"
PAGE_URL = "/login.html"
_locators = {
"username": "id=id_username",
"password": "id=id_password",
"submit_button": "id=id_submit",
}
def enter_username(self, username):
"""Enter the given string into the username field"""
self.selib.input_text(self.locator.username, username)
def enter_password(self,password):
"""Enter the given string into the password field"""
self.selib.input_text(self.locator.password, password)
def click_the_submit_button(self):
"""Click the submit button, and wait for the page to reload"""
with self._wait_for_page_refresh():
self.selib.click_button(self.locator.submit_button)
```
[robot framework]: http://www.robotframework.org
[Set library search order keyword]: http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Library%20Search%20Order
%prep
%autosetup -n robotframework-pageobjectlibrary-1.1
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-robotframework-pageobjectlibrary -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Sun Apr 23 2023 Python_Bot <Python_Bot@openeuler.org> - 1.1-1
- Package Spec generated
|