コード例 #1
0
def testMail():
    try:
        userSheet = excelObj.getSheetByName("账号")
        isExecuteUser = excelObj.getColumn(userSheet, account_isExecute)
        dataBookColumn = excelObj.getColumn(userSheet, account_dataBook)
        for idx, i in enumerate(isExecuteUser[1:]):
            if i.value == "y":
                userRow = excelObj.getRow(userSheet, idx + 2)
                userName = userRow[account_username - 1].value
                password = str(userRow[account_password - 1].value)
                print(userName, password)
                driver = launchBrowser()
                LoginAction.login(driver, userName, password)
                sleep(3)
                dataBookName = dataBookColumn[idx + 1].value
                print(dataBookName)
                contactPersonSheet = excelObj.getSheetByName(dataBookName)
                isExecuteData = excelObj.getColumn(contactPersonSheet,
                                                   contacts_isExecute)
                contactNum = 0
                isExecuteNum = 0
                for idy, data in enumerate(isExecuteData[1:]):
                    if data.value == "y":
                        isExecuteNum += 1
                        contactPersonRow = excelObj.getRow(
                            contactPersonSheet, idy + 2)
                        contactPersonName = contactPersonRow[
                            contacts_contactPersonName - 1].value
                        print(contactPersonName)

    except Exception as e:
        raise e
コード例 #2
0
def test():
    try:
        driver = LoginAction.driver("http://86.100.16.15:8001")
        LoginAction.login(driver, "szgsfengyj", "888888111")
        TreeAction.getFirstTree(driver, "重点监控纳税人库")

    except Exception as e:
        raise e('登录失败,用户名或者密码错误')
コード例 #3
0
def testMailLogin():
    try:
        driver = webdriver.Chrome(executable_path="E:\\driver\\chromedriver")
        driver.get("http://mail.126.com")
        driver.implicitly_wait(5)
        driver.maximize_window()
        LoginAction.login(driver,
                          username="******",
                          password="******")
        time.sleep(5)
        assert u"未读邮件" in driver.page_source
    except Exception, e:
        raise e
コード例 #4
0
def testMailLogin():
    try:
        driver = webdriver.Firefox()
        driver.get("http://mail.126.com")
        driver.implicitly_wait(30)
        driver.maximize_window()
        LoginAction.login(driver, "aaaa", "bbbb")
        time.sleep(5)
        assert u"未读邮件" in driver.page_source
    except Exception as e:
        raise e
    finally:
        driver.quit()
コード例 #5
0
def testMailLogin():
    try:
        driver = webdriver.Firefox(
            executable_path=
            "G:\pycharm\python_workspace\webdriver\geckodriver.exe")
        driver.get("http://mail.126.com")
        driver.implicitly_wait(30)
        driver.maximize_window()
        LoginAction.login(driver, username="******", password="******")
        assert u"未读邮件" in driver.page_source
    except Exception as e:
        raise e
    finally:
        driver.quit()
コード例 #6
0
    def logintree(url, username, password, ftree, stree, ttree=None):
        try:
            driver = LoginAction.driver(url)
            LoginAction.login(driver, username, password)
            TreeAction.getFirstTree(driver, ftree)
            TreeAction.getSecondTree(driver, stree)
            if ttree != None:
                TreeAction.getThirdTree(driver, ttree)

        except Exception as e:
            raise e

        finally:
            return driver
コード例 #7
0
def test_dbZdjknsr(pcbh):
    try:
        driver = LoginAction.driver("http://86.100.16.15:8001")
        LoginAction.login(driver, "szgscaiyj", "888888")
        TreeAction.getFirstTree(driver, "重点监控纳税人库")
        TreeAction.getSecondTree(driver, '重点监控纳税人手动出库')
        TreeAction.getThirdTree(driver, "出库审批")
        #for p in pcbh:
        ZdjknsrDbAction.gsycmlDb(driver, pcbh=pcbh, spsm='审批说明', spjg="不同意")

    except Exception as e:
        #selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: 停止运行此脚本吗?
        raise e

    finally:
        driver.quit()
コード例 #8
0
 def setUpClass(cls) -> None:
     TestBookCity.browser = webdriver.Chrome(chrome_options=options)
     logger.info("开始登陆...")
     TestBookCity.browser.get("https://plogin.m.jd.com/user/login.action")
     TestBookCity.login_cookie = LoginAction.login(not_vip_username,
                                                   not_vip_password,
                                                   TestBookCity.browser)
コード例 #9
0
def test_xgZdjknsr(pcbh):
    try:
        driver = LoginAction.driver("http://86.100.16.15:8001")
        LoginAction.login(driver, "szgsfengyj", "888888")
        TreeAction.getFirstTree(driver, "重点监控纳税人库")
        TreeAction.getSecondTree(driver, '重点监控纳税人手动出库')
        TreeAction.getThirdTree(driver, "出库申请")
        # for p in pcbh:
        #     print(p)
        ZdjknsrXgAction.pcXg(driver, pcbh=pcbh, xgsm='修改说明', spry="蔡永进")

    except Exception as e:
        #selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: 停止运行此脚本吗?
        raise e

    finally:
        driver.quit()
コード例 #10
0
def testErpLogin():
    try:
        # 启动谷歌浏览器
        driver = webdriver.Chrome(executable_path="E:\\Python36\\chromedriver")
        # 访问erp首页
        driver.get("https://qa1-erp.jfz.com")
        driver.implicitly_wait(30)
        driver.maximize_window()
        time.sleep(5)
        # 登录erp
        LoginAction.login(driver, "defang1", "123")
        time.sleep(5)
        assert "德芳理财" in driver.page_source
    except Exception as e:
        raise e
    finally:
        # 退出浏览器
        driver.quit()
コード例 #11
0
 def test_login(self):
     logging.info(u'登录测试用例现在开始执行')
     try:
         user_sheet = self.excelObj.get_sheetbyname(u'login')
         is_execute = self.excelObj.get_column(user_sheet, login_isExecute)
         logging.debug('is_execute[1:]:%s' % is_execute[1:])
         for idx, value in enumerate(is_execute[1:]):
             if value == 'y':
                 user_data = self.excelObj.get_row(user_sheet, idx+2)
                 username = user_data[login_username - 1]
                 password = user_data[login_password - 1]
                 assert_word = user_data[login_assert - 1]
                 driver = webdriver.Chrome()
                 driver.get('https://www.51kaihui.com/login/index')
                 time.sleep(3)
                 LoginAction.login(d=driver, username=username, password=password)
                 logging.info(u'登录用户名:%s,密码:%s' % (username, password))
                 time.sleep(3)
                 try:
                     assert assert_word in driver.page_source
                 except AssertionError as e:
                     logging.info(u'用户%s断言关键字:%s,断言失败' % (username, assert_word))
                     self.excelObj.write_cell(sheet=user_sheet,
                                              content='failed',
                                              row_number=idx+2,
                                              column_number=login_testResult,
                                              style='red')
                     self.excelObj.write_cell_currenttime(user_sheet, row_number=idx+2, column_number=login_testTime)
                 else:
                     logging.info(u'断言关键字:%s,断言成功' % assert_word)
                     self.excelObj.write_cell(sheet=user_sheet,
                                              content='pass',
                                              row_number=idx+2,
                                              column_number=login_testResult,
                                              style='green')
                     self.excelObj.write_cell_currenttime(user_sheet, row_number=idx+2, column_number=login_testTime)
                 driver.quit()
     except Exception as e:
         raise e
