RFS Web Automation Acceptance test--The 12th lecture List variables-list variable and its usage

Source: Internet
Author: User
Tags scalar

Introduction: What is Rfs--robotframework+selenium2library, this series mainly introduces the Web Automation acceptance test aspect.

( @ jing-Tao Chang Sina Weibo)

In this lecture we focus on the list variables-list variables and their usage.

I. List variables and their usage

In the previous articles we used a lot of list variables, I believe you will also encounter the need to use the place.

1. List variable Assignment

and scalar-like assignment, in addition to using the Set variable can also use the Create List.

Run it:

2. List variable use

In the use of attention to see whether the parameters of the keyword is scalar or list, the difference is to see if the variable name is preceded by * (asterisk),

The name of this keyword is the parameter that supports incoming scalar type, and *args is support for passing in the list type value.

The so-called List type value is actually said to support multiple values, that is, the number of indeterminate, list-like the same value, such as 2, 3 lines:

Of course, not to say that there is no asterisk can not use the list, as long as the number of variables to use the list to pass the value.

Like log this keyword, he has 2 scalar type of incoming parameters, if I want to pass the list is also possible, but it must be a list of 2 elements, because the second parameter of log has a default value, so if you pass in a list of 1 elements is also possible, But if you pass in a list of 3 elements, you will get an error.

You can write it up like this, but I don't recommend this approach, it's just a demonstration to explain the role of list.

To sum up, for keywords with multiple parameters, you can pass in more than one scalar variable as needed, or you can pass in the list variable and choose the appropriate way for your own needs.

Second, variable conversion

The scalar variable was previously referred to as an identifier, the list type variable is used as the identifier, and they can be converted, theoretically can be converted to each other, but there is a little limit.

1. The list variable is converted to scalar

The effect of this conversion is to turn the whole list into a scalar, and I think the main function is for those keywords that only receive scalar arguments, and you want to pass all the values of the list, or else you need to use the list as a scalar. For example, the FAIL keyword, whose msg this parameter can only receive scalar variables.

If you want to use fail, the value of the variable F is to play out, the following is sure to give an error.

The error message is Keyword ' Builtin.fail ' expected 0 to 1 arguments, got 3.

Then we change, so that the writing will not error.

Operation Result:

2. Scalar variable converted to list

In fact, the previous introduction of the user keyword also demonstrated that the return value is a list of keywords, if you give the variable to be assigned to write scalar, he will automatically turn him into a list.

Or the above example, we changed @{f} to ${f}

This is OK, too.

3. Limitation of conversion

However, as I mentioned earlier, the conversion is a bit restrictive.

First, it is mentioned in the previous note that variables are to be assigned (similar to initialization) before they can be used, and if there is a color hint in the ride that has not been assigned, use a preceding figure

The Purple ${f} is a hint that he has not been assigned, and the system defaults to the scalar form of @{f}, which can be seen in the above results.

Then this restriction is in the scalar conversion to list, the system will default ${f} is the scalar form of @{f}, but he does not default @{f} is the list form of ${f}, even if ${f} is already a list.

Take a look at the example:

In this case, the operation will be error: non-existing variable ' @{f} '.

What is the use of ${f} at this time? In addition to the scalar variables described earlier, the values are all elements, and you can get an element directly from index.

For example:

Operation Result:

After reading the above restrictions, but also to add that the system will default ${f} is the scalar form of @{f}, this is also a limit, must be ${f} is not assigned to the case, if ${f} is assigned to what is the case?

Take a look at the example:

What do you think is the value of ${f}?

Therefore, it is important to keep in mind that scalar and list variables are not identical, especially when you want to use them for different purposes.

An important effect is to cause the following list element to get out of bounds.

Third, the list element gets

The list element gets only one way, whether it is a one-dimensional list or a two-dimensional list, it is using the ${variable name [index]}, that is, with the $ variable, the variable name after the square brackets, inside is the ordinal.

1, one-dimensional list of examples.

Run:

2, two-dimensional list of examples.

Operation Result:

If log only writes ${f[1]}, the resulting

In short, is to use square brackets to indicate the elements you need, if it is a multidimensional list, you want to know exactly what layer you want, do not write less or write more.

RFS Web Automation Acceptance test--The 12th lecture List variables-list variable and its usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.