How to use Python to perform simple operations on Excel, which is important for interface automation testing
A. Prepare a JSON document in the following format:
{
"Register": {"mobile": "15500000090"},
"Login": {"mobile": "15500000090", "Password": "111111"}
}
1. You may be confused, this format and normal JSON format a little different, the general JSON string is this {"mobile": "15500000090"}
* Written in the above format is mainly to wrap a JSON string, which reduces a lot of code, you can read "register" or "login" in the part of the code, read the real content is contained in the back of the JSON string.
# Coding=utf-8
#ReadJsonContent
Import JSON
ClassOperationjson:
Def__INIT__ (Self):
Self.data =Self.read_data ()
#ReadJsonFile
DefRead_data (Self):
with open ( ". \dataconfig\mobile.json ') as fp:
data = json.load (FP)
return data
# get data by keyword
def get_data (self return Self.data[id]
if __name__ = ' __main__ ':
Opjson = Operationjson ()
print opjson.get_data ( " Login ')
2. We take two steps, the first step is to read the JSON file, the second step through the keyword to get the data content
Two. Allow the script as shown:
Successfully read to JSON string contents
Interface Automation test Python (3) _ Use Python to manipulate JSON