コード例 #12
0
def test_addZdjknsr():
    try:
        driver = LoginAction.driver("http://86.100.16.15:8001")
        LoginAction.login(driver, "szgsfengyj", "888888")
        TreeAction.getFirstTree(driver, "重点监控纳税人库")
        TreeAction.getSecondTree(driver, '重点监控纳税人手动出库')
        TreeAction.getThirdTree(driver, "出库申请")
        # 新增,勾选一个纳税人,提交审批
        pcbh = []
        #pcbh1=ZdjknsrAddAction.gsycmlAdd(driver,1,"\'蔡永进\'","解除原因","\'稽查定性开企业\'")
        pcbh2 = ZdjknsrAddAction.gsycmlAdd(driver,
                                           number=1,
                                           spry="蔡永进",
                                           reason="解除原因",
                                           lx="稽查定性虚开业")
        #pcbh.append(pcbh1)
        pcbh.append(pcbh2)
        return pcbh

    except Exception as e:
        raise e

    finally:
        driver.quit()
コード例 #13
0
def test126MailAddContacts():
    logging.info(u"126邮箱添加联系人数据驱动测试开始...")
    try:
        userSheet = excelObj.getSheetByName(u"126账号")
        isExecuteUser = excelObj.getColumn(userSheet, account_isExecute)
        dataBookColumn = excelObj.getColumn(userSheet, account_dataBook)
        print(u"测试为126邮箱添加联系人执行开始...")
        for idx, i in enumerate(isExecuteUser[1:]):
            if i.value == "y":
                userRow = excelObj.getRow(userSheet, idx + 2)
                username = userRow[account_username - 1].value
                password = str(userRow[account_password - 1].value)
                print(username, password)

                driver = LaunchBrower()
                logging.info(u"启动服务器,访问126邮箱主页")

                LoginAction.login(driver, username, password)
                time.sleep(3)
                try:
                    assert u"收 信" in driver.page_source
                    logging.info\
                        (u"用户%s登陆后,断言页面关键字收 信成功" %username)
                except AssertionError as e:
                    logging.debug(u"失败,"
                                  u"异常信息: %s" %
                                  (username, str(traceback.print_exc())))
                dataBookName = dataBookColumn[idx + 1].value
                dataSheet = excelObj.getSheetByName(dataBookName)
                isExecuteData = excelObj.getColumn(dataSheet,
                                                   contacts_isExecute)
                contactNum = 0
                isExecuteNum = 0
                for id, data in enumerate(isExecuteData[1:]):
                    if data.value == "y":
                        isExecuteNum += 1
                        rowContent = excelObj.getRow(dataSheet, id + 2)
                        contactPersonName = rowContent[
                            contacts_contactPersonName - 1].value
                        contactPersonEmail = rowContent[
                            contacts_contactPersonEmail - 1].value
                        isStar = rowContent[contacts_isStar - 1].value
                        contactPersonPhone = rowContent[
                            contacts_contactPersonMobile - 1].value
                        contactPersonComment = rowContent[
                            contacts_contactPersonComment - 1].value
                        assertKeyWord = rowContent[contacts_assertKeyWords -
                                                   1].value
                        print(contactPersonName, contactPersonEmail,
                              assertKeyWord)
                        print(contactPersonComment, contactPersonPhone, isStar)
                        AddContactPerson.add(driver, contactPersonName,
                                             contactPersonEmail, isStar,
                                             contactPersonPhone,
                                             contactPersonComment)
                        time.sleep(3)
                        logging.info(u"添加联系人%s成功" % contactPersonEmail)
                        excelObj.writeCellCurrentTime(dataSheet,
                                                      rowNo=id + 2,
                                                      colsNo=contacts_runTime)
                        try:
                            assert assertKeyWord in driver.page_source
                        except AssertionError as e:
                            excelObj.writeCell(dataSheet,
                                               "faild",
                                               rowNo=id + 2,
                                               colsNo=contacts_testResult,
                                               style="red")
                            logging.info(u"断言关键字%s失败" % assertKeyWord)
                    else:
                        excelObj.writeCell(dataSheet,
                                           "pass",
                                           rowNo=id + 2,
                                           colsNo=contacts_testResult,
                                           style="green")
                        contactNum += 1
                        logging.info(u"断言关键字%s成功" % assertKeyWord)
                print("contactNum = %s, isExecuteNum = %s"\
                      %(contactNum, isExecuteNum))
                if contactNum == isExecuteNum:
                    excelObj.writeCell(userSheet,
                                       "pass",
                                       rowNo=idx + 2,
                                       colsNo=account_testResult,
                                       style="green")
                    print(u"为用户 %s添加 %d个联系人,测试通过!"\
                         % (username, contactNum))
                else:
                    excelObj.writeCell(userSheet,
                                       "faild",
                                       rowNo=idx + 2,
                                       colsNo=account_testResult,
                                       style="red")
                    logging.info(u"为用户%s添加%d个联系人,%d个成功\n"\
                      % (username, isExecuteNum, contactNum))
            else:
                ignoreUserName = excelObj.getCellOfValue\
                    (userSheet, rowNo = idx + 2, colsNo = account_username)
                logging.info(u"用户%s被为忽略执行!," % ignoreUserName)
            driver.quit()
    except Exception as e:
        logging.debug(u"异常信息: %s"\
         %str(traceback.format_exc()))
