1. * * * * settings * * * introduction
settings set the libraries and resources that some test cases depend on.
*** Settings *** Library Selenium2Library /Library file library name Documentation Interface:/duty/sendToInnerDuty.action Suite Setup Run Keywords obtain cookie chunyu AND DutyLib.Set Cookie ${cookie} Test Template duty_sendToInnerDuty Library ../../../Libs/DutyLib.py Resource Prepare data.txt
Field Description:
Library: the system library of the robot framework
Documentation: describes the path of the test interface
Suite Setup: configure the environment in which the use case runs. For example, get the cookie Run Keywords field in advance, that is, set the cookie value required in the python file DutyLib by calling the keyword < get cookie >
Test Template: set the python function to be called to run the test case: duty_sendToInnerDuty
Library: set the external library file that needs to be called to run the test case, that is, the python file written by yourself, which contains the function duty_sendToInnerDuty. The above function can be called only after the library file is set
Resource: set the data resources required to run the test case, where the < prepare data. TXT > file is in the same folder as the test case.
2. Introduction to * * * variables * * *
There are two main types of variables in the Robotframework. Each variable can be named with the variable identifier {variable name}. The Robotframework is mainly divided into "Scalar" and "List" variables in daily use. The variable identifier of "Scalar" is "$" and the identifier of "List" is "@".
${boyname} Set variable TOM //Scalar variable assignment log ${boyname}
3. * * * * test cases * * * introduction
*** Test Cases *** vaild user //Case name or description [Setup] duty_setup startTimeStr=${next_Mon} 09:00:00 type=normal_duty customerId=177016 id=${duty_id} [Template] Login with valid user should succeed //Data driven johns long //value
explain:
Keyword: [Setup] used to set the pre step of the use case
Predecessor step Name: duty_setup / / the preceding step is a keyword, followed by the input parameter of the keyword
Input parameter: startTimeStr=${next_Mon} 09:00:00 type=normal_duty customerId=177016
4. * * * * keywords * * * introduction
*** Keywords ***
Login with valid user should succeed //keyword name
[Arguments] ${username} ${password} //[Arguments] set input parameters
Set Global Variable
u
s
e
r
n
a
m
e
/
/
set up
Set
{username} / / setting
username / / set {name} as a global variable so that it can be used in all use cases and keywords
[Return] ${cookie} / / set parameters
*** Keywords *** duty_setup //keyword name [Arguments] ${startTimeStr}=2018-12-31 00:00:00 ${type}=normal_duty ${customerId}=177016 ${duty_id} duty_save id=${EMPTY} dutySn=${EMPTY} problemId=${EMPTY} type=${type} customerId=${customerId} ... startTimeStr=${startTimeStr} endTimeStr=2018-12-31 23:59:59 customerContact=customer contact _test contactInfo=contact information_test infoSource=internal sourceDetail=Source details_test ... associationEntityListJson=[] attention=matters needing attention_test priority=HIGH title=Task theme_test description=<p>${time}_Task description_test</p> Set Suite Variable ${duty_id}
explain:
The keyword setting input parameter: [Arguments] ${startTimeStr}=2018-12-31 00:00:00 ${type}=normal_duty ${customerId}=177016
Calling python function: duty_save this function is defined in the library file DutyLib.py
The output parameter of the python function: ${duty_id}
The input parameter of the python function: follows the function name
Set the parameter variable as the global variable: Set Suite Variable ${duty_id}, so that other use cases can use this global variable when taking this keyword as the pre step
keyword usage:
Compatibility detection of Google browser
open browser http://www.baidu.com gc
Compatibility detection of Firefox browser
open browser http://www.baidu.com ff
Compatibility detection of ie browser
open browser http://www.baidu.com ie
log hello world
1_ Define variables
${a} Set variable hello world log ${a}
2_ Connection object
${hi} Catenate hello world log ${hi}
3_ Connection object
${hi} Catenate SEPARATOR=-- hello world log ${hi}
4_ Definition list
${abc} Create List a b c log ${abc}
4.1_ Definition list
@{abc} Create List a b c log many @{abc}
5. Time operation
${t} get time log ${t}
5.1 time operation_ sleep
${t} get time sleep 5 ${t} get time
6.if statement
${a} Set variable 59 run keyword if ${a}>=90 log excellent ... ELSE IF ${a}<=70 log good ... ELSE IF ${a}<=60 log pass ... ELSE log fail,
7.for loop
FOR ${var} IN a b c log ${var} log end
7.1inrangefor loop
FOR ${var} IN RANGE 10 log ${var} log end
8.createlist:for loop
@{abc} create list a b c FOR ${i} IN @{abc} log ${i}
9.exit for Loop if for loop
FOR ${var} IN a b c Runkeyword if '${var}'=='b' Exit for loop log ${var} log End of cycle
10.Evaluate random function
${d} Evaluate random.randint(1000,9999) random log ${d}
11. Import library
Import Library unittest
12. Import testpy file
Import Library test.py ${add} add 4 log ${add}
Verification of interface maximization
open browser https://www.baidu.com/index.php?tn=monline_3_dg ie maximize browser window
residence time
open browser https://www.baidu.com/ sleep 2 close browser
Click element - click element
open browser https://www.baidu.com click element xpath=/html/body/div[1]/div[1]/div[3]/a[2] log End of operation
Click the button button
Click link
open browser https://www.baidu.com click link xpath=/html/body/div[1]/div[1]/div[3]/a[2]
Verification of text frame
open browser http://10.1.2.229/zentao/user-login-L3plbnRhby8=.html sleep 3 input text xpath=//*[@id="account"] admin input text xpath=/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/input 123456 click button xpath=//*[@id="submit"]
Multi page Jump verification - select window new
open browser https://www.baidu.com gc click link xpath=/html/body/div[1]/div[1]/div[3]/a[1] select window new #Jump to keywords used by other websites click link xpath=//*[@id="pane-news"]/div/ul/li[1]/strong/a
Variable - set varriavle
${a} set variable 10 log ${a}
Conditional judgment - run keyworld if
${a} set variable 10 ${b} set variable 20 log ${a} log ${b} run keyword if ${a}>${b} log Go to self-study ... ELSE log I'm going to study by myself tonight
Get page data automatically - get window size
open browser https://www.baidu.com gc sleep 2 ${width} ${height} get window size log ${width} log ${height}
Automatic acquisition of web page resolution data - Baidu - GC FF IE
open browser https://www.baidu.com gc sleep 2 ${width} ${height} get window size maximize browser window ${width} ${height} get window size open browser https://www.baidu.com ff sleep 2 ${width} ${height} get window size maximize browser window ${width} ${height} get window size open browser https://www.baidu.com ie sleep 2 ${width} ${height} get window size maximize browser window ${width} ${height} get window size
Automatic acquisition of web page resolution data - Ping An Bank - GC FF IE
open browser http://bank.pingan.com gc sleep 2 ${width} ${height} get window size maximize browser window ${width} ${height} get window size open browser http://bank.pingan.com ff sleep 2 ${width} ${height} get window size maximize browser window ${width} ${height} get window size open browser http://bank.pingan.com ie sleep 2 ${width} ${height} get window size maximize browser window ${width} ${height} get window size
ZenTao
open browser http://127.0.0.1/index.php gc click element xpath=//*[@id="zentao"] sleep 3 input text xpath=//*[@id="account"] admin input text xpath=//*[@id="login-form"]/form/table/tbody/tr[2]/td/input 123456 sleep 3 click button xpath=//*[@id="submit"] sleep 3 click element xpath=//*[@id="mainmenu"]/ul/li[8]/a sleep 3 click element xpath=//*[@id="modulemenu"]/ul/li[3]/a sleep 3 click element xpath=//*[@id="featurebar"]/div[1]/div/a[3] sleep 3 maximize browser window input text xpath=//*[@id="title"] 666 sleep 3 set focus to element xpath=//*[@id="submit"] click button xpath=//*[@id="submit"]
Element location method xpath relative path
open browser http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html gc input text xpath=//*[@id="account"] admin input text xpath=//*[@id="login-form"]/form/table/tbody/tr[2]/td/input 123456 click element xpath=//*[@id="submit"]
Element location method - xpath absolute path
open browser http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html gc input text xpath=/html/body/div[1]/div[1]/div[2]/form/table/tbody/tr[1]/td/input admin input text xpath=/html/body/div[1]/div[1]/div[2]/form/table/tbody/tr[2]/td/input 123456 click element xpath=//*[@id="submit"]
Element positioning method css relative path
open browser http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html gc sleep 2 input text css=#account admin input text css=.table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1) 123456 sleep 2 click button css=#submit
Element location method css absolute path
open browser http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html ff sleep 2 input text css=html body.m-user-login div#container div#login-panel div#login-form.panel-content form.form-condensed table.table.table-form tbody tr td input#account.form-control admin #Absolute path input text css=.table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > input:nth-child(1) 123456 #Relative path #Password absolute path no sleep 2 click button css=html body.m-user-login div#container div#login-panel div#login-form.panel-content form.form-condensed table.table.table-form tbody tr td button#submit.btn.btn-primary
Element location method - css absolute path 2
open browser http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html ff sleep 2 input text css=html body.m-user-login div#container div#login-panel div#login-form.panel-content form.form-condensed table.table.table-form tbody tr td input#account.form-control admin input text css=html body.m-user-login div#container div#login-panel div#login-form.panel-content form.form-condensed table.table.table-form tbody tr td input.form-control 123456 sleep 2 click button #css=html body.m-user-login div#container div#login-panel div#login-form.panel-content form.form-condensed table.table.table-form tbody tr td button#submit.btn.btn-primary
Element location method - attribute location id
open browser http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html gc sleep 2 input text id=account admin input text name=password 123456 sleep 2 click button id=submit
Element location method - attribute location name
open browser http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html gc sleep 2 input text name=account admin input text name=password 123456 sleep 2 click button id=submit
Enter only the business elements corresponding to this page
open browser http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html gc sleep 2 input text account admin input text password 123456 sleep 2 click button id=submit
Job 1 - automation of login
open browser http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html gc sleep 2 input text xpath=//*[@id="account"] admin input text xpath=/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/input 123456 sleep 2 click button xpath=//*[@id="submit"]
Job 2 - add product automation
open browser http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html gc sleep 2 input text xpath=//*[@id="account"] admin input text xpath=/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/input 123456 sleep 2 click button xpath=//*[@ id="submit"] # login button sleep 3 maximize browser window click element xpath=/html/body/header/nav[1]/ul/li[2]/a #product sleep 2 click element xpath=/html/body/header/nav[2]/ul/li[11]/a #Add product sleep 2 input text xpath=//*[@ id="name"] Master Kang iced black tea # product name input text xpath=//*[@ id = "code"] 003 # product code sleep 2 #select frame xpath=/html/body/div[1]/div[1]/div/form/table/tbody/tr[7]/td/div/div[2]/iframe #Input text XPath = / HTML / body iced black tea is delicious! #sleep 2 set focus to element id=submit click button xpath=//*[@id="submit"]
Job 3 - automatic lifting BUG
open browser http://127.0.0.1/zentao/user-login.html gc sleep 2 input text xpath=//*[@id="account"] admin input text xpath=/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/input 123456 sleep 2 click button xpath=//*[@ id="submit"] # login button sleep 2 maximize browser window click element xpath=//*[@id="mainmenu"]/ul/li[8]/a sleep 2 click element xpath=//*[@id="modulemenu"]/ul/li[2]/a sleep 2 click element xpath=//*[@id="featurebar"]/div[1]/div[2]/a[2] sleep 2 click element xpath=//*[@id="openedBuild_chosen"]/ul sleep 2 click element xpath=//*[@id="openedBuild_chosen"]/div/ul/li sleep 2 input text xpath=//*[@ id="title"] does iced black tea contain sugar sleep 2 click element xpath=//*[@id="dataform"]/table/tbody/tr[5]/td/div[2]/div[2]/div/div[1]/button/span[2] sleep 2 click element xpath=//*[@id="dataform"]/table/tbody/tr[5]/td/div[2]/div[2]/div/div[1]/ul/li[2]/a/span sleep 2 click element xpath=//*[@id="dataform"]/table/tbody/tr[5]/td/div[2]/div[2]/div/div[2]/button/span[2] sleep 2 click element xpath=//*[@id="dataform"]/table/tbody/tr[5]/td/div[2]/div[2]/div/div[2]/ul/li[4]/a/span #Input box select frame xpath=//*[@id="dataform"]/table/tbody/tr[6]/td/div[2]/div[2]/iframe input text xpath=/html/body Formula of iced black tea unselect frame sleep 2 Execute javascript document.documentElement.scrollTop=500 #location #set focus to element id=submit #click button xpath=//*[@id="submit"]
Job 4 - add product automation - 2
open browser http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html gc sleep 2 input text xpath=//*[@id="account"] admin input text xpath=/html/body/div/div[1]/div[2]/form/table/tbody/tr[2]/td/input 123456 sleep 2 click button xpath=//*[@ id="submit"] # login button sleep 3 maximize browser window click element xpath=/html/body/header/nav[1]/ul/li[2]/a #product sleep 2 click element xpath=/html/body/header/nav[2]/ul/li[11]/a #Add product sleep 2 input text xpath=//*[@ id="name"] Master Kang iced black tea # product name input text xpath=//*[@ id = "code"] 003 # product code sleep 2 select frame xpath=/html/body/div[1]/div[1]/div/form/table/tbody/tr[7]/td/div/div[2]/iframe input text xpath=/html/body Iced black tea is delicious! unselect frame sleep 2 set focus to element id=submit click element xpath=//*[@id="aclprivate"] #set focus to element id=submit #click button xpath=//*[@id="submit"]
easybug login automation
open browser http://easybug.org gc sleep 2 Wait Until Page Contains element xpath=/html/body/div[1]/div[4]/div[1]/div[1]/div[2] 10 Display successful! input text xpath=//*[@id="_form"]/ul/li[1]/input 15331231280@qq.com input text xpath=//*[@id="_form"]/ul/li[2]/input ad12300 click element xpath=//*[@id="_submit"]/span
qq mailbox automation
open browser https://mail.qq.com gc sleep 3 select frame xpath=//*[@id="login_frame"] input text xpath=//*[@id="u"] sleep 3 input text xpath=//*[@id="p"] sleep 3 click element xpath=//*[@id="login_button"] unselect frame sleep 3