コード例 #1
0
class HomePage(object):
    def __init__(self, driver):
        self.driver = driver
        self.parseCf = ParseConfigFile()
        self.addContactsOptions = self.parseCf.getItemsSection(
            "163mail_addContactsPage")
        print(self.addContactsOptions)

    def createContactPersonButton(self):
        # 获取新建联系人按钮
        try:
            # 从定位表达式配置文件中读取定位新建联系人按钮的定位方式和表达式
            locateType,locatorExpression = self.addContactsOptions[\
                "addContactsPage.createContactctsBtn".lower()].split(">")
            # 获取新建联系人按钮并返还给调用者
            elementObj = getElement(self.driver, locateType, locatorExpression)
            return elementObj
        except Exception as e:
            raise e

    def contactPersonName(self):
        # 获取新建联系人界面中的姓名输入框
        try:
            locateType,locatorExpression = self.addContactsOptions[\
                "addContactsPage.contactPersonName".lower()].split(">")
            elementObj = getElement(self.driver, locateType, locatorExpression)
            return elementObj
        except Exception as e:
            raise e

    def contactPersonEmail(self):
        # 获取新建联系人界面中的邮箱输入框
        try:
            locateType,locatorExpression = self.addContactsOptions[\
                "addContactsPage.contactPersonEmail".lower()].split(">")
            elementObj = getElement(self.driver, locateType, locatorExpression)
            return elementObj
        except Exception as e:
            raise e

    def starContacts(self):
        # 获取新建联系人界面中的星标选择框
        try:
            locateType, locatorExpression = self.addContactsOptions[ \
                "addContactsPage.starContacts".lower()].split(">")
            elementObj = getElement(self.driver, locateType, locatorExpression)
            return elementObj
        except Exception as e:
            raise e

    def conttactPersonMobile(self):
        # 获取新建联系人界面中的手机输入框
        try:
            locateType, locatorExpression = self.addContactsOptions[\
                "addContactsPage.conttactPersonMobile".lower()].split(">")
            elementObj = getElement(self.driver, locateType, locatorExpression)
            return elementObj
        except Exception as e:
            raise e

    def contactPersonComment(self):
        # 获取新建联系人界面中的联系人备注输入框
        try:
            locateType, locatorExpression = self.addContactsOptions[\
                "addContactsPage.contactPersonComment".lower()].split(">")
            elementObj = getElement(self.driver, locateType, locatorExpression)
            return elementObj
        except Exception as e:
            raise e

    def savecontacePerson(self):
        # 获取新建联系人界面中的保存联系人按钮
        try:
            locateType, locatorExpression = self.addContactsOptions[ \
                "addContactsPage.savecontacePerson".lower()].split(">")
            elementObj = getElement(self.driver, locateType, locatorExpression)
            return elementObj
        except Exception as e:
            raise e
コード例 #2
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
コード例 #3
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
コード例 #4
0
 def __init__(self, driver):
     self.driver = driver
     self.parseCF = ParseConfigFile()
     self.loginOptions = self.parseCF.getItemsSection('LoginPage')