当前位置:网站首页>Public variables of robotframework
Public variables of robotframework
2022-04-23 16:36:00 【Sink the wine cup and fleeting time】
RobotFramework And Public variables
Public variables
I've learned that through Resource file Manage user keywords , Duplicate the extracted content , Simplify the operation steps in test cases
common.robot
*** Settings ***
Library SeleniumLibrary
*** Keywords ***
Log in to Netease mailbox
# open chrome Browser access 163 mailbox
open browser https://mail.163.com/ chrome
sleep 5
maximize browser window
# Switch to iframe
select frame xpath=//iframe[contains(@id,'iframe')]
# Enter... In the user name input box user name
sleep 2
input text xpath=//*[@name="email"] Your username
sleep 2
# Enter... In the password input box password
input text xpath=//*[@name="password"] Your password
sleep 2
# Click the login button
click element xpath=//*[@id="dologin"]
sleep 10
Close the browser
close browser
test.robot
*** Settings ***
Library SeleniumLibrary
Resource common.robot
Suite Setup Log in to Netease mailbox
Suite Teardown Close the browser
*** Test Cases ***
Use cases 1
log to console Here is the body of the use case
Use cases 2
log to console Here is the body of the use case
And the variables in the operation steps , For example, element positioning , May be used in this keyword , It will also be used in other keywords , If the element location changes , We need to change these keywords at the same time , so much trouble .
Another example is the account number 、 Data like passwords , Different accounts have different permissions , You need to use different accounts to operate .
therefore , For this type of data , It can be separated , That is to say Public variables , Play the role of sharing
RF Use of public variables
Public variables need to declare variables in the variable table , Create a new one Public variables .robot file , establish Variables surface , stay Variables Declare variables in the table
Public variables .robot
*** Variables ***
# Element localization
${
Netease email address } https://mail.163.com/
${
iframe} xpath=//iframe[contains(@id,'iframe')]
${
User name input box } xpath=//*[@name="email"]
${
Password input box } xpath=//*[@name="password"]
${
The login button } xpath=//*[@id="dologin"]
# Account data
${
jurisdiction 1 account number } user name 1
${
jurisdiction 1 password } password 1
${
jurisdiction 2 account number } user name 2
${
jurisdiction 2 password } password 2
And then in common.robot Import in file Public variables .robot file :Resource Public variables .robot
common.robot
*** Settings ***
Library SeleniumLibrary
Resource Public variables .robot
*** Keywords ***
Log in to Netease mailbox
[Arguments] ${
account number }=${
jurisdiction 1 account number } ${
password }=${
jurisdiction 1 password }
# open chrome Browser access 163 mailbox
open browser ${
Netease email address } chrome
sleep 5
maximize browser window
# Switch to iframe
select frame ${
iframe}
# Enter... In the user name input box user name
sleep 2
input text ${
User name input box } ${
account number }
sleep 2
# Enter... In the password input box password
input text ${
Password input box } ${
password }
sleep 2
# Click the login button
click element ${
The login button }
sleep 10
Close the browser
close browser
In this case , Element positioning has changed , Only need Public variables .robot Just modify the file , The default login account is jurisdiction 1 account number , If you need to use another account ,
stay Log in to Netease mailbox Add the variables corresponding to the account and password to be used after the keyword
test.robot
*** Settings ***
Library SeleniumLibrary
Resource common.robot
Suite Setup Log in to Netease mailbox ${
jurisdiction 2 account number } ${
jurisdiction 2 password }
Suite Teardown Close the browser
*** Test Cases ***
Use cases 1
log to console Here is the body of the use case
Use cases 2
log to console Here is the body of the use case
list Variable
Public variables .robot In file , The variable type can also be list Variable
For example, in the process of project iteration , There will be multiple test environments , By creating a list Variable , Put the addresses of these test environments in list Variable in . Here we use Netease email address For example , Be careful , When you declare a variable here, it becomes @{ Netease email address }
Public variables .robot
*** Variables ***
# Element localization
@{
Netease email address } https://mail.126.com/ https://mail.163.com/
${
iframe} xpath=//iframe[contains(@id,'iframe')]
${
User name input box } xpath=//*[@name="email"]
${
Password input box } xpath=//*[@name="password"]
${
The login button } xpath=//*[@id="dologin"]
# Account data
${
jurisdiction 1 account number } user name 1
${
jurisdiction 1 password } password 1
${
jurisdiction 2 account number } user name 2
${
jurisdiction 2 password } password 2
Use here https://mail.163.com/ This address , stay common.robot The file needs to be changed to ${ Netease email address }[1]( The second parameter )
common.robot
*** Settings ***
Library SeleniumLibrary
Resource Public variables .robot
*** Keywords ***
Log in to Netease mailbox
[Arguments] ${
account number }=${
jurisdiction 1 account number } ${
password }=${
jurisdiction 1 password }
# open chrome Browser access 163 mailbox
open browser ${
Netease email address }[1] chrome
sleep 5
maximize browser window
# Switch to iframe
select frame ${
iframe}
# Enter... In the user name input box user name
sleep 2
input text ${
User name input box } ${
account number }
sleep 2
# Enter... In the password input box password
input text ${
Password input box } ${
password }
sleep 2
# Click the login button
click element ${
The login button }
sleep 10
Close the browser
close browser
dict Variable
Public variables .robot In file , The variable type can be list Variable , It can also be dict Variable
Public variables .robot In file , The account password can be written like this
Public variables .robot
*** Variables ***
# Element localization
@{
Netease email address } https://mail.126.com/ https://mail.163.com/
${
iframe} xpath=//iframe[contains(@id,'iframe')]
${
User name input box } xpath=//*[@name="email"]
${
Password input box } xpath=//*[@name="password"]
${
The login button } xpath=//*[@id="dologin"]
# Account data
&{
Account data } jurisdiction 1 account number = user name 1 jurisdiction 1 password = password 1 jurisdiction 2 account number = user name 2 jurisdiction 2 password = password 2
Here is an example , You don't use the default parameters , Account content is ${ Account data }[ jurisdiction 1 account number ], The corresponding is user name 1, The password content is ${ Account data }[ jurisdiction 1 password ], The corresponding is password 1
common.robot
*** Settings ***
Library SeleniumLibrary
Resource Public variables .robot
*** Keywords ***
Log in to Netease mailbox
# open chrome Browser access 163 mailbox
open browser ${
Netease email address }[1] chrome
sleep 5
maximize browser window
# Switch to iframe
select frame ${
iframe}
# Enter... In the user name input box user name
sleep 2
input text ${
User name input box } ${
Account data }[ jurisdiction 1 account number ]
sleep 2
# Enter... In the password input box password
input text ${
Password input box } ${
Account data }[ jurisdiction 1 password ]
sleep 2
# Click the login button
click element ${
The login button }
sleep 10
Close the browser
close browser
Use variable files
In addition to creating Public variables .robot file , establish Variables surface , stay Variables Declare variables in the table in this way , You can also use python Module file Provide public variables to RF Use , Just define variables directly , Grammar is completely python grammar
config.py
url1 = 'https://mail.126.com/'
url2 = 'https://mail.163.com/'
stay RF The variable file is declared in the file :Variables config.py, Use variables directly $url1 that will do
common.robot
*** Settings ***
Library SeleniumLibrary
Resource Public variables .robot
Variables config.py
*** Keywords ***
Log in to Netease mailbox
# open chrome Browser access 163 mailbox
open browser $url1 chrome
sleep 5
maximize browser window
# Switch to iframe
select frame ${
iframe}
# Enter... In the user name input box user name
sleep 2
input text ${
User name input box } ${
Account data }[ jurisdiction 1 account number ]
sleep 2
# Enter... In the password input box password
input text ${
Password input box } ${
Account data }[ jurisdiction 1 password ]
sleep 2
# Click the login button
click element ${
The login button }
sleep 10
Close the browser
close browser
版权声明
本文为[Sink the wine cup and fleeting time]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231402128887.html
边栏推荐
- Set cell filling and ranking method according to the size of the value in the soft report
- Oak-d raspberry pie cloud project [with detailed code]
- homwbrew安装、常用命令以及安装路径
- Review 2021: how to help customers clear the obstacles in the last mile of going to the cloud?
- Sail soft calls the method of dynamic parameter transfer and sets parameters in the title
- ES常用查询、排序、聚合语句
- 第十天 异常机制
- 各大框架都在使用的Unsafe类,到底有多神奇?
- loggie 源码分析 source file 模块主干分析
- UWA Pipeline 功能详解|可视化配置自动测试
猜你喜欢

