Assertion function-RF

The purpose of the test case is to verify that some operations meet our expected results, so in the test case, the assertion function is an essential item. Every operation we do will have an expected result. In order to ensure that the result of the operation meets expectations, we need to add an assertion to the test case to ensure that the actual result is consistent with the expected result. So let us first understand some commonly used assertion functions:

1、should be equal 与should not be equal

We set a variable in the first line and assign it a value of 1, and the second line means that ${var} should be equal to 1.

run:


You will find that only the value of the variable is printed. Generally speaking, the assertion function only serves as an assertion. If the assertion is met, there is no operation. If the assertion is not met, an error will be reported:

Now we change the value of ${var} to 2, assert the same, and then run:


We found that the use case was red, and an assertion error was given here.

should not be equal is the opposite, used to assert inequality.

2、should be empty与should not be empty

Assertions are empty or not empty.

As shown in the figure above, create list is a function to create a list. If we did not assign a value to the list, ${var} is an empty list. Run:

You can see that the expected empty list is printed, and the use case runs successfully.

3、should contain、should not contain与should contain x times

Let me explain first, list variables can also be represented by @{var}, but ${var} can represent a single variable, or a list or dictionary, which is more convenient to use~~~ We have created a list with connotation 1. 2, 3 values, the assertion list contains 1:

After running and printing out the variable value, we can see that as we expected, ${var} is a list. Here we find that every value in the list has a u before it. This is because RF is Unicode encoding by default, and u here is Your use case or assertion has no impact.

No need to explain should not contain. Let's talk about should contain x times, according to the English translation, it should contain a certain value x times:

The assertion here means that the variable ${var} should contain two ones, and run:

as we expected.

The above-listed assertions are the most commonly used assertions in my work, and there are many more. Their meanings can actually be translated in English. After all, foreigners also write them according to their purpose:
how to test software , Interface testing, automated testing, interview experience exchange. If you are interested, you can add software test communication: 1085991341, and there will be technical exchanges with colleagues.

Should Be Equal As Numbers与Should not Be Equal As Numbers
Should End With与Should not End With
Should start With与Should not start With
should match与should not match

The above is what you may encounter in your work, if you can use the usage, you can F5 query.

Sometimes our assertion function cannot meet our needs. At this time, we need to write scripts in Python to implement the corresponding logic, and then import system keywords.
The above content hopes to be helpful to you. Friends who have been helped are welcome to like and comment.

Guess you like

Origin blog.csdn.net/Chaqian/article/details/106448073