一、UI自动化将local_storage存入yaml 文件,再读取,实现免登陆
local_storage有三个参数
HomeCredit_qa_jwt\HomeCredit_qa_customerName\HomeCredit_qa_customerEmail
# 执行js脚本,获取local_storage中的各个字段?
HomeCredit_qa_jwt = self.driver.execute_script('return window.localStorage.getItem("HomeCredit_qa_jwt");', "HomeCredit_qa_jwt")
HomeCredit_qa_customerName = self.driver.execute_script('return window.localStorage.getItem("HomeCredit_qa_customerName");', "HomeCredit_qa_customerName")
HomeCredit_qa_customerEmail = self.driver.execute_script('return window.localStorage.getItem("HomeCredit_qa_customerEmail");', "HomeCredit_qa_customerEmail")
#因为要存这三个key\value,拼成字典格式?
local_storage = {"HomeCredit_qa_jwt":HomeCredit_qa_jwt,
???????"HomeCredit_qa_customerName":HomeCredit_qa_customerName, "HomeCredit_qa_customerEmail":HomeCredit_qa_customerEmail}
?
#保存到yaml文件中
with open("local_storage.yaml", "w") as f:
# 第一个参数是要写入的数据,第二个字段是要进行数据操作的资源文件
yaml.safe_dump(local_storage, f)
#在basepage中将yaml文件中的local_storage数据读出来
local_storage = yaml.safe_load(open("../config/local_storage.yaml"))
#将local storage的各个值从字典中取出
HomeCredit_qa_jwt = local_storage["HomeCredit_qa_jwt"]
HomeCredit_qa_customerName = local_storage["HomeCredit_qa_customerName"]
HomeCredit_qa_customerEmail = local_storage["HomeCredit_qa_customerEmail"]
#执行js脚本将local_storage的值写入到local_storage中
self.driver.execute_script("localStorage.setItem(arguments[0],arguments[1]);", 'HomeCredit_qa_jwt',HomeCredit_qa_jwt)
self.driver.execute_script("localStorage.setItem(arguments[0],arguments[1]);", 'HomeCredit_qa_customerName',HomeCredit_qa_customerName)
self.driver.execute_script("localStorage.setItem(arguments[0],arguments[1]);", 'HomeCredit_qa_customerEmail',HomeCredit_qa_customerEmail)
总结:
将登陆和存yaml文件步骤,放在config文件夹中
在basepage文件中读取yaml文件中的local storage,这样就可以实现一次登陆多次使用,不用每次执行case都登陆一次
有更好的方法欢迎告知
|