コード例 #14
0
    def test_add_contract(self):
        logging.info(u'添加联系人数据驱动测试开始')
        try:
            # 根据excel文件中sheet名称获取此sheet的对象
            user_sheet = self.excelObj.get_sheetbyname(u'账号')
            # 获取账号是否执行
            is_execute_user = self.excelObj.get_column(user_sheet,
                                                       account_isExecute)
            # 获取账号sheet中的数据表列
            data_book_column = self.excelObj.get_column(
                user_sheet, account_dataBook)
            for idx, i in enumerate(is_execute_user[1:]):
                # 循环遍历账号表中的账号,为需要执行的账号添加联系人
                if i == "y":  # 表示要执行
                    # 获取第i行的数据
                    user_row = self.excelObj.get_row(user_sheet, idx + 2)
                    # print(type(user_row))
                    # print(user_row[1])
                    # 获取第i行用户名
                    username = user_row[account_username - 1]
                    # 获取第i行密码
                    password = str(user_row[account_password - 1])

                    # 创建浏览器实例对象
                    driver = self.launch_broswer()
                    logging.debug(u'启动浏览器,访问主页')

                    # 登录邮箱
                    LoginAction.login(d=driver,
                                      username=username,
                                      password=password)
                    logging.debug(u'用户%s密码%s正在进行登录' % (username, password))
                    sleep(3)
                    try:
                        assert u'通讯录' in driver.page_source
                        logging.info(u'用户%s登录成功' % username)
                    except AssertionError as e:
                        logging.info(u'用户%s登录失败, 异常信息:%s' %
                                     (username, str(traceback.format_exc())))
                        self.excelObj.write_cell(
                            user_sheet,
                            'failed',
                            row_number=idx + 2,
                            column_number=account_testResult,
                            style='red')

                    # 获取第i行用户要添加的联系人数据表sheet名
                    data_book_name = data_book_column[idx + 1]
                    # 获取对应的数据表对象
                    data_sheet = self.excelObj.get_sheetbyname(data_book_name)
                    # 获取联系人数据表中联系人是否执行
                    is_execute_data = self.excelObj.get_column(
                        data_sheet, contracts_isExecute)

                    contract_num = 0  # 记录添加成功联系人个数
                    is_execute_num = 0  # 记录需要执行联系人个数

                    for id, data in enumerate(is_execute_data[1:]):
                        # 获取第id+2行对象
                        row_content = self.excelObj.get_row(data_sheet, id + 2)
                        # 获取联系人姓名
                        contract_person_name = row_content[
                            contracts_contractName - 1]
                        # 获取联系人电话
                        contracts_person_mobile = row_content[
                            contracts_contractMobile - 1]
                        # 获取联系人备注
                        contracts_person_email = row_content[
                            contracts_contractEmail - 1]
                        # 添加联系人后断言的关键字
                        assert_keywords = row_content[contracts_assertKeyWords
                                                      - 1]

                        # 寻黄遍历是否执行添加联系人列,如果被设置为添加,则进行添加
                        if data == 'y':
                            logging.debug(u'用户 %s 需要添加联系人对象 %s' %
                                          (username, contract_person_name))
                            # 如果第id行被设置为执行,则is_execute_num自增1
                            is_execute_num += 1

                            # 执行添加联系人操作
                            AddContractPerson.add(
                                d=driver,
                                contract_name=contract_person_name,
                                contract_mobile=contracts_person_mobile,
                                contract_memo=contracts_person_email)
                            sleep(1)
                            logging.debug(u'用户 %s 添加联系人对象名字%s电话%s邮箱%s' %
                                          (username, contract_person_name,
                                           contracts_person_mobile,
                                           contracts_person_email))

                            # 在联系人工作表写入添加联系人执行时间
                            self.excelObj.write_cell_currenttime(
                                data_sheet,
                                row_number=id + 2,
                                column_number=contracts_runTime)
                            try:
                                # 断言给定的关键字是否出现在页面中
                                assert assert_keywords in driver.page_source
                            except AssertionError as e:
                                # 断言失败,在联系人工作表中写入添加联系人测试失败信息
                                self.excelObj.write_cell(
                                    data_sheet,
                                    'failed',
                                    row_number=id + 2,
                                    column_number=contracts_testResult,
                                    style='red')
                                logging.info(
                                    u'用户 %s 添加联系人%s失败' %
                                    (username, contract_person_name), e)
                            else:
                                # 断言成功,写入添加联系人信息成功
                                self.excelObj.write_cell(
                                    data_sheet,
                                    'pass',
                                    row_number=id + 2,
                                    column_number=contracts_testResult,
                                    style='green')
                                contract_num += 1
                                logging.debug(u'用户 %s 添加联系人%s成功' %
                                              (username, contract_person_name))
                        else:
                            logging.debug(u'用户 %s 不需要添加联系人对象 %s' %
                                          (username, contract_person_name))

                        logging.debug(
                            '需要添加的联系人个数contractNum为 = %s, 添加成功的联系人个数isExecuteNum为 = %s'
                            % (contract_num, is_execute_num))

                        if contract_num == is_execute_num:
                            # 如果成功添加联系人个数等于需要添加的联系人个数,说明给第i个用户添加联系人的用力执行成功
                            # 在账号工作表写入成功信息,否则写入失败信息
                            self.excelObj.write_cell(
                                user_sheet,
                                'pass',
                                row_number=idx + 2,
                                column_number=account_testResult,
                                style='green')
                            logging.debug(u'为用户%s 添加 %d个联系人,测试通过' %
                                          (username, contract_num))
                        else:
                            self.excelObj.write_cell(
                                user_sheet,
                                'failed',
                                row_number=idx + 2,
                                column_number=account_testResult,
                                style='red')
                            logging.info(u'为用户%s 添加 %d个联系人,测试失败' %
                                         (username, contract_num))
                    driver.quit()

                    logging.info(u'为用户%s 添加 %d个联系人,测试通过' %
                                 (username, contract_num))

                else:
                    logging.info(u'用户%s被设置为忽略执行' %
                                 self.excelObj.get_cell_value(
                                     user_sheet,
                                     row_number=idx + 2,
                                     column_number=account_username))
        except Exception as e:
            logging.info(u'数据驱动框架主程序发生异常,异常信息为:', e)
            logging.info(traceback.print_exc())
コード例 #15
0
def test163MailAddContacts():
    try:
        userSheet = excelObj.getSheetByName(u"163账号")
        isExecuteUser = excelObj.getColumn(userSheet, account_isExecute)
        dataBookColumn = excelObj.getColumn(userSheet, account_dataBook)
        print(u"测试为163邮箱添加联系人执行开始......")
        for idx, i in enumerate(isExecuteUser[1:]):
            if i.value == "y":
                userRow = excelObj.getRow(userSheet, idx + 2)
                username = userRow[account_username - 1].value
                password = str(userRow[account_password - 1].value)
                print(username, password)

                driver = LaunchBrowser()

                LoginAction.login(driver, username, password)
                sleep(3)
                dataBookName = dataBookColumn[idx + 1].value
                dataSheet = excelObj.getSheetByName(dataBookName)
                isExecuteData = excelObj.getColumn(dataSheet,
                                                   contacts_isExecute)
                contactNum = 0
                isExecuteNum = 0
                for id, data in enumerate(isExecuteData[1:]):
                    if data.value == "y":
                        isExecuteNum += 1
                        rowContent = excelObj.getRow(dataSheet, id + 2)
                        contactPersonName = rowContent[
                            contacts_contactPersonName - 1].value
                        contactPersonEmail = rowContent[
                            contacts_contactPersonEmail - 1].value
                        isStar = rowContent[contacts_isStar - 1].value
                        contactPersonPhone = rowContent[
                            contacts_contactPersonMobile - 1].value
                        contactPersonComment = rowContent[
                            contacts_contactPersonComment - 1].value
                        assertKeyWord = rowContent[contacts_assertKeyWords -
                                                   1].value
                        print(contactPersonName)

                        AddContactPerson.add(driver, contactPersonName,
                                             contactPersonEmail, isStar,
                                             contactPersonPhone,
                                             contactPersonComment)
                        sleep(1)

                        excelObj.writeCellCurrentTime(dataSheet,
                                                      rowNo=id + 2,
                                                      colsNo=contacts_runTime)
                        try:
                            assert assertKeyWord in driver.page_source
                        except AssertionError as e:
                            excelObj.writeCell(dataSheet,
                                               "faild",
                                               rowNo=id + 2,
                                               colsNo=contacts_testResult,
                                               style="green")
                            contactNum += 1
                        else:
                            excelObj.writeCell(dataSheet,
                                               "pass",
                                               rowNo=id + 2,
                                               colsNo=contacts_testResult,
                                               style="green")
                            contactNum += 1
                print("Todo1")

                if contactNum == isExecuteNum:
                    excelObj.writeCell(userSheet,
                                       "pass",
                                       rowNo=idx + 2,
                                       colsNo=account_testResult,
                                       style="green")
                    print("Todo2")
                else:
                    excelObj.writeCell(userSheet,
                                       "faild",
                                       rowNo=idx + 2,
                                       colsNo=account_testResult,
                                       style="red")
            else:
                print("Todo3")
            driver.quit()

    except Exception as e:
        print(u"数据驱动框架主程序发生异常,异常信息为:")
        print(traceback.print_exc())
