标签:fir osi 路径 HCL layui mission work perm ext
import time
from lib.pyse import Pyse
‘‘‘
# PageObject思想:将一个页面抽象成一个类,将这个页面上能够操作的元素,抽象成一个个的方法
# 好处:已封装好的模块,要修改的时候,就可以定位到某一块代码的地方
‘‘‘
#方法和思路,以及需要注意的点:
#1、当存在很多个类的时候,按照顺序从上到下依次继承,b继承a,c继承b,d集成c...
#2、一个页面是一个类,每个页面里面的任意一个操作都是一个方法
#3、每个页面结束之后,都要进行一个校验,看页面跳转之后页面的某个元素是否存在,比如登录成功之后,退出按钮是否存在
#4、如果某个元素定位不到的时候,就写全定位地址tmp=‘css=>#horizontal>div>div>ul>li[id="00000000000000000000000000000000"]‘,不要只写li[id="00000000000000000000000000000000"]
#5、调试过程中,当不知道为什么报错的时候,如何确定是不是定位元素的问题:
# print(self.pyse.wait_and_save_exception(tmp1,‘hehehe‘)),看打印的是true还是false,即可以判断有没有定位错误
#思路:
####1、page.py:用来存放页面的类和一个个操作的方法
#1、公用类里面放初始函数,用来选择浏览器
#2、公用类里面的open函数,用来放访问地址url——初始函数和open被test_zbox.py用例脚本的setUpClass调用
#3、公用类里面的quit函数,用来访问结束后退出——被test_zbox.py用例脚本的tearDownClass调用
###2、test_zbox.py:用来放测试用例,比如登录用例,提bug用例
###3、lib下放一个path.py:专门来存放基本的路径,比如用例路径、报告路径、错误图片路径
###4、run.py就是main.py,专门用来执行所有的用例,以及运行之后的结果存在测试报告当中
class BasePage(object): #放一些公用方法的类
def __init__(self):
self.pyse=Pyse(‘chrome‘) #pyse中默认是firefox,所以这里需要定义chrome
def open(self): #打开url
self.pyse.open(‘http://hf.zhuofansoft.com:8301/sxgov_mysql/‘)
def quit(self): #使用完后退出url页面
self.pyse.quit()
class LoginPage(BasePage): #页面的类
def sendUsername(self):
tmp=‘css=>#loginCode‘
self.pyse.type(tmp,‘admin‘)
def sendPasswd(self):
tmp = "css=>#loginPassword"
self.pyse.type(tmp,‘123‘)
def clickLogin(self):
tmp = ‘css=>#submitButton‘
self.pyse.click(tmp)
def checkLogin(self,name): #登录页面校验的方法:看登录成功之后的页面的某个元素是否能定位到,比如只有登录成功之后才有退出按钮
tmp0=‘css=>[src="systemIndex.do"]‘
self.pyse.switch_to_frame(tmp0)
tmp=‘css=>a[lay-href="getMenuList.do?permission=402881f95b4b1209015b4c0d15080157"]‘
return self.pyse.wait_and_save_exception(tmp,name) #pyse里面这个就是正确时返回true,失败时截图操作
class JczcPage(LoginPage):
def clickJczc(self):
tmp = ‘css=>a[lay-href="getMenuList.do?permission=402881f95b4b1209015b4c0d15080157"]‘
self.pyse.click(tmp)
class YhglPage(JczcPage):
def Yhclick(self):
self.pyse.switch_to_frame_out()
tmp0=‘css=>[src="getMenuList.do?permission=402881f95b4b1209015b4c0d15080157"]‘
self.pyse.switch_to_frame(tmp0)
tmp=‘css=>#menu_list>ul>li[id="402881f95b4b1209015b4c14115c017d"]‘
# print(self.pyse.wait_and_save_exception(tmp,‘用户管理‘))
self.pyse.click(tmp)
def zengjia(self):
tmp0=‘css=>[src="sys/user/list.do"]‘
self.pyse.switch_to_frame(tmp0)
tmp1=‘css=>a[class="btn btn-primary"]‘
self.pyse.click(tmp1)
class Yhinfo(YhglPage): #填bug信息页面的类
def name(self): #所属模块,从父级指向下级a,父级定位唯一,在tmp12中会唯一获取到
self.pyse.switch_to_frame_out()
tmp0=‘css=>#_DialogFrame_0‘
self.pyse.switch_to_frame(tmp0)
tmp1=‘css=>#name‘
self.pyse.type(tmp1,‘张三6‘)
def birthdate(self):
tmp0=‘css=>#birthdate‘
self.pyse.click(tmp0)
self.pyse.switch_to_frame_out()
tmp1=‘css=>[hidefocus="true"]‘
self.pyse.switch_to_frame(tmp1)
tmp2=‘css=>tr>td[class="Wselday"]‘
self.pyse.click(tmp2)
def sex(self):
self.pyse.switch_to_frame_out()
tmp0=‘css=>#_DialogFrame_0‘
self.pyse.switch_to_frame(tmp0)
tmp1=‘css=>.sexual>div>ins[class="iCheck-helper"]‘
self.pyse.click(tmp1)
def cardNo(self):
tmp=‘css=>#cardNo‘
self.pyse.type(tmp,‘456789199911112222‘)
def mobile(self):
tmp=‘css=>#mobile‘
self.pyse.type(tmp,‘15812345678‘)
def telphone(self):
tmp=‘css=>#telphone‘
self.pyse.type(tmp,‘021-1234567‘)
def position(self): #领导
tmp=‘css=>#position‘
self.pyse.select_by_value(tmp,‘402882285f6ff04e015f700f4e1b0012‘)
def email(self):
tmp=‘css=>#email‘
self.pyse.type(tmp,‘1@1.com‘)
def sort(self):
tmp=‘css=>#sort‘
self.pyse.type(tmp,‘1‘)
def type(self):
tmp=‘css=>#type‘
self.pyse.select_by_value(tmp,‘4028800b58cc8b450158ccd500ce0004‘)
def districtName(self):
tmp=‘css=>#districtName‘
self.pyse.click(tmp)
tmp1=‘css=>.input-group>div>ul>ul>li>a[id="districtTree_1_a"]‘
self.pyse.click(tmp1)
def organName(self):
tmp1=‘css=>td[class="table_text form-group"]>div>input[id="organName"]‘
self.pyse.click(tmp1)
tmp2=‘css=>td[class="table_text form-group"]>div>div>ul>ul>li>a[id="sysOrganTree_11_a"]‘
self.pyse.click(tmp2)
def shuli(self):
tmp=‘css=>.table_text>div[class="iradio_square-green"]>ins[class="iCheck-helper"]‘
# tmp=‘css=>#manage>form>div>table>tbody>tr>td>div[class="iradio_square-green"]>ins[class="iCheck-helper"]‘
# print(self.pyse.wait_and_save_exception(tmp,‘梳理没有定位到‘))
self.pyse.click(tmp)
def square_green(self):
tmp=‘css=>tr[class="work-list"]>td[class="table_text"]>ul>span>div>ins[class="iCheck-helper"]‘
self.pyse.click(tmp)
def qdgl(self):
# tmp=‘css=>div[class="sexual"]>label [class]>div[class="icheckbox_square-green"]>input[value="2c98cbab6ae66587016ae73b51f2002f"]‘
# tmp=‘xpath=>//tbody[@id="tbody1"]/tr/td/div/label/div/input[@value="2c98cbab6ae0f3a6016ae11487c60000"]‘
# tmp=‘css=>tr[id="workList"]>td>table>tbody>tr>td>div>label>div>input[value="2c98cbab6ae0f3a6016ae11487c60000"]‘
# tmp=‘css=>input[value="2c98cbab6ae66587016ae73b51f2002f"]‘
# tmp=‘css=>table[class="table"]>tbody>tr>td>div>label>div>ins[class="iCheck-helper"]‘
# tmp=‘xpath=>//input[@name="roleOid4028829d5a7ea57e015a7eaa9da10001" and @class="minimal" and @value="2c98cbab6ae0f3a6016ae11487c60000"]‘
# tmp=‘xpath=>//tbody[@id="tbody1"]/tr[1]/td[3]/div/label[1]/div/input[@name="roleOid4028829d5a7ea57e015a7eaa9da10001"]‘
tmp=‘xpath=>//tbody[@id="tbody1"]/tr[1]/td[3]/div/label[1]/div‘
# print(self.pyse.wait_and_save_exception(tmp,‘清单没有匹配‘))
self.pyse.click(tmp)
def jczc(self):
tmp=‘xpath=>//tbody[@id="tbody1"]/tr[2]/td[3]/div/label[1]/div‘
# print(self.pyse.wait_and_save_exception(tmp,‘基础匹配‘))
self.pyse.click(tmp)
def account(self):
tmp=‘css=>#account‘
self.pyse.type(tmp,‘zs1234566‘)
def password(self):
tmp=‘css=>#password‘
self.pyse.clear(tmp)
self.pyse.type(tmp,‘zs1234566‘)
def save(self):
tmp=‘css=>div>a[class="layui-layer-btn2"]‘
self.pyse.click(tmp)
def sure(self):
self.pyse.switch_to_frame_out()
tmp=‘css=>#_ButtonOK_1‘
self.pyse.click(tmp)
def checkYhinfo(self,name):
# self.pyse.switch_to_frame_out()
tmp0 = ‘css=>[src="getMenuList.do?permission=402881f95b4b1209015b4c0d15080157"]‘
self.pyse.switch_to_frame(tmp0)
tmp = ‘css=>#menu_list>ul>li[id="402881f95b4b1209015b4c14115c017d"]‘
return self.pyse.wait_and_save_exception(tmp,name)
class Page(Yhinfo):
pass
if __name__==‘__main__‘:
page=Page()
page.open()
page.sendUsername()
page.sendPasswd()
page.clickLogin()
print(page.checkLogin(‘登录失败了‘))
page.clickJczc()
page.Yhclick()
page.zengjia()
page.name()
page.birthdate()
page.sex()
page.cardNo()
page.mobile()
page.telphone()
page.position()
page.email()
page.sort()
page.type()
page.districtName()
page.organName()
page.shuli()
page.square_green()
page.qdgl()
page.jczc()
page.account()
page.password()
page.save()
page.sure()
print(page.checkYhinfo(‘保存失败了‘))
标签:fir osi 路径 HCL layui mission work perm ext
原文地址:https://www.cnblogs.com/zhaoxueying/p/11412127.html