from robotlibcore import DynamicCore
时间: 2024-01-12 11:04:58 浏览: 72
`DynamicCore` is a class from the `robotlibcore` library in Robot Framework that provides support for the dynamic library API. It allows library developers to implement keywords as regular Python functions that are then automatically published as keywords in the Robot Framework public API.
To use `DynamicCore`, a library class must inherit from it and then implement keywords as regular methods decorated with the `@keyword` decorator. Here is an example:
```python
from robotlibcore import DynamicCore, keyword
class MyLibrary(DynamicCore):
@keyword
def my_keyword(self, arg1, arg2):
"""
This is a keyword that takes two arguments and returns their sum.
"""
return arg1 + arg2
```
In the above example, `MyLibrary` is a library class that inherits from `DynamicCore`. The `my_keyword` method is decorated with the `@keyword` decorator, which automatically publishes it as a keyword in the Robot Framework public API.
When the library is imported and instantiated in a Robot Framework test case, the `my_keyword` method can be called as a keyword. For example:
```robotframework
*** Settings ***
Library MyLibrary
*** Test Cases ***
Example Test Case
${result}= My Keyword 1 2
Should Be Equal As Integers ${result} 3
```
In the above test case, the `My Keyword` keyword is used to call the `my_keyword` method of the `MyLibrary` instance. The result is then checked using the `Should Be Equal As Integers` keyword.