当前位置:网站首页>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
边栏推荐
- Report FCRA test question set and answers (11 wrong questions)
- File system read and write performance test practice
- About background image gradient()!
- Execution plan calculation for different time types
- Esxi encapsulated network card driver
- 无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
- Hyperbdr cloud disaster recovery v3 Release of version 3.0 | upgrade of disaster recovery function and optimization of resource group management function
- 文件系统读写性能测试实战
- What is cloud migration? The four modes of cloud migration are?
- Server log analysis tool (identify, extract, merge, and count exception information)
猜你喜欢

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

homwbrew安装、常用命令以及安装路径

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

Meaning and usage of volatile

第九天 static 抽象类 接口

力扣-198.打家劫舍

Postman batch production body information (realize batch modification of data)

Use itextpdf to intercept the page to page of PDF document and divide it into pieces

Install redis and deploy redis high availability cluster

无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
随机推荐
Interview question 17.10 Main elements
Postman batch production body information (realize batch modification of data)
Database dbvisualizer Pro reported file error, resulting in data connection failure
关于 background-image 渐变gradient()那些事!
New project of OMNeT learning
最详细的背包问题!!!
What is the experience of using prophet, an open source research tool?
人脸识别框架之dlib
阿里研发三面,面试官一套组合拳让我当场懵逼
Hyperbdr cloud disaster recovery v3 Release of version 3.0 | upgrade of disaster recovery function and optimization of resource group management function
漫画:什么是IaaS、PaaS、SaaS?
Set cell filling and ranking method according to the size of the value in the soft report
如何进行应用安全测试(AST)
VMware Workstation cannot connect to the virtual machine. The system cannot find the specified file
ESP32_ Arduino
建站常用软件PhpStudy V8.1图文安装教程(Windows版)超详细
Sail soft implements a radio button, which can uniformly set the selection status of other radio buttons
299. Number guessing game
众昂矿业:萤石浮选工艺
Loading order of logback configuration file