loggie 源码分析 source file 模块主干分析

JMeter setting environment variable supports direct startup by entering JMeter in any terminal directory
![[pyGame games] how did angry birds, a mobile game that became popular all over the world 10 years ago, dominate the list? Classic return](/img/f5/15b3731e75eb4d861bd9d29ae244da.png)
[pyGame games] how did angry birds, a mobile game that became popular all over the world 10 years ago, dominate the list? Classic return

Take according to the actual situation, classify and summarize once every three levels, and see the figure to know the demand

What is the experience of using prophet, an open source research tool?

Install redis and deploy redis high availability cluster

vim编辑器的实时操作

人脸识别框架之dlib

Use if else to judge in sail software - use the title condition to judge

第十天 异常机制
随机推荐
Use if else to judge in sail software - use the title condition to judge
Questions about disaster recovery? Click here
Set cell filling and ranking method according to the size of the value in the soft report
LVM and disk quota
Day (10) of picking up matlab
How to upgrade openstack across versions
Query the data from 2013 to 2021, and only query the data from 2020. The solution to this problem is carried out
Homewbrew installation, common commands and installation path
Day (5) of picking up matlab
Take according to the actual situation, classify and summarize once every three levels, and see the figure to know the demand
451. 根据字符出现频率排序
DanceNN:字节自研千亿级规模文件元数据存储系统概述
Nanny Anaconda installation tutorial
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
1959年高考数学真题
力扣-198.打家劫舍
Solution to the fourth "intelligence Cup" National College Students' IT skills competition (group B of the final)
OAK-D树莓派点云项目【附详细代码】
Redis "8" implements distributed current limiting and delay queues
Loading order of logback configuration file