当前位置:网站首页>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
边栏推荐
- Change the icon size of PLSQL toolbar
- Sail soft implements a radio button, which can uniformly set the selection status of other radio buttons
- Six scenarios of cloud migration
- 力扣-198.打家劫舍
- Vim使用Vundle安装代码补全插件(YouCompleteMe)
- Day 9 static abstract class interface
- Day (4) of picking up matlab
- Grbl learning (II)
- Custom implementation of Baidu image recognition (instead of aipocr)
- Detailed explanation of file operation (2)
猜你喜欢

Nacos 详解,有点东西

Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot

Set the color change of interlaced lines in cells in the sail software and the font becomes larger and red when the number is greater than 100

299. Number guessing game

第九天 static 抽象类 接口

Install redis and deploy redis high availability cluster

RAID磁盘阵列与RAID5的创建

【Pygame小游戏】10年前风靡全球的手游《愤怒的小鸟》,是如何霸榜的?经典回归......

Sort by character occurrence frequency 451

Cartoon: what are IAAs, PAAS, SaaS?
随机推荐
基于GPU实例的Nanopore数据预处理
Start Oracle service on Linux
Day (2) of picking up matlab
Homewbrew installation, common commands and installation path
TIA botu - basic operation
Cartoon: what are IAAs, PAAS, SaaS?
NVIDIA显卡驱动报错
Cloud migration practice in the financial industry Ping An financial cloud integrates hypermotion cloud migration solution to provide migration services for customers in the financial industry
阿里研发三面,面试官一套组合拳让我当场懵逼
[key points of final review of modern electronic assembly]
Force buckle - 198 raid homes and plunder houses
Matplotlib tutorial 05 --- operating images
homwbrew安装、常用命令以及安装路径
Real time operation of vim editor
Oak-d raspberry pie cloud project [with detailed code]
【Pygame小游戏】10年前风靡全球的手游《愤怒的小鸟》,是如何霸榜的?经典回归......
Vim使用Vundle安装代码补全插件(YouCompleteMe)
Loading order of logback configuration file
Use itextpdf to intercept the page to page of PDF document and divide it into pieces
JSP learning 2