python2.7基於selenium的web自動化測試專案--user目錄
阿新 • • 發佈:2019-01-06
#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('新增使用者成功')