def test_activity(self):
        logger.info("开始执行书详页促销活动脚本...")

        pc = ParseConfigFile()

        try:

            # books_data=getDataList('双周特价')
            # books_data=getDataList('本周特价')
            #
            # bookid=str(books_data[0]['ebook_id'])
            testBookDetailNotNeedLogin.browser.get(pc.getUrl('bookcity'))

            book_city_page=BookCityPage(testBookDetailNotNeedLogin.browser)
            book_city_page.discountButton().click()
            time.sleep(1)

            discount_page=WeeklyDiscountPage(testBookDetailNotNeedLogin.browser)
            discount_page.firstBook().click()
            time.sleep(1)
            bookid=re.search(r'[0-9]{8}', testBookDetailNotNeedLogin.browser.current_url).group()


            testBookDetailNotNeedLogin.browser.get(pc.getUrl('bookdetail') % (bookid))

            logger.info('启动浏览器,访问"书籍详情"页面...')
            bookDetailPage = BookDetailPage(testBookDetailNotNeedLogin.browser)
            activity_obj = bookDetailPage.acivityObj()
            activity_text = activity_obj.text.strip(string.whitespace)
            api_activity=BookDetai.getData(bookid)['promotion_msg']

            try:

                self.assertIs(activity_text==api_activity, 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
Beispiel #2
0
    def test_P(self):
        logger.info("开始执行唤起菜单脚本...")
        #获取是否执行列

        TestRead.browser.get('https://jdread.jd.com/h5/m')

        bcp=BookCityPage(TestRead.browser)
        bcp.toolButtonObj().click()

        time.sleep(2)
Beispiel #3
0
    def test_Discount_Button_Click(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)
            bookcityPage.discountButton().click()

            time.sleep(2)
            discountPage = DiscountPage(TestBookCity.browser)
            titleElement = discountPage.title()
            title_text = titleElement.text

            try:

                # self.assertIs('特价专区'==title_text , True)
                result1 = '特价专区' == title_text
                result2 = re.search(r'\d+件[\s\S]+元', title_text)
                result3 = "双周特价" == title_text
                if result1:
                    self.assertIs('特价专区' == title_text, True)
                elif None != result2:
                    self.assertIs(None != result2, 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_Login_Button(self):
        logger.info("开始执行登陆按钮脚本...")
        pc = ParseConfigFile()

        try:

            browser = webdriver.Chrome(chrome_options=options)

            browser.get(pc.getUrl('bookcity'))

            logger.info('启动浏览器,访问"书城"页面...')
            bookcityPage = BookCityPage(browser)
            time.sleep(3)

            # bookcityPage.loginButton().click()
            login_button = bookcityPage.loginButton()
            browser.execute_script("arguments[0].click();", login_button)

            jd_login_button = getElement(browser, 'xpath', '// a[. = "登 录"]')
            try:

                self.assertIs(jd_login_button.is_displayed(), 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
Beispiel #5
0
    def test_First_Collection_Book_Click_Redirect(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)
            page_first_book_name = bookcityPage.firstCollectionFirstBookName(
            ).text
            bookcityPage.firstCollectionFirstBookName().click()
            time.sleep(3)
            book_detail_page_title = TestBookCity.browser.title

            try:

                self.assertIs(page_first_book_name == book_detail_page_title,
                              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
Beispiel #6
0
    def test_Discount_Collection_Title(self):
        logger.info("开始执行本周特价title点击脚本...")
        pc = ParseConfigFile()

        try:

            browser = webdriver.Chrome(chrome_options=options)

            browser.get(pc.getUrl('bookcity'))

            logger.info('启动浏览器,访问"书城"页面...')
            bookcityPage = BookCityPage(browser)

            collectionName = bookcityPage.firstCollectionTitle().text
            counterHour = bookcityPage.firstCollectionCounterHour().text
            counterMinute = bookcityPage.firstCollectionCounterMinute().text

            checkHour = str(24 - int(time.localtime().tm_hour) - 1).zfill(2)
            checkMinute = str(60 - int(time.localtime().tm_min) - 1).zfill(2)

            bookcityPage.firstCollectionTitle().click()
            time.sleep(5)

            weeklyDiscountTitleText = WeeklyDiscountPage(browser).title().text

            try:

                self.assertIs(checkHour == counterHour, True)
                self.assertIs(checkMinute == counterMinute, True)
                # self.assertIs("本周特价"==collectionName,True)
                # self.assertIs("本周特价"==weeklyDiscountTitleText,True)

                logger.info('书城本周特价title点击成功!用例通过')

            except AssertionError as e:
                logger.debug('书城本周特价title点击失败!用例不通过')
                raise e

        except ElementNotVisibleException as e:

            logger.error("数据问题,元素没有找到..")
            raise e

        except NoSuchElementException as e:

            logger.error("数据问题..重试")
            raise e

        except Exception as e:

            logger.error(e)

            raise e
Beispiel #7
0
    def test_More_Tools_Button(self):
        logger.info("开始执行唤起更多工具按钮脚本...")
        pc = ParseConfigFile()

        try:

            TestBookCity.browser.get(pc.getUrl('bookcity'))

            logger.info('启动浏览器,访问"书城"页面...')
            bookcityPage = BookCityPage(TestBookCity.browser)

            logger.info('点击右上角更多按钮...')
            bookcityPage.toolButtonObj().click()

            try:

                self.assertIs(bookcityPage.firstPageButtonObj().is_displayed(),
                              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
Beispiel #8
0
    def test_Check_Domain(self):
        logger.info("开始执行频道切换按钮脚本...")
        pc = ParseConfigFile()

        try:

            TestBookCity.browser.get(pc.getUrl('bookcity'))

            logger.info('启动浏览器,访问"书城"页面...')
            bookcityPage = BookCityPage(TestBookCity.browser)

            domainname = bookcityPage.domainName().text
            domainurl = bookcityPage.domainUrl().text

            try:

                self.assertIs(('e.m.jd.com' in domainurl)
                              and ('京东读书' in domainname), 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
Beispiel #9
0
    def test_Freebook_Button_Click(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)
            bookcityPage.freebookButton().click()

            time.sleep(2)
            freePage = FreebookPage(TestBookCity.browser)
            time.sleep(2)
            titleElement = freePage.title()
            title_text = titleElement.text

            try:

                self.assertIs('免费专区' == title_text, 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
Beispiel #10
0
    def test_Banner_Click(self):
        logger.info("开始执行书城banner点击脚本...")
        pc = ParseConfigFile()

        try:

            TestBookCity.browser.get(pc.getUrl('bookcity'))

            logger.info('启动浏览器,访问"书城"页面...')
            bookcityPage = BookCityPage(TestBookCity.browser)

            bookcityPage.channelFoldDownButton().click()
            time.sleep(2)
            bookcityPage.channelNewEraButton().click()
            time.sleep(2)
            bookcityPage.newEraBanner().click()
            time.sleep(5)
            collectionPage = CollectionPage(TestBookCity.browser)
            titleElement = collectionPage.title()

            try:

                self.assertIs(titleElement.is_displayed(), True)
                logger.info('书城banner点击成功!用例通过')

            except AssertionError as e:
                logger.debug('书城banner点击失败!用例不通过')
                raise e

        except ElementNotVisibleException as e:

            logger.error("数据问题,元素没有找到..")

        except NoSuchElementException as e:

            logger.error("数据问题..重试")

        except Exception as e:

            logger.error(e)

            raise e
Beispiel #11
0
    def test_More_Tools_Index_Button(self):
        logger.info("开始执行更多按钮首页按钮脚本...")
        pc = ParseConfigFile()

        try:

            TestBookCity.browser.get(pc.getUrl('bookcity'))

            bookcityPage = BookCityPage(TestBookCity.browser)
            bookcityPage.toolButtonObj().click()
            index_image = bookcityPage.indexButtonImageInMoreTools()
            index_button = bookcityPage.firstPageButtonObj()
            if index_image.is_displayed() and index_button.is_displayed():
                index_button.click()

            # my_books_image=bookcityPage.myBooksButtonImageInMoreTools()
            # shop_cart_image=bookcityPage.shoppingCartButtonImageInMoreTools()
            # mine_image=bookcityPage.mineButtonImageInMoreTools()

            try:

                self.assertIs(bookcityPage.domainName().is_displayed(), True)

                logger.info('书城首页按钮点击成功!用例通过')

            except AssertionError as e:
                logger.debug('书城首页按钮点击失败!用例不通过')
                raise e

        except ElementNotVisibleException as e:

            logger.error("数据问题,元素没有找到..")
            raise e

        except NoSuchElementException as e:

            logger.error("数据问题..重试")
            raise e

        except Exception as e:

            logger.error(e)

            raise e
Beispiel #12
0
    def test_More_Tools_Shopping_Cart_Button(self):
        logger.info("开始执行更多按钮-【购物车】按钮脚本...")
        pc = ParseConfigFile()

        try:

            TestBookCity.browser.get(pc.getUrl('bookcity'))

            bookcityPage = BookCityPage(TestBookCity.browser)
            bookcityPage.toolButtonObj().click()

            shopping_cart_image = bookcityPage.shoppingCartButtonImageInMoreTools(
            )
            shopping_cart_button = bookcityPage.shoppingCartPageButtonObj()
            if shopping_cart_image.is_displayed(
            ) and shopping_cart_button.is_displayed():
                shopping_cart_button.click()
            # shop_cart_image=bookcityPage.shoppingCartButtonImageInMoreTools()
            # mine_image=bookcityPage.mineButtonImageInMoreTools()
            shoppingCartPage = ShoppingCartPage(TestBookCity.browser)
            time.sleep(5)

            try:

                self.assertIs(
                    shoppingCartPage.shoppingCartTitle().is_displayed(), True)

                logger.info('书城更多按钮-【购物车】点击成功!用例通过')

            except AssertionError as e:
                logger.debug('书城更多按钮-【购物车】点击失败!用例不通过')
                raise e

        except ElementNotVisibleException as e:

            logger.error("数据问题,元素没有找到..")
            raise e

        except NoSuchElementException as e:

            logger.error("数据问题..重试")
            raise e

        except Exception as e:

            logger.error(e)

            raise e
Beispiel #13
0
    def test_More_Tools_My_Books_Button(self):
        logger.info("开始执行更多按钮-【我的书籍】按钮脚本...")
        pc = ParseConfigFile()

        try:

            TestBookCity.browser.get(pc.getUrl('bookcity'))

            bookcityPage = BookCityPage(TestBookCity.browser)
            bookcityPage.toolButtonObj().click()
            my_books_image = bookcityPage.myBooksButtonImageInMoreTools()
            my_books_button = bookcityPage.myBookPageButtonObj()
            if my_books_image.is_displayed() and my_books_button.is_displayed(
            ):
                my_books_button.click()
            mybooksPage = MyBooksPage(TestBookCity.browser)
            # mybooks_title=mybooksPage.mybooksTitle()
            time.sleep(5)
            print(TestBookCity.browser.page_source)

            try:

                self.assertIs(mybooksPage.mybooksTitle().is_displayed(), True)

                logger.info('书城更多按钮-【我的书籍】点击成功!用例通过')

            except AssertionError as e:
                logger.debug('书城更多按钮-【我的书籍】点击失败!用例不通过')
                raise e

        except ElementNotVisibleException as e:

            logger.error("数据问题,元素没有找到..")
            raise e

        except NoSuchElementException as e:

            logger.error("数据问题..重试")
            raise e

        except Exception as e:

            logger.error(e)

            raise e
Beispiel #14
0
    def test_Switch_Channel_Button(self):
        logger.info("开始执行频道切换按钮脚本...")
        pc = ParseConfigFile()

        try:

            TestBookCity.browser.get(pc.getUrl('bookcity'))

            logger.info('启动浏览器,访问"书城"页面...')
            bookcityPage = BookCityPage(TestBookCity.browser)

            logger.info('点击频道折叠按钮...')
            bookcityPage.channelFoldDownButton().click()
            bookcityPage.channelVIPButton().click()
            TestBookCity.browser.refresh()
            titleText = bookcityPage.VIPText().text

            try:

                self.assertIs('开通京东读书VIP,海量书籍免费借阅' in titleText, 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
Beispiel #16
0
    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
Beispiel #17
0
    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