def classified_page_article_check(self): print('\n=======使用者瀏覽分類頁=======') self.driver.get('https://supertaste-pre.tvbs.com.tw/food') # 美食 self.driver.maximize_window() web_error_inspect.error_inspect(self) sleep(1) WebDriverWait(self.driver, 20).until(lambda x: x.find_element_by_class_name('overlay-color')) print('文章主圖正常顯示') web_classified_page.classified_page_article_backend_compare(self)
def index_latest_article_check(self): print('\n=======使用者瀏覽首頁分類區塊=======') self.driver.get('https://supertaste-pre.tvbs.com.tw') self.driver.maximize_window() web_error_inspect.error_inspect(self) sleep(1) WebDriverWait(self.driver, 20).until( lambda x: x.find_element_by_class_name('talk_article').find_element_by_class_name('overlay-color')) print('文章主圖正常顯示') web_index.index_latest_article_backend_compare(self)
def classified_page_article_direct(self): # 分類頁文章跳轉判斷 article_title = self.driver.find_element_by_id( 'combolistUl').find_element_by_class_name('txt').text print('文章標題 : ' + article_title) self.driver.find_element_by_class_name('overlay-color').click() sleep(3) web_error_inspect.error_inspect(self) # ERROR判斷 direct_article_title = self.driver.find_elements_by_class_name( 'margin_b10')[2].text self.assertEqual(article_title, direct_article_title) print('跳轉文章功能正常') sleep(0.5)
def store_check(self): print('\n=======使用者瀏覽店家頁面=======') self.driver.get('https://supertaste-pre.tvbs.com.tw/infocard') # 店家頁面 self.driver.maximize_window() web_error_inspect.error_inspect(self) sleep(1) WebDriverWait(self.driver, 20).until(lambda x: x.find_element_by_class_name('overlay-color')) print('店家主圖正常顯示') store_url_list = [] store_list = [] for i in range(6): store_list.append(self.driver.find_element_by_id('newstore').find_elements_by_class_name('txt')[i] .find_element_by_tag_name('p').text) for i in range(6): self.driver.find_element_by_id('newstore').find_elements_by_class_name('overlay-color')[i].click() self.driver.implicitly_wait(5) store_url_list.append(self.driver.current_url) print(self.driver.current_url) self.driver.back() WebDriverWait(self.driver, 20).until(lambda x: x.find_element_by_id('newstore')) self.assertEqual(len(set(store_url_list)), 6) print('最新店家內無重複店家') # 最新店家店名比對 web_search.latest_store_direct(self) # 後台 web_backend.backend_direct(self) web_backend.backend_login(self) # 後台 - 小編推薦與首頁分類置頂 self.driver.get('http://2017back-pre.tvbs.com.tw/index.php/program/program_store/program_store_list') # 獲取當前視窗控制代碼集合(列表型別) handles = self.driver.window_handles self.driver.switch_to.window(handles[-1]) backend_store_list = [] self.driver.find_element_by_xpath('//input[@value="1"]').click() Select(self.driver.find_element_by_name('store_status')).select_by_value('1') # 上架 self.driver.find_element_by_css_selector("input[value = '查詢']").click() WebDriverWait(self.driver, 20).until(lambda x: x.find_element_by_id('content-list_table')) for j in range(6): backend_store_list.append(self.driver.find_elements_by_tag_name('tr')[j + 2].find_elements_by_tag_name('td')[2] .text) self.assertEqual(store_list, backend_store_list) print('後台店家設定有正確顯示於前台')
def classified_page_article(self): print('\n=======在分類頁點擊文章,進入文章內頁=======') self.driver.get('https://supertaste-pre.tvbs.com.tw/food') self.driver.maximize_window() web_error_inspect.error_inspect(self) sleep(1) WebDriverWait(self.driver, 20).until(lambda x: x.find_element_by_class_name('header_logo')) web_classified_page.classified_page_article_direct(self) web_common_component.hot_click(self) js = "var action=document.documentElement.scrollTop=500" self.driver.execute_script(js) web_common_component.editor_recommend(self) web_common_component.good_news(self) web_common_component.is_fb_exist(self) web_article_page.article_line_direct(self) web_article_page.article_youtube_direct(self) web_article_page.article_fb_direct(self)
def index_article_direct(self): # 首頁文章跳轉 print('\n=======首頁文章跳轉=======') article_title = self.driver.find_element_by_class_name( 'talk_content_big').find_element_by_class_name('txt').text print('文章標題 : ' + article_title) date_time = self.driver.find_element_by_class_name('time').text datetime.datetime.strptime(date_time, '%Y/%m/%d %H:%M') print('時間格式正確 : ' + date_time) js = "var action=document.documentElement.scrollTop=500" self.driver.execute_script(js) sleep(1) self.driver.find_element_by_class_name('overlay-color').click() sleep(2) web_error_inspect.error_inspect(self) direct_article_title = self.driver.find_element_by_tag_name('h1').text self.assertEqual(article_title, direct_article_title) print('跳轉文章功能正常')
def index_article_backend_compare(self): # 首頁文章跳轉 print('\n=======首頁文章跳轉=======') article_title = self.driver.find_element_by_class_name( 'talk_content_big').find_element_by_class_name('txt').text print('文章標題 : ' + article_title) date_time = self.driver.find_element_by_class_name('time').text datetime.datetime.strptime(date_time, '%Y/%m/%d %H:%M') print('時間格式正確 : ' + date_time) js = "var action=document.documentElement.scrollTop=500" self.driver.execute_script(js) sleep(1) self.driver.find_element_by_class_name('overlay-color').click() sleep(2) web_error_inspect.error_inspect(self) direct_article_title = self.driver.find_element_by_tag_name('h1').text self.assertEqual(article_title, direct_article_title) print('跳轉文章功能正常') # 後台 web_backend.backend_direct(self) web_backend.backend_login(self) # 前後台文章標題比對 print('\n=======前後台文章標題比對=======') self.driver.get( "http://2017back-pre.tvbs.com.tw/index.php/program_supertaste/supertaste_articles/index/web_editor" ) Select(self.driver.find_element_by_name( 'search_categories_id')).select_by_value('46') # 雜貨 Select(self.driver.find_element_by_name( 'search_articles_status')).select_by_value('1') # 上架 self.driver.find_element_by_css_selector("input[value = '查詢']").click() WebDriverWait(self.driver, 20).until(lambda x: x.find_element_by_id('content')) backend_article_title = self.driver.find_element_by_class_name( 'td_title').text self.assertEqual(article_title, backend_article_title) print('前後台文章標題比對正確')
def classified_page_article_backend_compare(self): # 分類頁文章跳轉 print('\n=======分類頁文章跳轉=======') web_error_inspect.error_inspect(self) # ERROR判斷 # 判斷分類頁文章有無重複 article_list = [] article_url_list = [] for i in range(6): article_list.append( self.driver.find_element_by_id( 'combolistUl').find_elements_by_class_name('txt')[i].text) for i in range(9): self.driver.find_element_by_id( 'combolistUl').find_elements_by_class_name('txt')[i].click() self.driver.implicitly_wait(5) article_url_list.append(self.driver.current_url) print(self.driver.current_url) self.driver.back() WebDriverWait( self.driver, 20).until(lambda x: x.find_element_by_class_name('talk_article')) self.assertEqual(len(set(article_url_list)), 9) print('『分類頁無重複文章』') # 判斷時間格式 date_time = self.driver.find_element_by_id( 'combolistUl').find_element_by_class_name('time').text datetime.datetime.strptime(date_time, '%Y/%m/%d %H:%M') print('時間格式正確 : ' + date_time) # 跳轉驗證 article_title = self.driver.find_element_by_id( 'combolistUl').find_element_by_class_name('txt').text self.driver.find_element_by_id('combolistUl').find_element_by_class_name( 'txt').click() sleep(2) direct_article_title = self.driver.find_elements_by_class_name( 'margin_b10')[2].text self.assertEqual(article_title, direct_article_title) print('跳轉文章功能正常') # 後台 web_backend.backend_direct(self) web_backend.backend_login(self) # 前後台文章標題比對 print('\n=======前後台文章標題比對=======') self.driver.get( "http://2017back-pre.tvbs.com.tw/index.php/program_supertaste/supertaste_articles/index/web_editor" ) Select(self.driver.find_element_by_name( 'search_categories_id')).select_by_value('22') # 美食 Select(self.driver.find_element_by_name( 'search_articles_status')).select_by_value('1') # 上架 self.driver.find_element_by_css_selector("input[value = '查詢']").click() WebDriverWait(self.driver, 20).until(lambda x: x.find_element_by_id('content')) backend_article_title = self.driver.find_element_by_class_name( 'td_title').text self.assertEqual(article_title, backend_article_title) print('前後台文章標題比對正確')