コード例 #16
0
    def setUp(self) -> None:
        TestRead.browser = webdriver.Chrome(chrome_options=options)

        logger.info("开始登陆...")
        TestRead.browser.get("https://plogin.m.jd.com/user/login.action")
        TestRead.login_cookie=LoginAction.login('你的用户名', "你的密码", TestRead.browser)
コード例 #17
0
    def test_Login(self):
        logger.info("开始执行登录脚本...")
        #获取是否执行列
        isExecuteUser = TestLogin.excelObj.get_col_values(acount_isExecute)
        for idx, i in enumerate(isExecuteUser[1:]):
            start_time = time.time()
            if i == 'Y':
                username = TestLogin.excelObj.get_cell_value(
                    idx + 2, acount_username)
                password = TestLogin.excelObj.get_cell_value(
                    idx + 2, acount_password)
                usertype = TestLogin.excelObj.get_cell_value(
                    idx + 2, acount_type)
                logger.info("执行测试数据:%s,%s,%s" % (username, password, usertype))
                try:

                    browser = webdriver.Chrome(chrome_options=options)

                    browser.get(minepage)
                    logger.info('启动浏览器,访问"我的"页面...')
                    minePage = MinePage(browser)
                    minePage.LoginEntryButton().click()
                    logger.info('点击"我的"页面的登录按钮...')
                    LoginAction.login(username, password, browser)
                    logger.info('登录操作执行...')

                    try:
                        #minePage.ExitButtonObj()  # 如果在"我的"页面找到退出按钮,则通过测试用例,如果没找到该按钮则测试用例未通过
                        browser.implicitly_wait(5)
                        self.assertIs(minePage.ExitButtonObj().is_displayed(),
                                      True)
                        logger.info('在"我的"页面找【退出】按钮')
                    except Exception as e:
                        # self.assertTrue(1 == 2)

                        logger.debug('在"我的"页面找到【退出】按钮,失败,用例不通过')
                        TestLogin.excelObj.write_cell_value(
                            idx + 2, execute_testResult, 'fail', 'red')
                        TestLogin.excelObj.write_cell_value(
                            idx + 2, execute_time,
                            str(time.time() - start_time) + 'ms', 'red')
                        raise e

                    else:
                        logger.info('在"我的"页面找到【退出】按钮,成功,用例通过')
                        TestLogin.excelObj.write_cell_value(
                            idx + 2, execute_testResult, 'success', 'green')
                        TestLogin.excelObj.write_cell_value(
                            idx + 2, execute_time,
                            str(round(
                                (time.time() - start_time) / 1000, 2)) + 's')

                except ElementNotVisibleException as e:

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

                except NoSuchElementException as e:

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

                except Exception as e:

                    logger.error(e)

                    raise e
            else:
                continue
コード例 #18
0
def test126MailAddContacts():
    logging.info(u"126邮箱添加联系人数据驱动测试开始...")
    try:
        # 根据Excel文件中sheet名称获取sheet对象
        userSheet = exceObj.getSheetByName(u"126帐号")
        # 获取126帐号的sheet中的是否执行
        isExecuteUser = exceObj.getColumn(userSheet, account_isExecute)
        # 获取126帐号的sheet中的数据列表
        dataBookColumn = exceObj.getColumn(userSheet, account_dataBook)

        # enumerate()函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标
        for idx, i in enumerate(isExecuteUser[1:]):
            # 循环遍历126帐号表中的帐号,为需要执行账号添加联系人
            if i.value == "y":  # y表示需要执行
                # 获取第i行的数据
                userRow = exceObj.getRow(userSheet, idx + 2)
                # 获取第i行的用户名
                username = userRow[account_username - 1].value
                # 获取第i行的密码
                password = str(userRow[account_password - 1].value)
                # 打印用户名 密码
                print(username, password)

                # 创建浏览器实例对象
                driver = LaunchBrowser()
                logging.info(u"启动浏览器,访问126邮箱主页")

                # 登录126邮箱
                LoginAction.login(driver, username, password)
                # 设置等待时长,让浏览器启动完成以便后续操作
                sleep(3)
                try:
                    assert u"收信" in driver.page_source
                    logging.info(u"用户%s登录后,断言页面关键字“收信”成功" % username)
                except AssertionError as e:
                    logging.debug(u"用户%s登录后,断言页面关键字“收信”失败,"
                                  u"异常信息%s:" %
                                  (username, str(traceback.print_exc())))
                # 获取第i行中用户名添加的联系人数据表sheet名
                dataBookName = dataBookColumn[idx + 1].value
                # 获取对象数据表对象
                dataSheet = exceObj.getSheetByName(dataBookName)
                # 获取联系人数据表中的是否执行列的对象
                isExecuteData = exceObj.getColumn(dataSheet,
                                                  contacts_isExecute)
                contactNum = 0  # 记录添加成功联系人个数
                isExecuteNum = 0  # 记录需要执行联系人个数
                for id, data in enumerate(isExecuteData[1:]):
                    # 遍历循环是否执行添加联系人添加操作
                    # 如果设置被添加,则进行联系人添加操作
                    if data.value == "y":
                        # 如果第id行的联系人被设置为执行 isExecuteNUm 自增1
                        isExecuteNum += 1
                        # 获取联系人第id+2行对象
                        rowContent = exceObj.getRow(dataSheet, id + 2)
                        # 获取联系人姓名
                        contactPersonName = rowContent[
                            contacts_contactPersonName - 1].value
                        # 获取联系人邮箱号
                        contactPersonEmail = rowContent[
                            contacts_contactPersonEmail - 1].value
                        # 获取联系人是否为星标联系人
                        isStar = rowContent[contacts_isStar - 1].value
                        # 获取联系人手机号
                        contactPersonPhone = rowContent[
                            contacts_contactPersonMobile - 1].value
                        # 获取联系人备注信息
                        contactPersonComment = rowContent[
                            contacts_contactPersonComment - 1].value
                        # 添加成果后,断言关键字
                        assertKeyWord = rowContent[contacts_assertKeyWords -
                                                   1].value
                        print(contactPersonName, contactPersonEmail,
                              assertKeyWord)
                        print(contactPersonPhone, contactPersonComment, isStar)
                        # 执行新建联系人操作
                        AddContactPerson.add(driver, contactPersonName,
                                             contactPersonEmail, isStar,
                                             contactPersonPhone,
                                             contactPersonComment)
                        sleep(1)
                        logging.info(u"添加联系人%s成功" % contactPersonEmail)

                        # 在联系人工作表中写入添加联系人执行时间
                        exceObj.writCellCurrentTime(dataSheet,
                                                    rowNo=id + 2,
                                                    colsNo=contacts_runTime)
                        try:
                            # 断言关键是否在页面中
                            assert assertKeyWord in driver.page_source
                        except AssertionError as e:
                            # 断言失败就在联系人工作表中添加联系人测试失败信息
                            exceObj.writeCell(dataSheet,
                                              "faild",
                                              rowNo=id + 2,
                                              colsNo=contacts_testResult,
                                              style="red")
                            logging.info(u"断言关键字%s 失败" % assertKeyWord)
                        else:
                            # 反之为成功
                            exceObj.writeCell(dataSheet,
                                              "pass",
                                              rowNo=id + 2,
                                              colsNo=contacts_testResult,
                                              style="green")
                            # 成功的时候 成功添加联系人数量自增1
                            contactNum += 1
                            logging.info(u"断言关键字%s 成功" % assertKeyWord)
            else:
                logging.info(u"联系人%s被忽略执行" % contactPersonEmail)
            # print("contactNum = %s, isExecuteNum = %s" % (contactNum, isExecuteNum))
            if contactNum == isExecuteNum:
                # 如果成功添加联系人数与需要添加联系人数相等
                # 说明给第i个用户添加联系人测试用例执行成功
                # 在126帐号工作表中写入成功信息,否则为失败
                exceObj.writeCell(userSheet,
                                  "pass",
                                  rowNo=idx + 2,
                                  colsNo=account_testResult,
                                  style="green")
                # print(u"为用户%s添加%d个联系人,测试通过!" % (username, contactNum))
            else:
                exceObj.writeCell(userSheet,
                                  "faild",
                                  rowNo=idx + 2,
                                  colsNo=account_testResult,
                                  style="red")
            logging.info(u"为用户%s添加%d个联系人,%d个成功" %
                         (username, isExecuteNum, contactNum))
        else:
            ignoreUserName = exceObj.getCellOfValue(userSheet,
                                                    rowNo=idx + 2,
                                                    colsNo=account_username)
            logging.info(u"用户%s被忽略执行" % ignoreUserName)
        driver.quit()
    except Exception as e:
        logging.debug(u"数据驱动框架主程序发生异常,异常信息为:%s" % str(traceback.print_exc()))
