Comprehensive interpretation of SeleniumLibrary keywords

Comprehensive interpretation of SeleniumLibrary keywords!

In robotframework, to achieve web automation, you need to use the SeleniumLibrary library.

In the current version, there are 180+ keywords.

As the version is updated, the number and names of keywords will also change.

I did not find a comprehensive keyword introduction about this library on the Internet, so this article lists commonly used keywords according to keyword categories as a reference tool.

1. Installation

1. Installation of SeleniumLibrary:

Prerequisite: The python environment has been installed and the environment variables have been configured.

Then in the command line, run the following command:

Comprehensive interpretation of SeleniumLibrary keywords

 

Comprehensive interpretation of SeleniumLibrary keywords

 

Second, the relationship

2. SeleniumLibrary structure and relationship with Selenium

SeleniumLibrary is a python third-party library (stored in
Lib/site-packages/SeleniumLibrary under the python installation directory ).

Its structure is as follows, in which keywords are stored in the keywords directory.

In the source code, keywords are stored in different categories.

Including alert popups, table/select/iframe and other element operations, waiting, windows, etc.

Comprehensive interpretation of SeleniumLibrary keywords

 

In the source code of SeleniumLibrary, many places directly use the selenium API to encapsulate the operation of the webpage. It can be said that on the selenium, more element operation keywords are encapsulated and provided to the users of the robot framework.

After all, there are ready-made "wheels", and there is no need to reinvent them.

For example, the mouse operation in elment.py above.

In selenium, the ActionChains class is used to specifically implement mouse operations.

Take the element double-click operation as an example. If you use the python+selenium library to implement the double-click operation, you need the following code:

Comprehensive interpretation of SeleniumLibrary keywords

 

In SeleniumLibrary, the keyword double click element encapsulates the element and the mouse double-click operation.

Just pass in the element positioning (as shown in the figure below).

Comprehensive interpretation of SeleniumLibrary keywords

 

3. Keyword interpretation

3. SeleniumLibrary keyword classification interpretation

1) When importing the SeleniunLibrary library, the initialization parameters

SeleniumLibrary in the robotframework will initialize the SeleniumLibrary class when it is introduced.

The initialized parameters are effective for all keywords.

Comprehensive interpretation of SeleniumLibrary keywords

 

◆ Timeout:

Wait for the timeout period. If there is a timeout parameter in the keyword, use the default value here, 5 seconds.

◆ Implicit wait::

Hidden waiting time. 0.0 means there is no hidden wait.

◆ run on failure:

The action when the keyword fails to run. Capture Page Screenshot is the keyword for capturing page images. Indicates that when the operation fails, the current webpage picture will be automatically captured, that is, the function of automatically taking a screenshot when it fails.

◆ Screenshot root directory:

The storage path of the intercepted webpage image. None means that the path is not specified, and the default is the same directory as the output file.

When we introduce SeleniumLibrary into the robot, we can modify the default parameter values.

For example, modify the default timeout to 15s

Comprehensive interpretation of SeleniumLibrary keywords

 

2) Element positioning syntax:

In web automation, there are 8 major positioning methods. No matter what language/framework is used, the positioning method is universal.

In the robot framework, the positioning syntax has the following two expressions:

◆ Positioning strategy: positioning expression (such as id: kw)

◆ Positioning strategy = positioning expression (such as id=kw)

Among the robots, in addition to the eight positioning methods, several additional methods have been extended. The overall positioning methods are as follows (excerpted from official documents):

Comprehensive interpretation of SeleniumLibrary keywords

 

Example:

Comprehensive interpretation of SeleniumLibrary keywords

 

Note: The prefix of xpath positioning expression can be omitted: xpath.

3) Browser and window operation keywords

Comprehensive interpretation of SeleniumLibrary keywords

 

4) Element general operation keywords (including mouse/keyboard operation):

Comprehensive interpretation of SeleniumLibrary keywords

 

5) Operation keywords such as select/frame/alert/table:

Comprehensive interpretation of SeleniumLibrary keywords

 

6) Element waits for keywords

(If the keyword contains wait, the timeout parameter defaults to the seleniumlibrary initialization value, and the default is 5 seconds):

Comprehensive interpretation of SeleniumLibrary keywords

 

7) Assertion keywords (all keywords that contain should are):

Comprehensive interpretation of SeleniumLibrary keywords

 

There are many other assertion keywords, not to list them all.

8) Screen capture keywords:

Comprehensive interpretation of SeleniumLibrary keywords

 

Four, use examples

4. Robot-web automation usage example

Comprehensive interpretation of SeleniumLibrary keywords

Recommend a software testing learning exchange group: 785128166, there are shared videos, interview guidance, test materials, mind maps, and videos in the group. They are all dry goods, you can download and watch. Mainly share test foundation, interface test, performance test, automated test, TestOps architecture, Jmeter, LoadRunner, Fiddler, MySql, Linux, resume optimization, interview skills, and actual video data of large-scale test projects. Use every minute and every second of your time to learn to improve yourself, and don't use "no time" to conceal your mental laziness! Try hard while you are young, and give your future self an explanation!

Public number: Programmer Erhei, after paying attention, you can receive a large amount of learning materials for free.

Good things should be shared with friends
 

Guess you like

Origin blog.csdn.net/weixin_53519100/article/details/114703268