class SysManage(Page): ''' 系统管理 ''' sysmanage=PageElement(xpath="/html/body/div/div[1]/div/div[4]/div[12]/p/span[2]", describe="系统管理", timeout=2) import_log=PageElement(xpath="/html/body/div/div[1]/div/div[4]/div[12]/div[1]/p/span", describe="导入记录", timeout=2) count = PageElement(xpath='//*[@id="dataCon"]/div/div[3]/div[2]/div/span[2]', describe="条数统计", timeout=2)
class Evaluationpage(Page): #智能测评 #介绍页 join_loc = PageElement( xpath='//*[@id="root"]/div/div/div[2]/div[3]/a/span') #选择年级 grades = PageElements(xpath='//*[@id="root"]/div/div/ul/li') #下一步 next_loc = PageElement(xpath='//*[@id="root"]/div/div/div[3]/a/span') #题目选项 selects_loc = PageElements( xpath='//*[@id="root"]/div/div/div[2]/div[2]/div') #提交按钮 commit_loc = PageElement(xpath='//*[@id="root"]/div/div/div[4]/a') def start(self): self.join_loc.click() def first_step(self): time.sleep(5) grade = random.choice(self.grades) grade.click() time.sleep(1) self.next_loc.click() def second_step(self): for i in range(20): time.sleep(1) select = random.choice(self.selects_loc) select.click() Evaluationpage(self.driver) self.commit_loc.click()
class ArticlePage(Page): news_contaner = PageElement( id_='com.transsnet.news.more:id/fl_news_content') back_btn = PageElement(id_='com.transsnet.news.more:id/img_back') read_mod_btn = PageElement(id_='com.transsnet.news.more:id/tv_read_mode') web_mod_container = PageElement( id_='com.transsnet.news.more:id/fl_news_content')
class Resultpage(Page): #测试结果页 #重新测评 re_loc = PageElement(xpath='//*[@id="root"]/div/div/div[1]/a') #调整计划 adjust_loc = PageElement(xpath='//*[@id="root"]/div/div/div[4]/a') #开通AI乐学 open_loc = PageElement(css='#root > div > div > div.btn_box > a') def reevaluation(self): self.re_loc.click() time.sleep(5) Evaluationpage(self.driver).first_step() Evaluationpage(self.driver).second_step() def adjustplan(self): Resultpage(self.driver) time.sleep(3) self.adjust_loc.click() time.sleep(5) Adjustplanpage(self.driver).adjust() def open(self): Resultpage(self.driver) self.open_loc.click() time.sleep(3) Topaypage(self.driver).topay()
class LoginIndexPage(Page): username_input = PageElement( xpath='/html/body/div/div/form/div[2]/div/div[1]/input') password_input = PageElement( xpath='/html/body/div/div/form/div[3]/div/div/input') login_button = PageElement( xpath='/html/body/div/div/form/div[4]/div/button') erro_hint_loc = PageElement(class_name='el-form-item__error') erro_hint_two = PageElement(xpath='/html/body/div[2]/p') # page.username_input.send_keys("") # page.password_input.send_keys("11") # page.login_button.click() #登录 def login_action(self, username, password): self.username_input.send_keys(username) self.password_input.send_keys(password) self.login_button.click() ##登录失败(断言) def type_loginFail_hint1(self): return self.erro_hint_loc.text ##登录失败(断言) def type_loginFail_hint2(self): return self.erro_hint_two.text
class DemoPage(Page): single_way = PageElement(xpath='//*[@id="searchTypeSng"]') from_city = PageElement( xpath='//*[@id="dfsForm"]/div[2]/div[1]/div/input') # 出发城市 to_city = PageElement( xpath='//*[@id="dfsForm"]/div[2]/div[2]/div/input') # 到达城市 from_date = PageElement(xpath='//*[@id="fromDate"]') # 出发时间
class GuidPage(Page): skip_btn = PageElement(id_='com.transsnet.news.more:id/skip') topic_btn_list = PageElements( xpath= '//*[@id="com.transsnet.news.more:id/recycler"]//*[@id="com.transsnet.news.more:id/name"]' ) confirm_btn = PageElement(id_='com.transsnet.news.more:id/select_btn')
class Xiaolepage(Page): send_loc = PageElement(class_name='send_btn') input_loc = PageElement(class_name='inputQuertion') question_loc = PageElement( xpath= '/html/body/div[1]/div/div/div[4]/div/div[2]/div[2]/div[7]/div/div/p[2]' ) suggest_loc = PageElement( xpath= '/html/body/div[1]/div/div/div[4]/div/div[2]/div[2]/div[7]/div/div/p[3]' ) answer_loc = PageElement(class_name='click_btn') def question(self, qa): #提问 self.question_loc.click() self.input_loc = qa self.send_loc.click() def get_answer(self): #return str(self.send_loc.text) #print(str(self.send_loc.text)) #print(str(self.answer_loc.text)) return str(self.answer_loc.text) def suggest(self): #提建议 pass
class BaiduPage(Page): search_input = PageElement(id_="kw", describe="搜索框") search_button = PageElement(id_="su", describe="搜索按钮") settings = PageElement(link_text="设置", describe="设置下拉框") search_settings = PageElement(css=".setpref", describe="搜索设置选项") save_settings = PageElement(css=".prefpanelgo", describe="保存设置") search_result = PageElements(xpath="//div/h3/a", describe="搜索结果")
class LoginPage(Page): """ 登录page类 """ username = PageElement(css='#loginAccount', describe="用户名") password = PageElement(css='#loginPwd', describe="密码") login_button = PageElement(css='#login_btn', describe="登录按钮") user_info = PageElement(css="a.nav_user_name > span", describe="用户信息")
class Loginelement(Page): """Please use a locator:'id_'、'name'、'class_name'、'css'、'xpath'、'link_text'、'partial_link_text'.""" username = PageElement(name='username') password = PageElement(name='password') logig = PageElement(css='[type=submit]') assert_succeed = PageElement(id_='myprofile') assert_failed = PageElement(css="font[color='red']")
class BaiduPage(Page): search_input = PageElement(id_='kw', describe='搜索框') search_button = PageElement(id_='su', describe='搜索按钮') settings = PageElement(link_text='设置', describe='设置下拉框') search_setting = PageElement(css='.setpref', describe='搜索设置选项') save_setting = PageElement(css='.prefpanelgo', describe='保存设置') #定位一组元素 search_result = PageElements(xpath='//div/h3/a', describe='搜索结果')
class VipPage(Page): vip_banner = PageElement( css= '#content > div > div.banner > a > img.banner-content.banner-pc-img', describe='会员页banner图') login_input = PageElement(id_='login-email', describe='账号输入框') pwd_input = PageElement(id_='login-password', describe='密码输入框') login_btn = PageElement(css='#login > button', describe='登录按钮') vip = PageElement(css='#card-box-pc > div > header > div > div > div > a', describe='加入课程')
class Select_Page(Page): search_move = PageElement(xpath='//*[@id="u1"]/a[9]', log=True, describe='悬停至设置按钮') search_s = PageElement(css='.setpref[href^=javas]', log=True, describe='搜索设置按钮') search_results = PageElement(css='td>select[id=nr]', log=True, describe='搜索结果显示条目') search_savebutton = PageElement(css='div>a[class$=elgo]', log=True, describe='保存按钮') search_input = PageElement(css='.s_ipt', log=True, describe='') search_button = PageElement(xpath="//input[@id='su']", log=True, describe='百度一下按钮') search_id10 = PageElement(xpath="//*[@id='10']", log=True, describe='搜索条目为10') search_id20 = PageElement(xpath="//*[@id='20']", log=True, describe='搜索条目为20') search_id50 = PageElement(xpath="//*[@id='50']", log=True, describe='搜索条目为50')
class Login(Page): """ 舞泡登录元素封装 """ # 前往登录页面 close_consult_pop = PageElement(xpath='/html/body/div[6]/div/p[2]/img', describe='关闭咨询弹窗') go_login = PageElement(xpath='/html/body/div[5]/footer/div/a[4]/p', describe='前往登录页') def m5pao_go_login(self): self.go_login.click() # 登录页元素封装 login_username_loc = PageElement(id_='username', describe='用户名') login_password_loc = PageElement(id_='password', describe='密码') login_code_loc = PageElement(id_='vcode', describe='图片验证码') login_btn_loc = PageElement(xpath='//*[@id="fm1"]/div/div/input[4]', describe='登录按钮') login_go_register_loc = PageElement( xpath='//*[@id="fm1"]/div/div/div[5]/a[1]', describe='前往注册') login_go_forget_password_loc = PageElement( xpath='//*[@id="fm1"]/div/div/div[5]/a[2]', describe='忘记密码') # assert login_msg_hint = PageElement(id_='msg', describe='错误提示')
class Topaypage(Page): # 前往支付 topay_loc = PageElement(xpath='//*[@id="root"]/div/div/div[4]/a') #已拥有平板 own_loc = PageElement(link_text='已拥有') def topay(self): self.topay_loc.click() time.sleep(3) Topaypage(self.driver) self.own_loc.click()
class BaiduPage(Page): """百度page层,百度页面封装操作到的元素""" # url = "https://www.baidu.com/" # # def search_input(self, search_key): # self.by_id("kw").send_keys(search_key) # # def search_button(self): # self.by_id("su").click() search_input = PageElement(id_="kw") search_button = PageElement(id_="su")
class Customer_Manager_Check_Page(Page): """客户经理跟进IB页""" username_input = PageElement(id_='userName', describe='用户名') password_input = PageElement(id_='password', describe='密码') login_button = PageElement(id_='submit', describe='登录') Client_mgmt_a = PageElement(xpath='//*[@id="siderbar"]/dl[1]/dt/a', describe='客户管理') intention_IB = PageElement(xpath='//*[@id="siderbar"]/dl[1]/dd/ul/li[5]/a', describe='意向IB') follow_up_IB = PageElement(xpath='//*[@id="siderbar"]/dl[1]/dd/ul/li[5]/ul/li[1]/a', describe='待跟进IB') IB_username = PageElement(xpath='//*[@id="unfollowIbListBody"]/tr[1]/td[4]/a', describe='IB用户名') IB_info_iframe = PageElement(id_='listDetailFrame', describe='IB信息iframe') IB_grade_select = PageElement(id_='agentType', describe='IB等级') save_button = PageElement(xpath='//*[@id="myform"]/div/input', describe='保存')
class PayeeQuerypage(Page): '''alert弹框''' firstPage_alert = PageElement(xpath="/html/body/div[6]/div/span/div",describe = "电子对账提示框") firstPage_sure_button = PageElement(xpath="/html/body/div[6]/div/span/div/div/div/span/span/button[2]",describe="确定按钮") '''菜单按钮''' firstPage_menu_button = PageElement(xpath="//li[@href='#/Transfer']",describe="转账菜单") '''#####页面对象#####''' '''录入页面''' firstPage_payeequery_input = PageElement(xpath="//input[@data-reactid='.0.0.0.1.1.0.1.0.1.1.0.0.0.0']",describe="账户搜索框") firstPage_payeequery_lists = PageElements(xpath="//div[@class='card-item-inner ']",describe="搜索结果")
class BaiDuPage(Page): """ 百度page层,百度页面封装操作到的元素 """ search_input = PageElement(id_='kw', timeout=10, describe='百度搜索框') search_button = PageElement(id_='su', timeout=5, describe='百度一下按钮') #通过timeout可以添加元素超时时间,默认为10s #通过describe添加元素描述 #定义一组元素 search_result = PageElements(xpath='//div//h3/a') """
class AccountManagement(Page): customer_list = PageElement(xpath="/html/body/div/div[1]/div/div[4]/div[1]/div[2]/p", describe="客户列表",timeout=6) add_client = PageElement(name="add", describe="添加客户",timeout=2) input_cname=PageElement(xpath='//*[@name="customerName"]/div[2]/input',describe="输入客户名称",timeout=6) input_phone = PageElement(xpath='//*[@name="phone"]/div[2]/input', describe="输入电话号码") input_city = PageElement(xpath='//*[@name="region"]/div[2]/input', describe="输入省市") customer_level = PageElement(xpath='//*[@name="level"]/span',describe='选择客户级别') customer_level_1 =PageElement(xpath='//*[@name="level"]/div[1]/p[2]',describe='一级客户') pay_type=PageElement(xpath='//*[@name="payType"]/span',describe="付费方式") after_pay = PageElement(xpath='//*[@name="payType"]/div/p[3]',describe="后付费") save =PageElement(class_name='viewC_btnSave',describe="保存",timeout=1) customer_text = PageElements(xpath='//*[@class_name="tbCWrap"]/*',describe="客户列表资料",timeout=1)
class login_page(Page): login_click = PageElement(xpath='//*[@id="u1"]/a', describe='点击登录') login_exchange = PageElement( xpath='//*[@id="TANGRAM__PSP_11__footerULoginBtn"]', describe='点击切换登录方式') login_username = PageElement(name="userName", describe='输入账号') login_password = PageElement(name="password", describe='输入密码') login_enter = PageElement(id_="TANGRAM__PSP_11__submit", describe='点击【登录】')
class BalanceQuerypage(Page): firstPage_alert = PageElement(xpath="/html/body/div[6]/div/span/div", describe="电子对账提示框") firstPage_sure_button = PageElement( xpath="/html/body/div[6]/div/span/div/div/div/span/span/button[2]", describe="确定按钮") firstPage_accountmenu_button = PageElement( xpath="//li[@href='#/AccountManage/AccountQry']", describe="账户菜单") firstPage_yearlv_text = PageElement( xpath="//span[@data-reactid='.0.0.0.1.1.0.1.0.0.4.0.0.0.1.1.1']", describe="活期利率")
class BaiduPage(BasePage): url = "https://www.baidu.com" '''方法一:自定义方法元素定位 def search_input(self,search_key): self.by_id("kw").send_keys(search_key) def search_button(self): self.by_id("su").click() ''' '''方法二:poium方法元素定位''' search_input = PageElement(id_='kw') search_button = PageElement(id_='su')
class Loginpage(Page): loginname_loc = PageElement(name='loginName') password_loc = PageElement(name='password') login_loc = PageElement(id_='jLogin') def login(self, loginname, password): self.get("https://cas.leke.cn/login?service=") self.loginname_loc = loginname self.password_loc = password self.login_loc.click() self.get("http://webapp.leke.cn/leke-ai-pad/#/operation") time.sleep(5) return Mainpage(self.driver)
class TopLevelPage(Page): """top level pages. ex: HomePage, VideoPage, and OfflinePage""" news_tab = PageElement(id_='com.transsnet.news.more:id/tab_news') video_tab = PageElement(id_='com.transsnet.news.more:id/tab_video') offline_tab = PageElement(id_='com.transsnet.news.more:id/tab_me') @classmethod def selected_page(cls): for i, tab in enumerate([cls.news_tab, cls.video_tab, cls.offline_tab]): if tab.selected: print('tab.selected:{}'.format(tab.selected)) return i
class OfflinePage(TopLevelPage): top_tab_list = PageElements(xpath='//*[@resource-id="com.transsnet.news.more:id/offline_tab"]/*[1]/*') view_more_btn = PageElement(id_='com.transsnet.news.more:id/view_more_tv') topic_list = PageElements(xpath='//*[@resource-id="com.transsnet.news.more:id/flow_layout"]/*') start_btn = PageElement(id_='com.transsnet.news.more:id/start_btn_container') article_num_btn_1 = PageElement(xpath='//*[@resource-id="com.transsnet.news.more:id/per_channel_title"]/../*[7]') article_num_btn_2 = PageElement(xpath='//*[@resource-id="com.transsnet.news.more:id/per_channel_title"]/../*[8]') article_num_btn_3 = PageElement(xpath='//*[@resource-id="com.transsnet.news.more:id/per_channel_title"]/../*[9]') def to_offline_tab(self): self.top_tab_list[0].click() def to_saved_tab(self): self.top_tab_list[1].click()
class Exercisepage(Page): #选项元素标签是[2]--[6] question_loc = PageElement(class_name='slick-current') question_list_loc = PageElements(class_name='slick-slide') subit_loc = PageElement(class_name='submit_btn') #selects_loc = PageElement(xpath='/html/body/div[1]/div/div/div[3]/div[1]/div/div/div/div[' + str(x) + ']/div/div/div[3]/span[1]') selects_loc = PageElement(css='.slick-active .option:nth-child(2) > .num') def do_exercise(self): for x in range(0, len(self.question_list_loc)): self.selects_loc.click() time.sleep(2) time.sleep(20) self.subit_loc.click() '''
class SplashCountryPage(Page): container = PageElement(id_='com.transsnet.news.more:id/country_list') country_list = PageElements(id_='com.transsnet.news.more:id/tv_name') oper_index_dict = { '1': 0, # ke '2': 1, # ng '5': 2, # za '3': 3, # eg '8': 4, # gh '9': 5, # ug } def get_country_elem(self, oper_id): index = self.oper_index_dict[str(oper_id)] return self.country_list[index] def change_country(self, oper_id): self.get_country_elem(oper_id).click() def wait_for_loading(self, timeout=20): """ """ start_time = time.time() while True: if self.container is not None: return True elif time.time() - start_time > timeout: break time.sleep(1) return False
class CountrySelectionPage(Page): # delay = 2 # selected_country = PageElement(xpath='//node()[@resource-id="com.transsnet.news.more:id/right_icon"]/../*[2]') container = PageElement(id_='com.transsnet.news.more:id/country_list') country_list = PageElements(id_='com.transsnet.news.more:id/tv_name') oper_index_dict = { '1': 0, # ke '2': 1, # ng '5': 2, # za '3': 3, # eg '8': 4, # gh '9': 5, # ug } def get_country_elem(self, oper_id): index = self.oper_index_dict[str(oper_id)] return self.country_list[index] def change_country(self, oper_id): self.get_country_elem(oper_id).click() def wait_for_loading(self, timeout=20): """ """ start_time = time.time() while True: if self.container is not None: return True elif time.time() - start_time > timeout: break time.sleep(1) return False