RF用例編寫,及注意事項
阿新 • • 發佈:2018-12-04
知識點:
-
1.介面文件裡面classlist的[{“id”:230},{“id”:231}]是json格式的字串,最終rf中輸入傳參的時候是可以這樣[{“id”:230},{“id”:231}]寫的,但是這樣寫對QA編寫用例的人來說,這樣寫有點複雜,最好就是將id傳給介面就行,類似於230,,231這樣。現在就是要把230,,231這種格式轉化為[{“id”:230},{“id”:231}]的json格式
如何把這種格式230,,231轉化為[{“id”:230},{“id”:231}] -
圖1 ,先通過列表生成式,將230,,231構建成[{“id”:230},{“id”:231}]。 newClassList =
[{“id”:oneid} for oneid in classlist.split(",") if oneid]
newClassList = [{“id”:oneid} for oneid in “1,2,3,4,5,6,7,8,9”.split(",") if oneid]
#結果:[{‘id’: ‘1’}, {‘id’: ‘2’}, {‘id’: ‘3’}, {‘id’: ‘4’}, {‘id’: ‘5’}, {‘id’: ‘6’}, {‘id’: ‘7’}, {‘id’: ‘8’}, {‘id’: ‘9’}]
涉及到的用例:
程式碼:
import requests from cfg import g_vcode from pprint import pprint from robot.api import logger from robot.libraries.BuiltIn import BuiltIn class SchoolClassLib: #通常用類實現關鍵字型檔,類名和檔名相同 URL = "http://ci.ytesting.com/api/3school/school_classes" #可以寫在類的靜態屬性裡面,也可以寫在cfg的變數檔案裡面 def __init__(self): #定義一個初始化方法 self.vcode = g_vcode #也可以直接用全域性的變數g_vcode def set_vcode(self,vcode): self.vcode = vcode def delete_school_class(self,classid): #刪除班級 payload = { 'vcode' : self.vcode, } url = '{}/{}'.format(self.URL,classid) #url加上id,這裡是這樣構建一下 response = requests.delete(url,data=payload) return response.json() def list_school_class(self,gradeid=None): #列出班級 if gradeid != None: #gradeid是可填可不填的,預設是none params = { #如果傳gradeid 'vcode':self.vcode, 'action':'list_classes_by_schoolgrade', 'gradeid':int(gradeid) } else: params = { 'vcode':self.vcode, #如果不傳 'action':'list_classes_by_schoolgrade' } response = requests.get(self.URL,params=params) #params就是url請求的引數 bodyDict = response.json() #文件裡規定響應是json格式的訊息體。.json可以把json字串轉化為py中的物件。得到的是一個字典 # pprint (bodyDict,indent=2) #indent引數就是指定pprint打印出來的引數是兩個 logger.debug(f"ret:\n{bodyDict}") #通常的執行就不顯示了,報錯的時候顯示所有 return bodyDict def add_school_class(self,gradeid,name,studentlimit,idSavedName=None): #新增班級 #最後一個引數就是給新增班級返回的id賦值的變數取一個名字 #這個引數只有一個場景有用(初始化清除),大部分場景都沒有用。這是應該用預設引數 payload = { 'vcode' : self.vcode, 'action' : 'add', 'grade' : int(gradeid), 'name' : name, 'studentlimit' : int(studentlimit), } response = requests.post(self.URL,data=payload) bodyDict = response.json() pprint (bodyDict,indent=2) #logger.debug(f"ret:\n{bodyDict}") #通常的執行就不顯示了,報錯的時候顯示所有 if idSavedName: #如果傳這個引數 BuiltIn().set_global_variable("${%s}"%idSavedName,bodyDict['id']) #設定全域性變數 return bodyDict #修改班級介面 def modify_school_class(self,classid,newname,newstudentlimit): url = f'{self.URL}/{classid}' #字串拼接url payload = { 'vcode': self.vcode, 'action': 'modify', 'name': newname, 'studentlimit': int(newstudentlimit), } response = requests.put(url,data=payload) bodyDict = response.json() pprint(bodyDict,indent=2) return bodyDict def delete_all_school_classes(self): #初始化清除,要刪除所有的用例 # 先列出所有班級 rd = self.list_school_class() pprint(rd, indent=2) # 刪除列出的所有班級 for one in rd['retlist']: #文件裡面“retlist”:[{},{}] {}裡面是一個個班級,id也在裡面 self.delete_school_class(one['id']) #獲取到id,傳給delete #再列出所有班級 rd = self.list_school_class() pprint (rd,indent=2) # 如果沒有刪除乾淨,通過異常報錯給RF # 參考http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#reporting-keyword-status if rd['retlist'] != []: raise Exception("cannot delete all school classes!!") # def classlist_should_contain(self, # classlist, # classname, # gradename, # invitecode, # studentlimit, # studentnumber, # classid): # item = { # "name":classname, # "grade__name":gradename, # "invitecode":invitecode, # "studentlimit":int(studentlimit), # "studentnumber":int(studentnumber), # "id":classid, # "teacherlist":[] # } # if item not in classlist: # #在rf裡面如果要實現一個檢查點關鍵字,怎麼表示檢查點不通過???就是丟擲異常。 # raise Exception("class list dose not contain your class info") # #裡面的東西隨便寫的 #classlist_should_contain增強版:可能會新增一門課程,多了兩條課程,為了解決這種情況。可以加一個引數指定它包含多少次 def classlist_should_contain(self, classlist, classname, gradename, invitecode, studentlimit, studentnumber, classid, expectedtimes=1): #可以設定一個預設值,不寫的話只應該包含一次 item = { "name":classname, "grade__name":gradename, "invitecode":invitecode, "studentlimit":int(studentlimit), "studentnumber":int(studentnumber), "id":classid, "teacherlist":[] } occurTimes = classlist.count(item) #看occurTimes在列表裡面出現多少次 if occurTimes != expectedtimes: #實際出現的次數和預期的次數是否相等 #在rf裡面如果要實現一個檢查點關鍵字,怎麼表示檢查點不通過???就是丟擲異常。 raise Exception(f"班級列表包含了{occurTimes}次指定資訊,期望包含{expectedtimes}!!") #裡面的東西隨便寫的 def classlist_should_not_contain(self, classlist, classname, gradename, invitecode, studentlimit, studentnumber, classid): item = { "name":classname, "grade__name":gradename, "invitecode":invitecode, "studentlimit":int(studentlimit), "studentnumber":int(studentnumber), "id":classid, "teacherlist":[] } if item in classlist: #如果在裡面的話就會丟擲異常 #在rf裡面如果要實現一個檢查點關鍵字,怎麼表示檢查點不通過???就是丟擲異常。 raise Exception("class list contain your class info") #裡面的東西隨便寫的 if __name__ == '__main__': #除錯用 scm = SchoolClassLib() #ret = scm.list_school_class(2) # ret = scm.add_school_class(1,'新測試',77) # print(json.dumps(ret, indent=2)) # #ret = scm.delete_school_class(63630) # pprint(ret) # print(json.dumps(ret, indent=2)) # # ret = scm.list_school_class(1) # print(json.dumps(ret, indent=2)) # # #scm.delete_all_school_classes() #scm.classlist_should_contain() """ 實現一些個關鍵字 """
import requests,json from cfg import g_vcode from pprint import pprint from robot.api import logger from robot.libraries.BuiltIn import BuiltIn class TeacherLib: #通常用類實現關鍵字型檔,類名和檔名相同 URL = "http://ci.ytesting.com/api/3school/teachers" #可以寫在類的靜態屬性裡面,也可以寫在cfg的變數檔案裡面 def __init__(self): #定義一個初始化方法 self.vcode = g_vcode #也可以直接用全域性的變數g_vcode def set_vcode(self,vcode): self.vcode = vcode def list_teacher(self,subjectid=None): #列出班級 if subjectid != None: #gradeid是可填可不填的,預設是none params = { #如果傳gradeid 'vcode':self.vcode, 'action':'search_with_pagenation', 'subjectid':int(subjectid) } else: params = { 'vcode':self.vcode, #如果不傳 'action':'search_with_pagenation' } response = requests.get(self.URL,params=params) #params就是url請求的引數 bodyDict = response.json() #文件裡規定響應是json格式的訊息體。.json可以把json字串轉化為py中的物件。得到的是一個字典 pprint (bodyDict,indent=2) #indent引數就是指定pprint打印出來的引數是兩個 #logger.debug(f"ret:\n{bodyDict}") #通常的執行就不顯示了,報錯的時候顯示所有 return bodyDict def add_teacher(self,username,realname,subjectid,classlist,phonenumber,email, idcardnumber,idSavedName=None): #新增班級 #最後一個引數就是給新增班級返回的id賦值的變數取一個名字 #這個引數只有一個場景有用(初始化清除),大部分場景都沒有用。這是應該用預設引數 classlist = str(classlist) newClassList = [{"id": oneid} for oneid in classlist.split(",") if oneid] #構建一個列表物件,這裡面的classlist是字串類似於"230,231" payload = { 'vcode' : self.vcode, 'action' : 'add', 'username' : username, 'realname' : realname, 'subjectid' : int(subjectid), 'classlist': json.dumps(newClassList), #json就是一個字串,只不過符合了py程式碼的字串。dumps(newClassList)就變成了,json格式的字串,一dumps就變成了符合json格式的字串 'phonenumber': phonenumber, 'email': email, 'idcardnumber': idcardnumber, } response = requests.post(self.URL,data=payload) bodyDict = response.json() pprint (bodyDict,indent=2) #logger.debug(f"ret:\n{bodyDict}") #通常的執行就不顯示了,報錯的時候顯示所有 if idSavedName: #如果傳這個引數 BuiltIn().set_global_variable("${%s}"%idSavedName,bodyDict['id']) #設定全域性變數,把返回結果的id存到一個變數裡面 return bodyDict #修改老師介面 def modify_teacher(self,teacherid, realname=None, subjectid=None, classlist=None, phonenumber=None, email=None, idcardnumber=None): #=None都是可選的引數,非必填 url = f'{self.URL}/{teacherid}' #字串拼接url payload = { 'vcode': self.vcode, 'action': 'modify', } if realname is not None: payload["realname"] = realname if subjectid is not None: payload["subjectid"] =int(subjectid) if phonenumber is not None: payload["phonenumber"] = phonenumber if email is not None: payload["email"] = email if idcardnumber is not None: payload["idcardnumber"] = idcardnumber #'1,2,3' if classlist is not None: newClassList = [{"id": oneid} for oneid in classlist.split(",") if oneid] payload["classlist"] = json.dumps(newClassList) response = requests.put(url,data=payload) bodyDict = response.json() pprint(bodyDict,indent=2) return bodyDict #刪除老師 def delete_teacher(self,teacherid): #刪除老師 payload = { 'vcode' : self.vcode, } url = '{}/{}'.format(self.URL,teacherid) #url加上id,這裡是這樣構建一下 response = requests.delete(url,data=payload) bodyDict = response.json() pprint(bodyDict, indent=2) return bodyDict #刪除所有老師 def delete_all_teachers(self): #初始化清除,要刪除所有的用例 # 先列出所有班級 rd = self.list_teacher() pprint(rd, indent=2) if rd["retcode"] !=0: #列出老師的介面如果不是正常返回0,就拋異常 raise Exception("cannot list teachers!!!") # 刪除列出的所有老師 for one in rd['retlist']: #文件裡面“retlist”:[{},{}] {}裡面是一個個班級,id也在裡面 self.delete_teacher(one['id']) #獲取到id,傳給delete #再列出所有老師 rd =self.list_teacher() pprint (rd,indent=2) # 如果沒有刪除乾淨,通過異常報錯給RF # 參考http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#reporting-keyword-status if rd['retlist'] != []: raise Exception("cannot delete all school classes!!") # def classlist_should_contain(self, # classlist, # classname, # gradename, # invitecode, # studentlimit, # studentnumber, # classid): # item = { # "name":classname, # "grade__name":gradename, # "invitecode":invitecode, # "studentlimit":int(studentlimit), # "studentnumber":int(studentnumber), # "id":classid, # "teacherlist":[] # } # if item not in classlist: # #在rf裡面如果要實現一個檢查點關鍵字,怎麼表示檢查點不通過???就是丟擲異常。 # raise Exception("class list dose not contain your class info") # #裡面的東西隨便寫的 #classlist_should_contain增強版:可能會新增一門課程,多了兩條課程,為了解決這種情況。可以加一個引數指定它包含多少次. def teacherlist_should_contain(self, teacherlist, username, realname, id, teachclasslist, phonenumber, email, idcardnumber, expectedtimes=1): #可以設定一個預設值,不寫的話只應該包含一次 #1,2,3 確保是字串,而不是整數 teachclasslist = str(teachclasslist) item = { "username":username, "realname":realname, "id":int(id), "teachclasslist":[int(one) for one in teachclasslist.split(",")], #要符合介面文件裡面[230,231],傳進來是1,2,3的格式 "phonenumber":phonenumber, "email":email, "idcardnumber":idcardnumber } occurTimes = teacherlist.count(item) #看occurTimes在列表裡面出現多少次 logger.info("occur {} times".format(occurTimes),also_console=True) #列印到介面上,列印到日誌裡面 if occurTimes != expectedtimes: #實際出現的次數和預期的次數是否相等 #在rf裡面如果要實現一個檢查點關鍵字,怎麼表示檢查點不通過???就是丟擲異常。 raise Exception("teacherlist list contain your teacher info {} times,expect {} times,expect{}times!!".format(occurTimes,expectedtimes)) #裡面的東西隨便寫的 # def classlist_should_not_contain(self, # classlist, # classname, # gradename, # invitecode, # studentlimit, # studentnumber, # classid): # item = { # "name":classname, # "grade__name":gradename, # "invitecode":invitecode, # "studentlimit":int(studentlimit), # "studentnumber":int(studentnumber), # "id":classid, # "teacherlist":[] # } # if item in classlist: #如果在裡面的話就會丟擲異常 # #在rf裡面如果要實現一個檢查點關鍵字,怎麼表示檢查點不通過???就是丟擲異常。 # raise Exception("class list contain your class info") # #裡面的東西隨便寫的 # if __name__ == '__main__': #除錯用 scm = TeacherLib() #ret = scm.list_school_class(2) # ret = scm.add_school_class(1,'新測試',77) # print(json.dumps(ret, indent=2)) # #ret = scm.delete_school_class(63630) # pprint(ret) # print(json.dumps(ret, indent=2)) # # ret = scm.list_school_class(1) # print(json.dumps(ret, indent=2)) # # #scm.delete_all_school_classes() #scm.classlist_should_contain() """ 實現一些個關鍵字 """
*** Settings ***
Library pylib.TeacherLib
Variables cfg.py
Suite Setup add teacher tuobagui 拓跋珪
... ${g_subject_math_id}
... ${suite_g7c1_classid}
... 13002021526 [email protected] 3208821966
... suite_math_teacher_id
Suite Teardown delete teacher ${suite_math_teacher_id}
#先建立一個老師在刪除
#${g_subject_math_id}
*** Settings ***
Library pylib.TeacherLib
Variables cfg.py
*** Test Cases ***
新增老師2 - tc001002
${addRet}= add_teacher murongba 慕容霸
... ${g_subject_science_id}
... ${suite_g7c1_classid}
#上面是所教班級id
... 13002021501 [email protected] 3208821902
should be true $addRet['retcode']==0
${listRet}= list_teacher
teacherlist should contain &{listRet}[retlist]
... murongba 慕容霸 &{addRet}[id]
... ${suite_g7c1_classid}
... 13002021501 [email protected] 3208821902
[Teardown] delete_teacher &{addRet}[id]
新增老師3 - tc001003
${listRet1}= list teacher
${addRet}= add_teacher tuobagui 拓跋珪
... ${g_subject_science_id}
... ${suite_g7c1_classid}
#上面是所教班級id
... 13002021501 [email protected] 3208821902
should be true $addRet['retcode']==1
should be true $addRet['reason']=="登入名 tuobagui 已經存在"
${listRet2}= list_teacher
should be equal ${listRet1} ${listRet2}
刪除老師1 - tc001081
#刪除一個id號不存在的老師
#列出老師
${listRet1}= list teacher
#刪除老師,不存在的ID
${delRet}= delete teacher 99999999
should be true $delRet['retcode']==404
should be true $delRet['reason']=="id 為`99999999`的老師不存在"
#列出老師,檢驗一下
${listRet2}= list teacher
should be equal ${listRet1} ${listRet2}
刪除老師2 - tc001082
#刪除一個存在的id,不能刪除資料環境裡面的環境
#列出老師
${listRet1}= list teacher
# 新增 老師 教7年級1班 科學
${addRet}= add teacher murongke 慕容恪
... ${g_subject_science_id}
... ${suite_g7c1_classid}
... 13000000110 [email protected] 320520110
should be true $addRet['retcode']==0
#刪除老師
delete teacher &{addRet}[id]
#列出老師,檢驗一下
${listRet2}= list teacher
should be equal ${listRet1} ${listRet2}
#第一種方法,相當於手動設定一個全域性變數
#*** keywords ***
#suite setup action
# ${ret}= add_school_class 1 1班 60
# set global variable ${suitesetclassid} &{ret}[id]
#*** Settings ***
#Library pylib.SchoolClassLib
#Suite Setup suite setup action
#Suite Teardown delete_school_class ${suitesetclassid}
#解釋
#設定一個全域性變數,新增的課程的響應返回值裡面的id
# set global variable是設定的全域性的
# set suit variable是設定的這個套件的
#第二種方法,因為升級了add_school_class這個關鍵字,關鍵字內部可以直接生成一個全域性變數。一旦add_school_class的傳值有suite_g7c1_classid,就會有一個全域性變數suite_g7c1_classid
*** Settings ***
Library pylib.SchoolClassLib
Suite Setup add school class 1 1班 60 suite_g7c1_classid
Suite Teardown delete_school_class ${suite_g7c1_classid}
#最後一個引數,如果新增課程正好用在環境的初始化上面,可以用最後一個引數指定一個全域性變數的名字,id是多少,把它儲存到一個全域性變數裡面,這個變數是rf的指令碼用的。方便後面使用這個初始化環境新增的id
#測試套件目錄 執行結束後,要和執行前一致
#測試套件檔案 執行結束後,要和執行前一致
#測試套件用例 執行結束後,要和執行前一致
#這個檔案裡面是實現新增一個7年級1班的初始化
#實現的用例是建立一個班級,系統中不存在同年級的同名班級
#1是代表7年級,1班,上限不超過60人
#核心就是為了設定一個全域性變數,解決了棘手的問題:套件的初始化話,變數沒辦法存下來的問題
#還有就是初始化裡面建立的資料要留給後面用,動態產生的東西,就這樣儲存下來給後面用
#set_global_variable 全域性有效
#set_suite_variable 當前的套件有效,就像d-7年級1班裡面的所有的子套件,子用例都有效。通常要限制範圍就用set_suite_variable
#set_test_variable 只對當前的用例有效。通常是在用例裡面,用的不對。
*** Settings ***
Library pylib.SchoolClassLib
*** Test Cases ***
#新增班級2 - tc000002
# ${ret1}= add school class 1 2班 60
# should be true $ret1['retcode']==0
#
##列出班級,和新增的班級檢驗一下,id一致,邀請碼一致
# ${ret2}= list school class 1
# should be true {'name': '2班', 'grade__name': '七年級', 'invitecode': $ret1['invitecode'], 'studentlimit': 60, 'studentnumber': 0, 'id': $ret1['id'], 'teacherlist': []}in $ret2['retlist']
##列出班級的響應是這樣的:(見圖文件規定)
##rf的寫法實在不是容易的事情,rf不擅長處理複雜的資料,不能換行。
##最好是通過其他的方法來實現
# [Teardown] delete_school_class &{ret1}[id]
##&{ret1}是新增課程產生的字典,取出id刪掉
#第二種簡單,方便,基於py的寫法,用關鍵字實現。
新增班級2 - tc000002
${ret1}= add school class 1 2班 60
should be true $ret1['retcode']==0
#驗證狀態碼是不是0
#列出班級,檢驗一下
${ret2}= list school class 1
${retlist}= evaluate $ret2['retlist']
#把響應裡面的retlist取出來,賦值到變數裡面
classlist should contain ${retlist}
... 2班 七年級 &{ret1}[invitecode] 60 0 &{ret1}[id]
#...是換行,後面傳的都是引數,$ret1['invitecode']不是py表示式,所以裡面不能加引號,從字典裡面取資料用&
#實現一個關鍵字,判斷${retlist}裡面是否包含2班,七年級。。。這些內容。
[Teardown] delete_school_class &{ret1}[id]
#&{ret1}是新增課程產生的字典,取出id刪掉
新增班級3 - tc000003
${ret1}= add school class 1 1班 60
#這裡建立的和資料環境裡面的是一樣的,滿足建立一個已有的同名的課程
#should be true $ret1=={"retcode":1,"reason":"duplicated class name"}
#根據文件判斷返回值,可以向上面一樣寫,不能有兩個以上的空行,安全起見,也可以分開寫
should be true $ret1["retcode"]==1
should be true $ret1["reason"]=="duplicated class name"
#列出班級,檢驗一下
${ret2}= list school class 1
${retlist}= evaluate $ret2['retlist']
#實現關鍵字classlist should not contain ,列出的列表裡面不包含下面的資訊(就是新增的資訊)
classlist should not contain ${retlist}
... 1班 七年級 &{ret1}[invitecode] 60 0 &{ret1}[id]
#[Teardown]清除的操作就不要了,應該是新增不成功的。也沒法根據id來刪除
修改班級1 - tc000051
#新增7年級2班
${ret1}= add school class 1 2班 60
should be true $ret1['retcode']==0
${classid}= evaluate $ret1["id"]
#修改為7年級222班
${modifyRet}= modify_school_class ${classid} 222班 60
should be true $modifyRet['retcode']==0
#列出班級,檢驗一下
${ret2}= list school class 1
${retlist}= evaluate $ret2['retlist']
#把響應裡面的retlist取出來,賦值到變數裡面
classlist should contain ${retlist}
... 222班 七年級 &{ret1}[invitecode] 60 0 &{ret1}[id]
[Teardown] delete_school_class ${classid}
修改班級2 - tc000052
#新增7年級2班
${ret1}= add school class 1 2班 60
should be true $ret1['retcode']==0
${classid}= evaluate $ret1["id"]
#先列出班級
${listret1}= list school class 1
#修改為7年級1班
${modifyRet}= modify_school_class ${classid} 1班 60
should be true $modifyRet['retcode']==1
should be true $modifyRet["reason"]=="duplicated class name"
#再列出班級,和之前列出的班級比較下,是一樣的話,就說明修改沒有成功。就是正確的
${listret2}= list school class 1
should be equal ${listret1} ${listret2}
[Teardown] delete_school_class ${classid}
#這個用例執行不通過,就是系統的bug,返回的狀態碼是10000
修改班級3 - tc000053
#修改id號不存在的班級,可以寫一個很大的數字
${modifyRet}= modify_school_class 9999 1班 60
should be true $modifyRet["retcode"]==404
should be true $modifyRet['reason']=='id 為`9999`的班級不存在'
# log to console ${modifyRet} 可以打印出來看看,9999上面的符號有點坑
刪除班級1 - tc000081
#刪除id號不存在的班級,也可以寫一個很大的數字
${delRet}= delete school class 9999
should be true ${delRet}["retcode"]==404
should be true ${delRet}['reason']=='id 為`9999`的班級不存在'
# log to console ${modifyRet} 可以打印出來看看,9999上面的符號有點坑
刪除班級2 - tc000082
#新增7年級2班
${ret1}= add school class 1 2班 60
should be true $ret1['retcode']==0
${classid}= evaluate $ret1["id"]
#先列出班級
${listret1}= list school class 1
${retlist}= evaluate $listret1["retlist"]
classlist should contain ${retlist}
... 2班 七年級 &{ret1}[invitecode] 60 0 &{ret1}[id]
#刪除為7年級2班
${delRet}= delete school class ${classid}
should be true $delRet['retcode']==0
#列出班級,檢驗一下
${listret2}= list school class 1
${retlist}= evaluate $listret2['retlist']
#把響應裡面的retlist取出來,賦值到變數裡面
classlist_should_not_contain ${retlist}
... 2班 七年級 &{ret1}[invitecode] 60 0 &{ret1}[id]
*** Settings ***
Library pylib.TeacherLib
Variables cfg.py
*** Test Cases ***
新增老師1 - tc001001
${addRet}= add_teacher tuobagui 拓跋珪
... ${g_subject_math_id}
... ${suite_g7c1_classid}
#上面是所教班級id
... 13002021526 [email protected] 3208821966
should be true $addRet['retcode']==0
${listRet}= list_teacher
teacherlist should contain &{listRet}[retlist]
... tuobagui 拓跋珪 &{addRet}[id]
... ${suite_g7c1_classid}
... 13002021526 [email protected] 3208821966
[Teardown] delete_teacher &{addRet}[id]
*** Settings ***
Library pylib.SchoolClassLib
Library pylib.TeacherLib
Suite Setup Run Keywords delete all teachers AND
... delete_all_school_classes
#老師和班級,先刪除老師。才能刪除班級。文件裡面有
*** Settings ***
Library pylib.SchoolClassLib
*** Test Cases ***
新增班級1 - tc000001
${ret1}= add school class 1 1班 60
should be true $ret1['retcode']==0
#列出班級,和新增的班級檢驗一下,id一致,邀請碼一致
${ret2}= list school class 1
${fc}= evaluate $ret2['retlist'][0]
should be true $fc['id']==$ret1['id']
should be true $fc['invitecode']==$ret1['invitecode']
#將垃圾資料清除掉,不要破壞空白資料環境
[Teardown] delete_school_class &{ret1}[id]
#&{ret1}是新增課程產生的字典,取出id刪掉
g_vcode = '00000002775300822470'
g_subject_math_id = 1 #學科數學的id是1,可讀性更好
g_subject_science_id = 5
g_grade_7_id = 1 #7年級的id是1,可讀性更好
"""
全域性的變數可以g-開頭
"""