コード例 #19
0
            logger.error(e)
        else:
            logger.info("找到元素" + locateExpression)
            return element


if __name__ == "__main__":
    from selenium import webdriver
    import time

    mobile_emulation = {'deviceName': 'Galaxy S5'}
    options = webdriver.ChromeOptions()
    options.add_experimental_option("mobileEmulation", mobile_emulation)
    browser = webdriver.Chrome(chrome_options=options)
    browser.get("https://plogin.m.jd.com/user/login.action")
    #测试退出按钮
    LoginAction.login('你的用户名', '你的密码', browser,
                      'https://jdread.jd.com/h5/m/p_cart_shop')
    # minePage=MinePage(browser)
    # minePage.ExitButtonObj().click()

    cartPage = ShoppingCartPage(browser)

    time.sleep(2)
    print(cartPage.shoppingCartTitle().is_displayed())
    # time.sleep(2)
    # bookCityPage.toolButtonObj().click()

    time.sleep(2)
    browser.quit()
コード例 #20
0
def aatest163MailAddContacts():
    logging.info("163邮箱添加联系人数据驱动测试开始...")
    try:
        #根据Excel文件中的sheet名称获取此sheet对象
        userSheet = excelObj.getSheetByName("163账号")
        #获取163账号sheet中是否执行列
        isExecuteUser = excelObj.getColumn(userSheet, account_isExecute)
        #获取163账号sheet中的数据表列
        dataBookColumn = excelObj.getColumn(userSheet, account_dataBook)

        for idx, i in enumerate(isExecuteUser[1:]):
            #循环遍历163账号表中的账号,为需要执行的账号添加联系人
            if i.value == "y":  #表示要执行
                #获取第idx+2行的数据
                userRow = excelObj.getRow(userSheet, idx + 2)
                #获取第idx+2行中的用户名
                username = userRow[account_username - 1].value
                #获取第idx+2行中的密码
                password = str(userRow[account_password - 1].value)
                print(username, password)

                #创建浏览器实例对象
                driver = LaunchBrowser()
                logging.info("启动浏览器,访问163邮箱主页")

                #登录163邮箱
                LoginAction.login(driver, username, password)
                #等待3s,让登录跳转完成,以便正常进行后续操作
                sleep(3)
                try:
                    #断言登录后跳转的页面是否包含“收信”
                    assert "收 信" in driver.page_source
                    logging.info("用户 %s 登录后,断言页面关键字“收信”成功" % username)
                except AssertionError as e:
                    logging.debug("用户 %s 登录后,断言页面关键字“收信”失败,异常信息:%s" %
                                  (username, str(traceback.format_exc())))
                #获取为第idx+2行中用户添加的联系人数据表sheet名
                dataBookName = dataBookColumn[idx + 1].value
                #获取对应的数据表对象
                datasheet = excelObj.getSheetByName(dataBookName)
                #获取联系人数据表中是否执行列对象
                isExecuteData = excelObj.getColumn(datasheet,
                                                   contacts_isExecute)
                contactNum = 0  #记录添加成功联系人个数
                isExecuteNum = 0  #记录需要执行联系人个数
                for id, data in enumerate(isExecuteData[1:]):
                    #循环遍历是否执行添加联系人列,如果被设置为添加,则进行联系人添加操作
                    if data.value == "y":
                        #如果第id+2行的联系人被设置为执行,则isExecuteNum自增1
                        isExecuteNum += 1
                        #获取联系人表第id+2行对象
                        rowContent = excelObj.getRow(datasheet, id + 2)
                        #获取了联系人姓名
                        contactPersonName = rowContent[
                            contacts_contactPersonName - 1].value
                        #获取联系人邮箱
                        contactPersonEmail = rowContent[
                            contacts_contactPersonEmail - 1].value
                        #获取是否设置为星标联系人
                        isStar = rowContent[contacts_isStar - 1].value
                        #获取联系人手机号
                        contactPersonPhone = rowContent[
                            contacts_contactPersonMobile - 1].value
                        #获取联系人备注信息
                        contactPersonComment = rowContent[
                            contacts_contactPersonComment - 1].value
                        #添加联系人成功后,断言的关键字
                        assertKeyWord = rowContent[contacts_assertKeyWords -
                                                   1].value
                        print(contactPersonName, contactPersonEmail,
                              assertKeyWord, contactPersonPhone,
                              contactPersonComment, isStar)
                        #执行新建联系人操作
                        AddContactPerson.add(driver, contactPersonName,
                                             contactPersonEmail, isStar,
                                             contactPersonPhone,
                                             contactPersonComment)
                        sleep(1)
                        logging.info("添加联系人 %s 成功" % contactPersonEmail)
                        #在联系人工作表中写入添加联系人执行时间
                        excelObj.writeCellCurrentTime(datasheet,
                                                      rowNo=id + 2,
                                                      colsNo=contacts_runtime)
                        try:
                            #断言给定的关键字是否出现在页面中
                            assert assertKeyWord in driver.page_source
                        except AssertionError as e:
                            #断言失败,在联系人工作表中写入添加联系人测试失败信息
                            excelObj.writeCell(datasheet,
                                               "faild",
                                               rowNo=id + 2,
                                               colsNo=contacts_testResult,
                                               style="red")
                            logging.info("断言关键字 “%s” 失败" % assertKeyWord)
                        else:
                            #断言成功,写入添加联系人成功信息
                            excelObj.writeCell(datasheet,
                                               "pass",
                                               rowNo=id + 2,
                                               colsNo=contacts_testResult,
                                               style="green")
                            contactNum += 1
                            logging.info("断言关键字 “%s” 成功" % assertKeyWord)
                    else:
                        logging.info("联系人%s被忽略执行" % contactPersonEmail)
                # print("contactNum = %s,isExecuteNum = %s" %(contactNum,isExecuteNum))
                if contactNum == isExecuteNum:
                    #如果成功添加的联系人数与需要添加的联系人数相等,说明给第i个用户添加联系人测试用例执行成功,在163账号工作表中写入成功信息,否则写入失败信息
                    excelObj.writeCell(userSheet,
                                       "pass",
                                       rowNo=idx + 2,
                                       colsNo=account_testResult,
                                       style="green")
                    # print("为用户 %s 添加%d 个联系人,测试通过!" %(username,contactNum))
                else:
                    excelObj.writeCell(userSheet,
                                       "faild",
                                       rowNo=idx + 2,
                                       colsNo=account_testResult,
                                       style="red")
                logging.info("为用户%s添加%d个联系人,%d个成功\n" %
                             (username, isExecuteNum, contactNum))
            else:
                # print("用户 %s 被设置为忽略执行!" %excelObj.getCellOfValue(userSheet,rowNo=idx+2,colsNo=account_username))
                #获取被忽略执行的用户名
                ignoreUserName = excelObj.getCellOfValue(
                    userSheet, rowNo=idx + 2, colsNo=account_username)
                logging.info("用户%s被忽略执行\n" % ignoreUserName)
            driver.quit()
    except Exception as e:
        logging.debug("数据驱动框架主程序执行过程发生异常,异常信息为:%s" %
                      str(traceback.format_exc()))
