def test_baidu_search(self): """ 这里一定要test开头,把测试逻辑代码封装到一个test开头的方法里。 :return: """ homepage = Baidu(self.driver) ea = BasePage(self.driver) homepage.type_search('selenium') # 调用页面对象中的方法 ea.wait(10) homepage.send_submit_btn() #调用页面对象类中的点击搜索按钮方法 ea.wait(10) homepage.get_windows_img() time.sleep(5) # 调用基类截图方法 try: assert 'selenium' in homepage.get_page_title( ) # 调用页面对象继承基类中的获取页面标题方法 print('Test Pass.') except Exception as e: print('Test Fail.', format(e))
from selenium import webdriver from framework.base_page import BasePage import time driver = BasePage("driver") driver.wait(10) driver.get("http://testhotel.hblckj.cn/login.html") driver.send_keys("xpath=/html/body/div[2]/div[2]/form/div[1]/input","18640857881") driver.send_keys("xpath=/html/body/div[2]/div[2]/form/div[2]/input","jt123456") driver.click("xpath=/html/body/div[2]/div[2]/form/div[4]/div/a") driver.wait(5) driver.set_window_size(600,600) # driver.sleep(3) driver.max_window() driver.get_window_img() driver.clear("xpath=/html/body/div[3]/div/div[1]/div[2]/form/div[1]/input") driver.right_click("xpath=/html/body/div[3]/div/div[1]/div[2]/form/div[1]/input") driver.move_to_element("xpath=/html/body/div[1]/div/ul/li[1]/a") driver.back() driver.forward() driver.get_attribute("xpath=/html/body/div[3]/div/div[1]/div[2]/form/div[5]/button","type") driver.get_text("xpath=/html/body/div[3]/div/div[1]/div[2]/form/div[5]/button")