“This is my third day of the November Gwen Challenge. 2021 last more text challenge “when using the robotframework, the built-in library to provide the keyword is always not satisfied, at this time you can use python to write some class libraries, for the robotframework to call, this python file to achieve the method is called the extension keyword

How to import Python files as python modules

One way is to put it in the python installation path, just like the seleniumlibrary of the robotframework. The downside of this approach is that if you don’t re-develop the robotframework, the entire installation depends on packaging, and every time you deploy the environment, You’re going to have to redo the library that you wrote, but now there’s another way, which is to put it with your code

Naming rules

The file name of a python module is the library name, and if you have a python module that has a class in it, the class name should be the same as the file name, otherwise your extension key, the robotframework doesn’t recognize it, it’s going to get an error and it’s not going to work for example if I write a test library, Setting the Browser headless mode How do I set the download path

The file name and class name must be the same

Import the use

In the same directory as the Python library, I created a Robot resource file that references the Python library

Note: Because it is the same directory, there is no path information when importing. If it is not in the same directory, you need to add relative path. If you are not familiar with robot syntax, you can configure it through the robot-ride graphical interface

Click the Library button and find your Python file to import and save

The keyword name and parameters must be written in the robot syntax, just like any other keyword

The Python source for this method

If you set up your Robot editing environment and import these keywords in PyCharm, the coding will be very friendly

Python libraries use the distinction of whether initialization is required

The python init() method does not need to be passed as a parameter, so it can be used directly. Another python library that we have implemented, which sometimes needs to be instantiated, is init(), which needs to be passed as a parameter. You need to include the instantiation parameters as well

For example, if I write an action file library, I need to pass a file to instantiate before calling its methods. In the Robot file setting, I can introduce a list of library Python library parameters

Python source code

conclusion

The above import methods are based on the path method import, the key is to import only the same class name and module name, this is also what I said at the beginning