当前位置:网站首页>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
边栏推荐
- Grbl learning (I)
- 欣旺达:HEV和BEV超快充拳头产品大规模出货
- Install redis and deploy redis high availability cluster
- What is cloud migration? The four modes of cloud migration are?
- Query the data from 2013 to 2021, and only query the data from 2020. The solution to this problem is carried out
- 04 Lua 运算符
- LVM与磁盘配额
- Redis "8" implements distributed current limiting and delay queues
- Gartner 发布新兴技术研究:深入洞悉元宇宙
- Xinwangda: HEV and Bev super fast charging fist products are shipped on a large scale
猜你喜欢
力扣-198.打家劫舍
Review 2021: how to help customers clear the obstacles in the last mile of going to the cloud?
Summary according to classification in sail software
Research and Practice on business system migration of a government cloud project
人脸识别框架之dlib
Download and install mongodb
You need to know about cloud disaster recovery
英语 | Day15、16 x 句句真研每日一句(从句断开、修饰)
TIA botu - basic operation
Hypermotion cloud migration helped China Unicom. Qingyun completed the cloud project of a central enterprise and accelerated the cloud process of the group's core business system
随机推荐
各大框架都在使用的Unsafe类,到底有多神奇?
Start Oracle service on Linux
如何进行应用安全测试(AST)
Force buckle-746 Climb stairs with minimum cost
Sail soft implements a radio button, which can uniformly set the selection status of other radio buttons
Day (4) of picking up matlab
The most detailed Backpack issues!!!
Solution to the fourth "intelligence Cup" National College Students' IT skills competition (group B of the final)
漫画:什么是IaaS、PaaS、SaaS?
Esxi encapsulated network card driver
VMware Workstation cannot connect to the virtual machine. The system cannot find the specified file
Database dbvisualizer Pro reported file error, resulting in data connection failure
Sail soft segmentation solution: take only one character (required field) of a string
Homewbrew installation, common commands and installation path
人脸识别框架之dlib
451. 根据字符出现频率排序
Detailed explanation of file operation (2)
Cloudy data flow? Disaster recovery on cloud? Last value content sharing years ago
You need to know about cloud disaster recovery
Hyperbdr cloud disaster recovery v3 Release of version 3.0 | upgrade of disaster recovery function and optimization of resource group management function