Esempio n. 1
0
class TestBaiDu(unittest.TestCase):
    URL = Config().get('URL')
    print(URL)
    excel = DATA_PATH + '/baidu.xlsx'

    def sub_setUp(self):
        # 初始页面是main page,传入浏览器类型打开浏览器
        self.page = BaiDuMainPage(browser_type='chrome').get(
            self.URL, maximize_window=False)

    def sub_tearDown(self):
        self.page.quit()

    def test_search(self):
        datas = ExcelReader(self.excel).data
        for d in datas:
            with self.subTest(data=d):
                self.sub_setUp()
                self.page.search(d['search'])
                time.sleep(2)
                self.page = BaiDuResultPage(self.page)  # 页面跳转到result page
                links = self.page.result_links
                for link in links:
                    logger.info(link.text)
                self.sub_tearDown()
Esempio n. 2
0
class TestBaiDu(unittest.TestCase):
    URL = Config().get('URL')
    excel = DATA_PATH + '/baidu.xlsx'

    locator_kw = (By.ID, 'kw')
    locator_su = (By.ID, 'su')
    locator_result = (By.XPATH, '//div[contains(@class, "result")]/h3/a')

    def sub_setUp(self):
        self.page = BaiDuMainPage(browser_type='chrome').get(
            self.URL, maximize_window=True)

    def sub_tearDown(self):
        self.page.quit()

    def test_search(self):
        datas = ExcelReader(self.excel).data
        print(datas)
        for d in datas:
            with self.subTest(data=d):
                self.sub_setUp()
                self.page.search(d["search"])
                time.sleep(3)
                self.page = BaiDuResultPage(self.page)
                links = self.page.result_links
                for link in links:
                    logger.info(link.text)
                self.sub_tearDown()
Esempio n. 3
0
class TestBaiDu(unittest.TestCase):
    #URL = 'https://www.baidu.com/'
    URL = Config().get('URL')
    #base_path = os.path.abspath(os.path.join(os.getcwd(), '..\..'))#获取路径
    #driver_path = os.path.abspath(base_path+'\drivers\geckodriver.exe')

    excel = os.path.join(DATA_PATH, 'baidu.xlsx')
    locator_kw = (By.ID, 'kw')
    locator_su = (By.ID, 'su')
    locator_result = (By.XPATH, '//div[contains(@class, "result")]/h3/a')

    def sub_setUp(self):
        #初始页面是main page,传入浏览器类型打开浏览器
        self.page = BaiDuMainPage(browser_type='chrome').get(
            self.URL, maxmize_windows=False)

        #self.driver = webdriver.Firefox(executable_path=os.path.join(DRIVER_PATH,'geckodriver.exe'))#用框架里的浏览器驱动
        #self.driver.get(self.URL)

    def sub_tearDown(self):
        #self.driver.quit()
        self.page.quit()

    def test_search(self):
        #可以对用例简单说明
        u"""百度搜索"""
        datas = ExcelReader(self.excel).data
        for d in datas:
            with self.subTest(data=d):
                self.sub_setUp()
                self.page.search(d['search'])
                #self.driver.find_element(*self.locator_kw).send_keys(d['search'])
                #self.driver.find_element(*self.locator_su).click()
                #self.driver.implicitly_wait(5)
                time.sleep(2)
                self.page.save_screen_shot('test_baidu')  #调用截图方法
                self.page = BaiDuResultPage(self.page)  #页面跳转到result page
                links = self.page.result_links
                #links = self.driver.find_elements(*self.locator_result)  # ????????
                for link in links:
                    # print(link.text)
                    logger.info(link.text)
                self.sub_tearDown()
Esempio n. 4
0
class Testbaidu(unittest.TestCase):
    URL = Config().get('URL')
    excel = DATA_PATH + '/baidu.xlsx'

    def sub_setUp(self):  #self  本身的意思     setup开始的时候先执行   一次
        #初始页面main page,传入浏览器类型打开浏览器
        self.page = BaiDuMainPage(browser_type='chrome').get(self.URL)

    def sub_tearDown(self):  #tesrdown    结束的时候执行一次
        self.page.quit()

    def test_search(self):
        datas = ExcelReader(self.excel).data
        for d in datas:
            with self.subTest(data=d):
                self.sub_setUp()
                self.page.search(d['search'])
                time.sleep(2)
                self.page = BaiDuResultPage(self.page)  #跳转到result page
                links = self.page.result_links
                for link in links:
                    logger.info(link.text)
                self.sub_tearDown()
Esempio n. 5
0
class TestBaiDu(unittest.TestCase):
    URL = Config().get('URL')
    excel = os.path.join(DATA_PATH , 'baidu_search.xlsx')

    def sub_setUp(self):
        self.page = BaiDuMainPage(browser_type='chrome').get(self.URL)
    def sub_tearDown(self):
        self.page.quit()

    def test_search(self):
        '''对小心走火、小坦克、jianhao_he执行百度搜索操作'''
        datas = ExcelReader(excel=self.excel).data

        for d in datas:
            print(d)
            with self.subTest(data=d):
                self.sub_setUp()
                self.page.search(d['A'])
                self.page = BaiDuResultPage(self.page)
                links = self.page.result
                for link in links:
                    logger.info(link.text)
                self.sub_tearDown()
Esempio n. 6
0
class TestBaiDu(unittest.TestCase):
    URL = Config().get('URL')
    excel = DATA_PATH + '/baidu.xlsx'

    def sub_setUp(self):
        # 初始页面是main page,传入浏览器类型打开浏览器
        self.page = BaiDuMainPage(browser_type='chrome').get(self.URL, maximize_window=False)

    def sub_tearDown(self):
        self.page.quit()

    def test_search(self):
        datas = ExcelReader(self.excel).data
        for d in datas:
            with self.subTest(data=d):
                self.sub_setUp()
                self.page.search(d['search'])
                time.sleep(2)
                self.page = BaiDuResultPage(self.page)  # 页面跳转到result page
                links = self.page.result_links
                for link in links:
                    logger.info(link.text)
                self.sub_tearDown()