def test_book_cover_author_publish_recmmand_name(self): logger.info("开始执行书详页-书籍封面、书名、作者和出版社脚本...") #获取是否执行列 isExecuteUser=testBookDetailNotNeedLogin.excelObj.get_col_values(book_isExecute_book_detail, sheet_name='基本信息验证书籍') pc = ParseConfigFile() for idx,i in enumerate(isExecuteUser[1:]): start_time=time.time() data_Type=testBookDetailNotNeedLogin.excelObj.get_cell_value(idx + 2, book_type) if 'Y'==i : bookid=testBookDetailNotNeedLogin.excelObj.get_cell_value(idx + 2, book_id) bookname=testBookDetailNotNeedLogin.excelObj.get_cell_value(idx + 2, book_name) bookAuthor=testBookDetailNotNeedLogin.excelObj.get_cell_value(idx + 2, book_author) bookPublish=testBookDetailNotNeedLogin.excelObj.get_cell_value(idx + 2, book_publish) logger.info("执行测试数据:%s,%s,%s,%s"%(bookid,bookname,bookAuthor,bookPublish)) try: logger.info('启动浏览器,访问"书籍详情"页面...') testBookDetailNotNeedLogin.browser.get(pc.getUrl('bookdetail') % (bookid)) bookDetailPage = BookDetailPage(testBookDetailNotNeedLogin.browser) book_cover_obj=bookDetailPage.bookCoverObj() book_publish_obj=bookDetailPage.publishObj() book_author_obj=bookDetailPage.authorObj() book_name_obj=bookDetailPage.bookNameObj() book_recommand_obj=bookDetailPage.foldRecommandObj() try: self.assertIs(book_cover_obj.is_displayed(),True) self.assertIs(book_publish_obj.text.strip(string.whitespace)==bookPublish.strip(string.whitespace),True) self.assertIs(book_author_obj.text.strip(string.whitespace)==bookAuthor.strip(string.whitespace),True) self.assertIs(book_name_obj.text.strip(string.whitespace)==bookname.strip(string.whitespace),True) self.assertIs(book_recommand_obj.is_displayed(),True) logger.info('执行书详页-书籍封面、书名、作者和出版社脚本成功!用例通过') testBookDetailNotNeedLogin.excelObj.write_cell_value(idx + 2, execute_testResult_book_detail, 'success', 'green') testBookDetailNotNeedLogin.excelObj.write_cell_value(idx + 2, execute_time_book_detail, str(round((time.time() - start_time) / 1000, 2)) + 's') except AssertionError as e: logger.debug('执行书详页--书籍封面、书名、作者和出版社脚本失败!用例不通过') testBookDetailNotNeedLogin.excelObj.write_cell_value(idx + 2, execute_testResult_book_detail, 'fail', 'red') testBookDetailNotNeedLogin.excelObj.write_cell_value(idx + 2, execute_time_book_detail, str(time.time() - start_time) + 'ms', 'red') raise e except ElementNotVisibleException as e: logger.error("数据问题,元素没有找到..") except NoSuchElementException as e: logger.error("数据问题..重试") except Exception as e: logger.error(e) raise e else: continue
def test_First_Collection_Detail_List(self): logger.info("开始执行本周特价合集页列表检查脚本...") pc = ParseConfigFile() try: TestBookCity.browser.get(pc.getUrl('bookcity')) logger.info('启动浏览器,访问"书城"页面...') bookcityPage = BookCityPage(TestBookCity.browser) bookcityPage.channelFoldDownButton().click() time.sleep(2) bookcityPage.channelFeaturedButton().click() time.sleep(2) collectionName = bookcityPage.firstCollectionTitle().text bookcityPage.firstCollectionTitle().click() collectionPage = CollectionPage(TestBookCity.browser) book_element_list = collectionPage.bookNameList() book_name_set = set([ e.text.replace(" ", "") for e in book_element_list if e.text != '' ]) api_book_name_set = set( GetCollectionBooks.getBookNameDataList(collectionName)) book_name_set_check = book_name_set.issubset(api_book_name_set) api_thirdbook_name = GetCollectionBooks.getDataList( collectionName)[2]['name'] api_thirdbook_old_price = str( GetCollectionBooks.getDataList(collectionName)[2]['price']) api_thirdbook_cur_price = str( GetCollectionBooks.getDataList(collectionName)[2]['jd_price']) api_thirdbook_catagory = GetCollectionBooks.getDataList( collectionName)[2]['category_third'][0] page_thirdbook_name = collectionPage.bookNameList()[2].text # page_thirdbook_old_price =collectionPage.bookOldPriceList()[2].text.strip('¥') # page_thirdbook_cur_price =collectionPage.bookCurPriceList()[2].text.strip('¥') try: self.assertIs(book_name_set_check, True) self.assertIs(api_thirdbook_name == page_thirdbook_name, True) # self.assertIs(api_thirdbook_catagory==page_thirdbook_catagory,True) # self.assertIs(api_thirdbook_cur_price==page_thirdbook_cur_price,True) # self.assertIs(api_thirdbook_old_price==page_thirdbook_old_price,True) logger.info('书城本周特价合集页列表检查脚本成功!用例通过') except AssertionError as e: logger.debug('书城本周特价合集页列表检查脚本失败!用例不通过') raise e except ElementNotVisibleException as e: logger.error("数据问题,元素没有找到..") except NoSuchElementException as e: logger.error("数据问题..重试") except Exception as e: logger.error(e) raise e
def test_price_sell_off_book(self): logger.info("开始执行书详页打折书价格脚本...") pc = ParseConfigFile() try: # books_data=getDataList('本周特价') testBookDetailNotNeedLogin.browser.get(pc.getUrl('bookcity')) bookcityPage = BookCityPage(testBookDetailNotNeedLogin.browser) bookcityPage.channelFoldDownButton().click() time.sleep(2) bookcityPage.channelFeaturedButton().click() time.sleep(2) bookcityPage.discountButton().click() # time.sleep(2) # discountPage = DiscountPage(testBookDetailNotNeedLogin.browser) # discountPage.first_book().click() time.sleep(2) current_url=testBookDetailNotNeedLogin.browser.current_url collection_id=re.search(r'\d{4}',current_url).group(0) collection_data=CollectionDetail.getDataJson(collection_id) bookid=str(collection_data['data']['items'][0]['ebook_id']) testBookDetailNotNeedLogin.browser.get(pc.getUrl('bookdetail') % (bookid)) logger.info('启动浏览器,访问"书籍详情"页面...') bookDetailPage = BookDetailPage(testBookDetailNotNeedLogin.browser) real_price_obj = bookDetailPage.realPriceObj() original_price_obj=bookDetailPage.originalPriceObj() discount_obj=bookDetailPage.discountObj() # color=discount.get_attribute('color') api_realprice = str(BookDetai.getData(bookid)['jd_price']) api_price = str(BookDetai.getData(bookid)['price']) api_discount= str(BookDetai.getData(bookid)['discount']) real_price=str(int(round(float(real_price_obj.text.strip('¥')) * 100))) original_price=str(int(round(float(original_price_obj.text.strip('¥'))* 100))) discount= discount_obj.text try: self.assertIs(real_price_obj.is_displayed() and api_realprice == real_price, True) self.assertIs(original_price_obj.is_displayed() and api_price == original_price, True) self.assertIs(discount_obj.is_displayed() and api_discount == discount, True) logger.info('书详页折扣书价格脚本执行成功!用例通过') except AssertionError as e: logger.debug('书详页折扣书价格脚本执行失败!用例通过') raise e except ElementNotVisibleException as e: logger.error("数据问题,元素没有找到..") except NoSuchElementException as e: logger.error("数据问题..重试") except Exception as e: logger.error(e) raise e
def test_Discount_Collection_List(self): logger.info("开始执行本周特价列表检查脚本...") pc = ParseConfigFile() try: browser = webdriver.Chrome(chrome_options=options) browser.get(pc.getUrl('bookcity')) logger.info('启动浏览器,访问"书城"页面...') bookcityPage = BookCityPage(browser) page_book_set = set([ bookcityPage.firstCollectionFirstBookName().text.replace( " ", ""), bookcityPage.firstCollectionSecondBookName().text.replace( " ", ""), bookcityPage.firstCollectionThirdBookName().text.replace( " ", "") ]) collectionName = bookcityPage.firstCollectionTitle().text api_book_set = set( GetCollectionBooks.getBookNameDataList(collectionName)) # print(page_book_set) # print(api_book_set) booklist_check = page_book_set.issubset(api_book_set) # api_firstbook_jd_price= str(int(float(GetCollectionBooks.getDataList(collectionName)[0]['jd_price']) * 100)) + "阅豆" # api_firstbook_price= str(int(float(GetCollectionBooks.getDataList(collectionName)[0]['price']) * 100)) + "阅豆" api_firstbook_jd_price = str( round( GetCollectionBooks.getDataList(collectionName)[0] ['jd_price'], 2)) api_firstbook_price = str( round( GetCollectionBooks.getDataList(collectionName)[0]['price'], 2)) page_firstbook_jd_price = str( round( float(bookcityPage.firstCollectionFirstBookNewPrice().text. strip('¥')), 2)) page_firstbook_price = str( round( float(bookcityPage.firstCollectionFirstBookOldPrice().text. strip('¥')), 2)) try: self.assertIs(booklist_check, True) self.assertIs( (api_firstbook_jd_price == page_firstbook_jd_price) and (api_firstbook_price == page_firstbook_price), True) logger.info('书城本周特价列表检查成功!用例通过') except AssertionError as e: logger.debug('书城本周特价列表检查失败!用例不通过') raise e except ElementNotVisibleException as e: logger.error("数据问题,元素没有找到..") except NoSuchElementException as e: logger.error("数据问题..重试") except Exception as e: logger.error(e) raise e