In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
How to handwrite robot automation use cases, although there are a lot of tutorials on the Internet, but they are all about ride. For how to write from a script point of view, it has been scattered and vague. This article takes the most common API interface automation on the Internet as an example, giving directional guidance, the text is not much, enough for you to understand, want to go deep, please follow the text in the text, and then go to Baidu, slowly experience, gradually profound.
Use case writing premise: the robot/python environment has been deployed
The first http interface * Settings * Library CollectionsLibrary ProcessLibrary RequestsLibrary*** Variables * * {DOMAIN} http://10.xx.xx.xx:8091${URI} / test/backend/xxxxlogin$ {"Content-Type": "application/json"} ${USER} {"accountType": "1", "phonenumStr": "iamusername", "password": "iampassword"} ${LIST_ANIMALS} ["cat" "dog"] * * Test Cases * * my first http test case create session myhttp ${DOMAIN} ${uri} set variable ${URI} # headers must be converted to json Otherwise, data will not be able to pass ${header} to json ${HEADER} ${postdata} to json ${DATA} ${resp} post request myhttp uri=$ {uri} data=$ {postdata} headers=$ {header} # verify the status of http should be equal as integers 200 ${resp.status_code} # print debug information # log ${resp.content} # log ${json} # log ${json [0]} # log ${json [1] ["id"]} ${json} to json ${resp.content} # verify the key value of the returned data should be equal as strings 2.0 ${json [1] ["jsonrpc"]} multi-step operation
All the return values are of string type, which can be converted to json and can be used at will like a typical word.
${json} to json ${resp.content}
Take the value as the input parameter for the next call
It is recommended that each testcase only test one function. During the interface testing phase, do not construct scenarios that are too complex (more than one screen of use case code will be considered complex and need to be split).
Result check
All the returns obtained by the request http are of string type, and the values can be freely accessed only when parsed into json.
A variety of check functions are provided as follows:
Should be equal as integers should be equal as numbers should be equal as stringsshould be trueshould be emptyshould contain should contain any# not also supports should not be equal as integers should not be equal as numbers should not be equal as stringsshould not be trueshould not be emptyshould not contain should not contain any data driver
Robot claims to support data-driven and supports reading data from tables to run use cases according to template, but the problem is that if you want to pick and split the case in the data table, it will be powerless. Therefore, data-driven is suitable for large-scale protocol testing, while the need for detailed statistical case is not easy to use. Our suggestion is to use test data to be scattered in the testcase to maintain the independence and flexibility of case. If there is indeed a large number of manual operations, provide gadgets to automatically create testcase.
Data driven is defined as a Template, and then a use case can be formed according to the parameters, and each piece of data is executed independently.
* Test Cases * Invalid Username [Tags] Iteration-3 Smoke [Template] Login with invalid credentials should fail invalidname qwe123 091931 invalidpassword*** Test Cases * Login Success [Tags] Iteration-3 Smoke core [Template] Login success 068970 qwe123 052255 qwe123 precondition (optional)
A use case file contains a lot of testcase, I want to add some actions what to do? The framework provides two methods. If it is a precondition (executed before the start of each use case), you can use Set up to write your action in setting. If the action is complex, you can call it as a keyword, like the following:
* * Settings * * Test Setup Get config * * Keywords * * Get config log is initializing. Set suite variable ${config} {"env": "uat", "user": ""} cleanup action (optional)
If it is a postcondition (called after the end of each testcase), use Tear down, as shown in the following example:
* * Settings * * Test Teardown Do clean*** Keywords * * Do clean log is cleaning up. Keyword drive
The framework provides a custom keyword scheme. You only need to write your logical actions under the Keywords. The keywords can be in English or Chinese, with no restrictions on spaces and special characters. You can write use case code like natural language.
* Keywords * My first keywords log hello keywords my first keyword log Hello, my keyword
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.