|
1 |
| -Python Library Core |
2 |
| -=================== |
| 1 | +PythonLibraryCore |
| 2 | +================= |
3 | 3 |
|
4 | 4 | Tools to ease creating larger test libraries for `Robot Framework`_ using
|
5 |
| -Python. |
| 5 | +Python. The Robot Framework `hybrid`_ and `dynamic library API`_ gives more |
| 6 | +flexibility for library than the static library API, but they also sets requirements |
| 7 | +for libraries which needs to be implemented in the library side. PythonLibCore |
| 8 | +eases the problem by providing simpler interface and handling all the requirements |
| 9 | +towards the Robot Framework library APIs. |
6 | 10 |
|
7 |
| -Code is stable and version 1.0 is already used by SeleniumLibrary_. |
8 |
| -Better documentation and packaging still to do. |
| 11 | +Code is stable and version 1.0 is already used by SeleniumLibrary_ and |
| 12 | +WhiteLibrary_. The version 2.0 support changes in the Robot Framework |
| 13 | +3.2. |
9 | 14 |
|
10 | 15 | .. image:: https://github.com/robotframework/PythonLibCore/workflows/CI/badge.svg?branch=master
|
11 | 16 | :target: https://github.com/robotframework/PythonLibCore
|
12 | 17 |
|
| 18 | +Usage |
| 19 | +----- |
| 20 | +There are two ways to use PythonLinCore, either by `HybridCore` or by using `DynamicCore`. |
| 21 | +`HybridCore` provides support for the hybrid library API and `DynamicCore` provides support |
| 22 | +for dynamic library API. Consult the Robot Framework `User Guide`_, for choosing the |
| 23 | +correct API for library. |
| 24 | + |
| 25 | +Regardless which library API is chosen, both have similar requirements. |
| 26 | + |
| 27 | +1) Library must inherit either the `HybridCore` or `DynamicCore`. |
| 28 | +2) Library keywords must be decorated with Robot Framework `@keyword`_ decorator. |
| 29 | +3) Provide a list of class instances implementing keywords to `library_components` argument in the `HybridCore` or `DynamicCore` `__init__`. |
| 30 | + |
| 31 | +It is also possible implement keywords in the library main class, by marking method with |
| 32 | +`@keyword` as keywords. It is not requires pass main library instance in the |
| 33 | +`library_components` argument. |
| 34 | + |
| 35 | +All keyword, also keywords implemented in the classes outside of the main library are |
| 36 | +available in the library instance as methods. This automatically publish library keywords |
| 37 | +in as methods in the Python public API. |
| 38 | + |
| 39 | +The example in below demonstrates how the PythonLibCore can be used with a library. |
| 40 | + |
13 | 41 | Example
|
14 | 42 | -------
|
15 | 43 |
|
16 | 44 | .. sourcecode:: python
|
17 | 45 |
|
18 | 46 | """Main library."""
|
19 | 47 |
|
20 |
| - from robotlibcore import HybridCore |
| 48 | + from robotlibcore import DynamicCore |
21 | 49 |
|
22 | 50 | from mystuff import Library1, Library2
|
23 | 51 |
|
24 | 52 |
|
25 |
| - class MyLibrary(HybridCore): |
| 53 | + class MyLibrary(DynamicCore): |
26 | 54 | """General library documentation."""
|
27 | 55 |
|
28 | 56 | def __init__(self):
|
29 | 57 | libraries = [Library1(), Library2()]
|
30 |
| - HybridCore.__init__(self, libraries) |
| 58 | + DynamicCore.__init__(self, libraries) |
31 | 59 |
|
| 60 | + @keyword |
| 61 | + def keyword_in_main(self): |
| 62 | + pass |
32 | 63 |
|
33 | 64 | .. sourcecode:: python
|
34 | 65 |
|
@@ -65,3 +96,8 @@ Example
|
65 | 96 |
|
66 | 97 | .. _Robot Framework: http://robotframework.org
|
67 | 98 | .. _SeleniumLibrary: https://github.com/robotframework/SeleniumLibrary/
|
| 99 | +.. _WhiteLibrary: https://pypi.org/project/robotframework-whitelibrary/ |
| 100 | +.. _hybrid: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#hybrid-library-api |
| 101 | +.. _dynamic library API: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#dynamic-library-api |
| 102 | +.. _User Guide: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-libraries |
| 103 | +.. _@keyword: https://github.com/robotframework/robotframework/blob/master/src/robot/api/deco.py |
0 commit comments