class Look_Tie_HomePage(BasePage): # 查看帖子 look_post_loc = (By.CSS_SELECTOR, '.xs3 a') # 打开帖子 open_post_loc = (By.CSS_SELECTOR, '.ts') def enter_post(self): self.change_window() time.sleep(1) self.click(*self.look_post_loc) self.get_windows_img() time.sleep(1) def check(self): self.change_window() time.sleep(1) title = self.get_text(*self.open_post_loc) self.get_windows_img() return title def logout(self): self.testone = Main_Homepage(self.driver) self.close() self.change_window() self.close() self.change_window() self.testone.logout() time.sleep(1)
def test_center_contral(self): test_login = Login_HomePage(self.driver) test_main = Main_Homepage(self.driver) test_default = Default_Homepage(self.driver) test_admin_login = Admin_Login_HomePage(self.driver) test_management_center = Management_Center_HomePage(self.driver) test_new_bankuai = New_Bankuai_Homepage(self.driver) # 登录 test_login.login('admin', 'admin') # 点击默认板块 test_main.click_moren() # 删除帖子 test_default.delete() # 点击管理中心 test_main.enter_plate() # 进入版块管理(管理中心 - -论坛) test_admin_login.enter_plate('admin') # 点击论坛 test_management_center.enter_plate() # 创建新的版块 test_management_center.new_plate('自动化测试') # 管理员退出 test_main.logout() # 普通用户登录 test_login.login('lucky ', 'lucky') # 在新的版块下发帖 test_main.send_post_new() test_new_bankuai.send_post_new('你好呀', '今天也要加油鸭!!!') # 回复帖子 test_new_bankuai.reply_post('是的呀,加油鸭,加油鸭')
def logout(self): self.testone = Main_Homepage(self.driver) self.close() self.change_window() self.close() self.change_window() self.testone.logout() time.sleep(1)
def test_send_tie(self): test_login=Login_HomePage(self.driver) test_main = Main_Homepage(self.driver) test_default = Default_Homepage(self.driver) test_login.login('admin','admin') test_main.click_moren() test_default.send_post('搭建框架','今天学习搭建自动化测试框架') test_default.reply_post('好好努力,加油鸭') test_default.logout()
def test_vote(self): test_login = Login_HomePage(self.driver) test_main = Main_Homepage(self.driver) test_default = Default_Homepage(self.driver) test_vote = Vote_homepage(self.driver) test_login.login('admin', 'admin') test_main.click_moren() test_default.menu_loc() test_vote.publish_post() test_vote.vote() test_vote.get_name_ratio() test_vote.get_theme_name()
def new_plate(self, name): self.testone = Main_Homepage(self.driver) time.sleep(1) self.change_window() self.enter_iframe() time.sleep(2) self.click(*self.home_page_click_new_border_loc) print('点击新增版块按钮成功') time.sleep(1) self.clear(*self.home_page_new_txt_loc) time.sleep(1) print('清除新板块的名字成功') self.sendkeys(name, *self.home_page_new_txt_loc) print('输入新板块的名字成功') time.sleep(1) self.click(*self.home_page_submit_new_loc) self.get_windows_img() # 退出管理中心 time.sleep(2) self.change_window() self.testone.logout()
class Management_Center_HomePage(BasePage): # 点击论坛 home_page_click_luntan_loc = (By.CSS_SELECTOR, '.nav ul li:nth-child(7)') # 点击添加新版块 home_page_click_new_border_loc = (By.CSS_SELECTOR, '.lastboard .addtr') # 找到新模块文本框 home_page_new_txt_loc = (By.CSS_SELECTOR, 'form .tb2 tbody:nth-last-child(2) .board .txt') # 找到提交按钮 home_page_submit_new_loc = (By.CSS_SELECTOR, '.fixsel .btn') def enter_plate(self): time.sleep(1) self.click(*self.home_page_click_luntan_loc) def new_plate(self, name): self.testone = Main_Homepage(self.driver) time.sleep(1) self.change_window() self.enter_iframe() time.sleep(2) self.click(*self.home_page_click_new_border_loc) print('点击新增版块按钮成功') time.sleep(1) self.clear(*self.home_page_new_txt_loc) time.sleep(1) print('清除新板块的名字成功') self.sendkeys(name, *self.home_page_new_txt_loc) print('输入新板块的名字成功') time.sleep(1) self.click(*self.home_page_submit_new_loc) self.get_windows_img() # 退出管理中心 time.sleep(2) self.change_window() self.testone.logout()
def test_search_tie(self): test_login = Login_HomePage(self.driver) test_main = Main_Homepage(self.driver) test_look_tie = Look_Tie_HomePage(self.driver) test_login.login('admin', 'admin') test_main.search('haotest') test_look_tie.enter_post() title = test_look_tie.check() try: self.assertEqual(title, 'haotest', msg=title) print('断言结果:帖子标题和期望的一致') except: print('断言结果:帖子标题和期望的不一致') test_main.logout()