At present, what we need to consider is how to realize the keyword- driven automatic output of the interface, and realize the detachment of scripts and use cases in a certain sense through the encapsulation of keywords!
The installation of robot framework is not too much explanation, there are too many online materials~
Example: ! ! ! ! !
Step 1: Create a new project
Test items can be stored in directories or files, and the format can be in TXT, TSV or HTML format. It is recommended to select the directory and TXT for the project, which is easy to manage
Step 2: Create a new test suite
Like the test project, the test suite can also be stored in directories and files, and the format can also be in TXT, TSV or HTML format. It is recommended that the test suite choose file storage and TXT
Step 3: Create a new test case
————————After the creation of this series of basic support components———The directory structure is———————
Here's how to create a use case on this framework! ! !
we know! rf is driven by keywords, and the test object is identified and operated by the test library.
So how to use keywords? First we need to import the test library! ! !
Step 4: Add lib. The test libraries that need to be applied this time are all in the screenshots. In fact, you can also use the urllib2 library to obtain url content information
ps: Both json and requests are libraries imported by python! (queryPrdodcut.py is a library packaged by me personally)
You can query the methods under lib through F5, and choose which one to use to see which one you need to use
Step 5, method application, press and hold ctrl to introduce the method
Step 6: Output a case of a scene, the following is a case created by me personally (currently the case output by the third library and my own method)
1.set variable means to set a variable 2. catenate means to assemble multiple parameters together 3.requests.get means to use the resquests library to obtain a response through a get request4.should be qeual as strings means whether it is equal to the expected value is an assertion
5.log means to view the content
Special Note: This method can use rep.status_code and rep.content
Is it cumbersome to use the built-in one? It took so many inputs to complete a request, so I encapsulated a get request library about http (of course checkValue is also a function I personally encapsulated~)
The specific implementation is as follows:
__author__ = 'niuzhigang'
#!/usr/bin/env python
#*- coding: UTF-8 -*-
#encoding=utf-8
import json
import requests
class queryProduct(object):
@classmethod
def interfacetest(self,reqadress,reqinterface,reqc,reqd, floattimeout):
requrl = reqadress + reqinterface
print "print requrl --->"+requrl
header={"content-type":"application/json"}
reqparams = {'c':reqc, 'd': reqd}
reqparam = json.dumps(reqparams,encoding='utf-8',ensure_ascii=False)
print 'print reqparams --->'+reqparam
timeout = float(floattimeout)
# get request result
getrep = requests.get(url=requrl,headers=header, params=reqparams,timeout=timeout)
print "get req result --->"+getrep.text
return getrep.text
So here comes the question? How to use a library defined by yourself? (Specifically how to develop a little basic knowledge of python is enough~ I won't talk about it~)
Next, please personally package the library to play~
PS: The self-encapsulated library can print logs according to your own needs~ the implementation method is to print in the function! ! ! !
Explanation: Why did you write timeout = float(floattimeout)---->timeout to float, because it is a string type after inputting through rf, so it needs to be converted to float
The result of running rf is as follows:
Step 7: View the judgment result, execute the play key or F8
ps The blue ones are all hyperlinks that can be opened, such as: want to see the failure or pass of each specific case ------> click
can be viewed) the results are as follows:
Supplement: At present, only the basic structure of the interface has been implemented, and more will be maintained later, such as sending reports, email WeChat, etc., and more keyword encapsulation~~~
Of course, this also supports ui automation, such as web importing selenium library can realize ui automation
I am also new to rf, I hope you will communicate with each other more in the future! ! !
Friends who are studying for the test can click the small card below