コード例 #21
0
            time.sleep(3)
            apd=AddressBookPage(driver)
            apd.createContactPersonButton().click()
            if contactName:
                apd.contactPersonName().send_keys(contactName)
            apd.contactPersonEmail().send_keys(contactEmail)
            if isStar == u"是":
                apd.starContacts().click()
            if contactPhone:
                apd.contactPersonMobile().send_keys(contactPhone)
            if contactComment:
                apd.contactPersonComment().send_keys(contactComment)
            apd.saveContacePerson().click()
        except Exception as e:
            print(traceback.print_exc())
            raise e

if __name__ == '__main__':

    from appModules.LoginAction import LoginAction
    from selenium import  webdriver
    driver = webdriver.Firefox(executable_path="c:\\geckodriver")
    driver.get("http://mail.163.com")
    time.sleep(5)
    LoginAction.login(driver, "13530480151", "k511983973")
    time.sleep(5)
    AddContactPerson.add(driver, u"张三", "*****@*****.**", u"是", "", "")
    time.sleep(5)
    assert u"张三" in driver.page_source
    driver.quit()
    def test_read_book_button(self):
        logger.info("开始执行书详页-阅读按钮脚本...")

        # 获取是否执行列
        isExecuteUser = testBookDetailNeedLogin.excelObj.get_col_values(
            book_isExecute, sheet_name='VIP逻辑验证书籍')
        pc = ParseConfigFile()

        for idx, i in enumerate(isExecuteUser[1:]):
            start_time = time.time()
            data_Type = testBookDetailNeedLogin.excelObj.get_cell_value(
                idx + 2, book_type)
            if 'Y' == i and "VIP_user_VIP_book" == data_Type:
                bookid = testBookDetailNeedLogin.excelObj.get_cell_value(
                    idx + 2, book_id)
                bookname = testBookDetailNeedLogin.excelObj.get_cell_value(
                    idx + 2, book_name)
                username = testBookDetailNeedLogin.excelObj.get_cell_value(
                    idx + 2, acount_username_check_vip)
                password = testBookDetailNeedLogin.excelObj.get_cell_value(
                    idx + 2, acount_password_check_vip)

                logger.info("执行测试数据:%s,%s,%s,%s" %
                            (bookid, bookname, username, password))

                try:

                    browser = webdriver.Chrome(chrome_options=options)

                    # 登陆
                    logger.info('登录操作执行...')
                    browser.get("https://plogin.m.jd.com/user/login.action")
                    LoginAction.login(username, password, browser,
                                      pc.getUrl('bookdetail') % (bookid))

                    logger.info('启动浏览器,访问"书籍详情"页面...')
                    bookDetailPage = BookDetailPage(browser)

                    read_button = bookDetailPage.readButton()
                    browser.execute_script("arguments[0].scrollIntoView();",
                                           read_button)

                    try:

                        self.assertIs(read_button.text == 'VIP免费读', True)
                        read_button.click()
                        time.sleep(2)
                        check_url = '%sstatic/read/dist/index.html?ebookId=%s&name=' % (
                            url, bookid) in browser.current_url
                        self.assertIs(check_url, 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
            elif 'Y' == i and "VIP_user_VIP_book" != data_Type:
                bookid = testBookDetailNeedLogin.excelObj.get_cell_value(
                    idx + 2, book_id)
                bookname = testBookDetailNeedLogin.excelObj.get_cell_value(
                    idx + 2, book_name)
                username = testBookDetailNeedLogin.excelObj.get_cell_value(
                    idx + 2, acount_username_check_vip)
                password = testBookDetailNeedLogin.excelObj.get_cell_value(
                    idx + 2, acount_password_check_vip)

                logger.info("执行测试数据:%s,%s,%s,%s" %
                            (bookid, bookname, username, password))
                try:

                    browser = webdriver.Chrome(chrome_options=options)

                    # 登陆
                    logger.info('登录操作执行...')
                    browser.get("https://plogin.m.jd.com/user/login.action")
                    LoginAction.login(username, password, browser,
                                      pc.getUrl('bookdetail') % (bookid))

                    logger.info('启动浏览器,访问"书籍详情"页面...')
                    bookDetailPage = BookDetailPage(browser)

                    read_button = bookDetailPage.readButton()
                    browser.execute_script("arguments[0].scrollIntoView();",
                                           read_button)

                    try:

                        self.assertIs(read_button.text == '立即阅读', True)
                        read_button.click()
                        time.sleep(2)
                        check_url = '%sstatic/read/dist/index.html?ebookId=%s&name=' % (
                            url, bookid) in browser.current_url
                        self.assertIs(check_url, 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

            else:
                continue
コード例 #23
0
def test126MailAddContacts():
    logging.info(u"126邮箱添加联系人数据驱动测试开始...")
    try:
        userSheet = excelObj.getSheetByName(u"126账号")
        # 获取126账号sheet表中是否执行列
        isExecuteUser = excelObj.getColumn(userSheet, account_isExecute)
        # 获取126账号sheet表中数据表列
        dataBookColumn = excelObj.getColumn(userSheet, account_dataBook)
        print u"测试为126邮箱添加联系人执行开始..."
        for idx, i in enumerate(isExecuteUser[1:]):
            if i.value == 'y':  # 要执行
                userRow = excelObj.getRow(userSheet, idx + 2)
                username = userRow[account_username - 1].value
                password = str(userRow[account_password - 1].value)
                print username, password

                # 创建浏览器实例对象
                driver = LaunchBrowser()
                logging.info(u"启动浏览器,访问126邮箱主页")

                # 登录
                LoginAction.login(driver, username, password)
                sleep(3)
                try:
                    assert u"收 信" in driver.page_source
                    logging.info(u"用户%s登录后,断言页面关键字'收信'成功" % username)
                except AssertionError, e:
                    logging.debug(
                        u"用户%s登录后, 断言页面关键字'收信'失败,",
                        u"异常信息:%s" % (username, str(traceback.format_exc())))
                dataBookName = dataBookColumn[idx + 1].value
                # 获取账号对应的联系人sheet页数据
                dataSheet = excelObj.getSheetByName(dataBookName)
                isExecuteData = excelObj.getColumn(dataSheet,
                                                   contacts_isExecute)

                contactNum = 0  # 记录添加成功联系人人数
                isExecuteNum = 0  # 记录需要执行联系人人数
                for id, data in enumerate(isExecuteData[1:]):
                    if data.value == "y":
                        isExecuteNum += 1
                        rowContent = excelObj.getRow(dataSheet, id + 2)
                        contactPersonName = rowContent[
                            contacts_contactPersonName - 1].value
                        contactPersonEmail = rowContent[
                            contacts_contactPersonEmail - 1].value
                        isStar = rowContent[contacts_isStar - 1].value
                        contactPersonPhone = rowContent[
                            contacts_contactPersonMobile - 1].value
                        contactPersonComment = rowContent[
                            contacts_contactPersonComment - 1].value

                        # 添加联系人成功后,断言的关键字
                        assertKeyWord = rowContent[contacts_assertKeyWords -
                                                   1].value
                        print contactPersonName, contactPersonEmail, assertKeyWord
                        print contactPersonPhone, contactPersonComment, isStar

                        # 执行联系人操作
                        AddContactPerson.add(driver, contactPersonName,
                                             contactPersonEmail, isStar,
                                             contactPersonPhone,
                                             contactPersonComment)
                        sleep(1)
                        logging.info(u"添加联系人%s成功" % contactPersonEmail)

                        # 在联系人工作表 中写入添加联系人执行时间
                        excelObj.writeCellCurrentTime(dataSheet,
                                                      rowNo=id + 2,
                                                      colsNo=contacts_runTime)
                        try:
                            assert assertKeyWord in driver.page_source
                        except AssertionError, e:
                            # 断言失败,在联系人工作表中写入添加联系人测试失败信息
                            excelObj.writeCell(dataSheet,
                                               "faild",
                                               rowNo=id + 2,
                                               colsNo=contacts_textResult,
                                               style="red")
                            logging.info(u"断言关键字'%s'失败" % assertKeyWord)
                        else:
                            # 断言成功,在联系人工作表中写入成功信息
                            excelObj.writeCell(dataSheet,
                                               "pass",
                                               rowNo=id + 2,
                                               colsNo=contacts_textResult,
                                               style="green")
                            contactNum += 1
                            logging.info(u"断言关键字'%s'成功" % assertKeyWord)
                    else:
                        logging.info(u"联系人%s被忽略执行" % contactPersonEmail)
                if contactNum == isExecuteNum:
                    excelObj.writeCell(userSheet,
                                       "pass",
                                       rowNo=idx + 2,
                                       colsNo=account_testResult,
                                       style="green")
                else:
                    excelObj.writeCell(userSheet,
                                       "faild",
                                       rowNo=idx + 2,
                                       colsNo=account_testResult,
                                       style="red")
                logging.info(u"为用户%s添加%d个联系人,%d个成功\n" %
                             (username, isExecuteNum, contactNum))
            else:
コード例 #24
0
            logger.error(e)
        else:
            logger.info("找到元素" + locateExpression)
            return element


if __name__=="__main__":
    from selenium import webdriver
    import time

    mobile_emulation = {'deviceName': phone_model}
    options = webdriver.ChromeOptions()
    options.add_experimental_option("mobileEmulation", mobile_emulation)
    browser = webdriver.Chrome(chrome_options=options)
    browser.get("https://plogin.m.jd.com/user/login.action")
    LoginAction.login('你的用户名','你的密码',browser,'http://jdread.jd.com/h5/m')

    bookCityPage=BookCityPage(browser)
    login_btn=bookCityPage.loginButton()
    login_btn.click()
    # bookCityPage.toolButtonObj().click()
    # bookCityPage.minePageButtonObj().click()

    # time.sleep(2)
    # bookCityPage.toolButtonObj().click()

    time.sleep(2)
    browser.quit()


コード例 #25
0
    # 创建解析Excel对象
    excelObj = ParseExcel()
    # 将excel文件加载到内存
    excelObj.loadWorkBook(dataFilePath)

    # 根据excel文件中的Sheet名称获取此Sheet对象
    userSheet = excelObj.getSheetByName(u"126账号")
    # 获取126账号sheet中是否执行列
    isExecuteUser = excelObj.getColumn(userSheet, account_isExecute)

    for idx, i in enumerate(isExecuteUser[1:]):
        # 循环遍历126账号表中的账号,为需要执行的账号添加联系人
        if i == "y":
            # 获取第i行数据 从第二行开始才有数据
            userRow = excelObj.getRow(userSheet, idx + 2)
            print userRow
            # 获取第i行中的用户名
            username = userRow[account_username - 1]
            print username
            # 获取第i行中的密码
            password = str(userRow[account_password - 1])
            print username, password

            driver = webdriver.Firefox(
                executable_path="C:\\wmh\\driver\\geckodriver")
            driver.get("https://mail.126.com")
            time.sleep(5)
            LoginAction.login(driver, username, password)
            time.sleep(5)
            driver.quit()
コード例 #26
0
            logger.info("找到元素" + locateExpression)
            return elements


if __name__ == "__main__":
    from selenium import webdriver
    import time
    from util.SimulateLogin_galaxyS5 import simulator_login

    mobile_emulation = {'deviceName': 'Galaxy S5'}
    options = webdriver.ChromeOptions()
    options.add_experimental_option("mobileEmulation", mobile_emulation)
    browser = webdriver.Chrome(chrome_options=options)
    browser.get("https://plogin.m.jd.com/user/login.action")
    # 测试退出按钮
    LoginAction.login('你的用户名', '你的密码', browser,
                      'https://jdread.jd.com/h5/m/p_book_detail/30132192')
    # minePage=MinePage(browser)
    # minePage.ExitButtonObj().click()
    book_detail_page = BookDetailPage(browser)
    book_detail_page.catalogButton().click()
    time.sleep(2)
    catagoryPage = CatagoryPage(browser)
    time.sleep(2)
    print(catagoryPage.titleObj().is_displayed())
    print(catagoryPage.sortButton().is_displayed())
    # print(catagoryPage.canAccessChapters()[0].is_displayed())
    # print(catagoryPage.cannotAccessChapters()[0].is_displayed())
    print(catagoryPage.firstChapter().is_displayed())
    # time.sleep(2)
    # bookCityPage.toolButtonObj().click()
コード例 #27
0
            logger.error(e)
        else:
            logger.info("找到元素" + locateExpression)
            return element


if __name__ == "__main__":
    from selenium import webdriver
    import time

    mobile_emulation = {'deviceName': 'Galaxy S5'}
    options = webdriver.ChromeOptions()
    options.add_experimental_option("mobileEmulation", mobile_emulation)
    browser = webdriver.Chrome(chrome_options=options)
    browser.get("https://plogin.m.jd.com/user/login.action")
    #测试退出按钮
    LoginAction.login('你的用户名', '你的密码', browser,
                      'https://jdread.jd.com/h5/m/p_book_my_list/1')
    # minePage=MinePage(browser)
    # minePage.ExitButtonObj().click()

    minePage = MyBooksPage(browser)

    time.sleep(2)
    print(minePage.mybooksTitle().is_displayed())
    # time.sleep(2)
    # bookCityPage.toolButtonObj().click()

    time.sleep(2)
    browser.quit()
コード例 #28
0

class HomePage(object):
    def __init__(self, driver):
        self.driver = driver
        self.parseCF = ParseCofigFile()
        self.loginOptions = self.parseCF.getItemsSection('126mail_homePage')
        print(self.loginOptions)

    def addressLink(self):
        try:
            locateType, locatorExpression = self.loginOptions \
                ['homepage.addressbook'.lower()].split('>')
            elementObj = getElement(self.driver, locateType, locatorExpression)
            return elementObj
        except Exception as e:
            raise e


if __name__ == '__main__':
    from selenium import webdriver
    import time
    driver = webdriver.Firefox()

    url = "http://mail.126.com"
    driver.get(url)
    LoginAction.login(driver, 'xiyang198803', 'guoliping1988')
    driver.refresh()
    hp = HomePage(driver)
    hp.addressLink().click()
コード例 #29
0
            apb.contract_person_mobile().send_keys(contract_mobile)
            if contract_memo:
                # 非必填项
                apb.contract_person_email().send_keys(contract_memo)
            # 单击添加联系人页面确定按钮
            apb.save_contract_person().click()
        except Exception as e:
            # 打印堆栈异常信息
            print(traceback.print_exc())
            raise e


if __name__ == '__main__':
    # 打开
    from selenium import webdriver
    driver = webdriver.Chrome()
    driver.get('https://www.51kaihui.com/login/index')
    time.sleep(3)
    # 登录
    from appModules.LoginAction import LoginAction
    LoginAction.login(d=driver, username='******', password='******')
    time.sleep(3)
    # 新建联系人
    AddContractPerson.add(d=driver,
                          contract_name=u'张三',
                          contract_mobile='1234566788',
                          contract_memo='')
    time.sleep(3)
    # 验证添加后张三在页面源码中
    assert u"张三" in driver.page_source
    driver.quit()
def test126MailAddContacts():
        logging.info(u'126邮箱添加联系人的数据驱动测试开始。。。')
        try:
            userSheet=excelObj.getSheetByName(u'126账号')
            #获取126账号表格中的是否执行列
            isExecuteUser=excelObj.getColumn(userSheet,account_isExcute)
            #获取数据表那一列
            dataBookColumn=excelObj.getColumn(userSheet,account_dataBook)
            print(u'测试为126邮箱添加联系人执行开始')
            #取到是否执行那一列的所有内容
            for idx,i in enumerate(isExecuteUser[1:]):
                if i.value=='y':
                    #idx是从0开始,真实数据需要到第二行才是,取到的是第i行的内容
                    userRow=excelObj.getRow(userSheet,idx+2)
                    #第i行的用户名
                    username=userRow[account_username-1].value
                    #第i行的密码
                    password=str(userRow[account_password-1].value)
                    print(username,password)
                    driver=LaunchBrowser()
                    logging.info(u'启动浏览器,访问126邮箱主页')
                    LoginAction.login(driver,username,password)
                    time.sleep(2)
                    try:
                        assert u'收信' in driver.page_source
                        logging.info(u'用户%s登陆后,断言页面关键字“收信”成功'%username)
                    except AssertionError as e:
                        logging.debug(u'用户%s登录后,断言页面关键字“收信”失败' u'异常信息:%s'%(username,str(traceback.format_exc())))
                    dataBookName=dataBookColumn[idx+1].value
                    dataSheet=excelObj.getSheetByName(dataBookName)
                    isExecuteData=excelObj.getColumn(dataSheet,contacts_isExecute)
                    contactNum=0
                    isExecuteNum=0
                    for id,data in enumerate(isExecuteData[1:]):
                        if data.value=='y':
                            isExecuteNum+=1
                            rowContent=excelObj.getRow(dataSheet,id+2)
                            contactPersonName=rowContent[contacts_contactPersonName-1].value
                            contactPersonEmail=rowContent[contacts_contactPersonEmail-1].value
                            contactPersonPhone=rowContent[contacts_contactPersonMobile-1].value
                            isStar=rowContent[contacts_isStar-1].value
                            contactPersonComment=rowContent[contacts_contactPersonComment-1].value
                            assertKeyWord=rowContent[contacts_assertKeyWords-1].value
                            print(contactPersonName,contactPersonEmail,assertKeyWord)
                            print(contactPersonPhone,contactPersonComment,isStar)
                            AddContactPerson.add(driver,contactPersonName,
                                                 contactPersonEmail,
                                                 isStar,
                                                 contactPersonPhone,
                                                 contactPersonComment)
                            time.sleep(2)
                            logging.info(u'添加联系人%s成功'%contactPersonEmail)
                            excelObj.writeCellCurrnetTime(dataSheet,rowNo=id+2,colsNo=contacts_runTime)
                            try:
                                assert assertKeyWord in driver.page_source
                            except AssertionError as e:
                                excelObj.writeCell(dataSheet,"faild",rowNo=id+2,colsNo=contacts_testResult,style="red")
                                logging.info(u'断言关键字%s失败'%assertKeyWord)
                            else:
                                excelObj.writeCell(dataSheet,"pass",rowNo=id+2,colsNo=contacts_testResult,style="green")
                                contactNum+=1
                                logging.info(u'断言关键字%s成功'%assertKeyWord)
                        print("contactNum=%s,isExecuteNum=%s" %(contactNum,isExecuteNum))
                        if contactNum==isExecuteNum:
                            excelObj.writeCell(userSheet,'pass',rowNo=idx+2,colsNo=account_testResult,style='green')
                            print(u"为用户%s添加%d个联系人,测试通过!" %(username,contactNum))
                            logging.info(u"为用户%s添加%d个联系人,测试通过!" %(username,contactNum))
                        else:
                            excelObj.writeCell(userSheet,'faild',rowNo=idx+2,colsNo=account_testResult,style='red')
                elif i.value=='n':
                    print("u用户%s被设置为忽略执行!"%excelObj.getCellOfValue(userSheet,rowNo=idx+2,colsNo=account_username))
                    logging.info((u'联系人%s被忽略执行'%contactPersonEmail))
                else:
                    print(u'执行完毕')
                #driver.quit()
        except Exception as e:
            print(u'数据驱动框架助程序发生异常,异常信息为:')
            logging.debug(u'数据驱动框架助程序发生异常,异常信息为:%s'%str(traceback.format_exc()))