#Login.py
###封装登录系统
# -*- coding:utf8 -*- from base.Base import Base from selenium.webdriver.common.by import By from base.Base import log from base.Base import consoleLog class LoginPage(Base): #登录页面 userName_loc = (By.NAME, 'user_phone') passWord_loc = (By.NAME, 'user_pwd') login_loc = (By.ID, 'login_btn') #退出登录 yes_loc = (By.CSS_SELECTOR,'.l-btn-text') quit_loc = (By.CSS_SELECTOR,'#logout > span') #修改密码 oldpwd_loc = (By.ID,'old_pwd') newpwd_loc = (By.ID,'user_pwd') confirmpwd_loc = (By.ID,'user_pwd_confirm') submit_loc = (By.ID,'submit_btn') @log def login(self, username,password): """登录系统""" self.open('http://isz.ishangzu.com/isz_base/',self.userName_loc,havaFrame=False) self.input_text(self.userName_loc, username) self.input_text(self.passWord_loc, password) self.click(self.login_loc) consoleLog('登录成功') @log def anewLogin(self,username,password): """新增用户重新登录""" self.driver.back() self.click(self.quit_loc) self.click(self.yes_loc) self.login(username,password) self.input_text(self.oldpwd_loc,'isz12345') self.input_text(self.newpwd_loc,'isz1234567') self.input_text(self.confirmpwd_loc,'isz1234567') self.click(self.submit_loc) consoleLog('密码修改完成')
#UserPage.py
###系统用户模块
# -*- coding:utf8 -*- from base.Base import Base from base import Page from selenium.webdriver.common.by import By from base.Base import log from base.Base import consoleLog class UserPage(Base): searchUserMould = { 'user_name_loc' : (By.ID, 'user_name_search'), 'user_phone_loc' : (By.ID, 'user_phone_search'), 'user_dep_loc_1' : (By.CSS_SELECTOR,'#search_panel > table > tbody > tr > td:nth-child(8) > span > span > a'), 'user_dep_loc_2' : (By.CSS_SELECTOR,'body > div:nth-child(9) > div > ul > li > div > span:nth-child(3)'), #部门下拉第一个 'user_post_loc_1' : (By.CSS_SELECTOR,'#search_panel > table > tbody > tr > td:nth-child(10) > span > span > a'), 'user_post_loc_2' : (By.CSS_SELECTOR,'body > div:nth-child(8) > div > div:nth-child(1)'), #岗位下拉第一个 'user_status_loc_1' : (By.CSS_SELECTOR,'#search_panel > table > tbody > tr > td:nth-child(12) > span > span > a'), 'user_status_loc_2' : (By.CSS_SELECTOR,'body > div:nth-child(3) > div > div:nth-child(1)') #用户状态下拉第一个 } addUser_loc = (By.ID,'add_btn') addUserMould = { 'user_name_loc' : (By.CSS_SELECTOR,'#user_name + span > input:nth-child(1)'), 'user_dep_loc' : '.con-conditions > input#dep_id', 'user_phone_loc' : (By.CSS_SELECTOR,'#user_phone + span > input:nth-child(1)'), 'user_post_loc' : 'input#position_id', 'user_role_loc' : 'input#role_id', 'user_mail_loc' : (By.CSS_SELECTOR,'#user_email + span > input:nth-child(1)'), 'submit_loc' : (By.ID,'submit_btn') } @log def addUser(self,username,userphone,userpost,userrole,usermail): """新增用户""" self.open(Page.userPage,self.addUser_loc,havaFrame=False) self.click(self.addUser_loc) self.input_text(self.addUserMould['user_name_loc'],username) self.type_combotree(self.addUserMould['user_dep_loc'],'00000000000000000000000000000000') self.input_text(self.addUserMould['user_phone_loc'],userphone) self.type_select(self.addUserMould['user_post_loc'],userpost) self.type_select(self.addUserMould['user_role_loc'],userrole) self.input_text(self.addUserMould['user_mail_loc'],usermail) self.click(self.addUserMould['submit_loc']) Base.succeed += 1 self.check_submit() consoleLog('新增用户成功')