Пример #1
0
def open_browser(browserName, *arg):
    # 打开浏览器
    global driver, waitUtil
    try:
        if browserName.lower() == 'ie':
            driver = webdriver.Ie(executable_path=ieDriverFilePath)
        elif browserName.lower() == 'chrome':
            # 创建 Chrome 浏览器的一个 Options 实例对象
            #driver = webdriver.Chrome()
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument(proxy_url)
            try:

                # 添加屏蔽 --ignore -certificate -errors 提示信息的设置参数项
                chrome_options.add_experimental_option(
                    "excludeSwitches", ["ignore - certificate -errors"])
                driver = webdriver.Chrome(executable_path=chromeDriverFilePath,
                                          chrome_options=chrome_options)
            except Exception as e:
                raise e
        else:
            driver = webdriver.Firefox(executable_path=firefoxDriverFilePath)
        # driver 对象创建成功胡,创建等待类实例对象
        waitUtil = WaitUtil(driver)
    except Exception as e:
        raise e
Пример #2
0
def open_browser(browserName, *args):
    # 打开浏览器
    global driver, waitUtil
    try:
        if browserName.lower() == 'ie':
            driver = webdriver.Ie(executable_path=ieDriverFilePath)
        elif browserName.lower() == 'Firfox':
            driver = webdriver.Firefox(executable_path=firefoxDriverFilePath)
            # driver = webdriver.Chrome(executable_path=chromeDriverFilePath)
            # # 创建chrome浏览器的一个options实例对象
            # chrome_options = Options()
            # # 添加屏蔽 ---ignore -certificate --errors
            # chrome_options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
            # driver = webdriver.Chrome(executable_path=chromeDriverFilePath,
            #                           chrome_options=chrome_options)

        else:

            driver = webdriver.Chrome(executable_path=chromeDriverFilePath)

        # driver 对象创建成果,创建等待类实例对象
        waitUtil = WaitUtil(driver)

    except Exception as e:
        raise e
Пример #3
0
def open_browser():
    #  打开浏览器
    global driver, waitUtil
    try:
        driver = webdriver.Ie()
        waitUtil = WaitUtil(driver)
    except Exception as e:
        raise e
Пример #4
0
def open_browser(*arg):
    # 打开浏览器
    global driver, waitUtil
    try:
        driver = webdriver.Chrome(executable_path = firefoxDriverFilePath)
        # driver对象创建成果后,创建等待类实例对象
        waitUtil = WaitUtil(driver)
    except Exception as err:
        raise err
Пример #5
0
def open_browser(browserName, *arg):
    global driver, waitUtil
    try:
        if browserName.lower() == 'chrome':
            driver = webdriver.Chrome(executable_path=chromeDriverPath)
        else:
            driver = webdriver.Firefox(executable_path=firefoxDriverPath)
        waitUtil = WaitUtil(driver)
    except Exception as e:
        raise e
Пример #6
0
def open_browser(browserName, *args):
    global driver, waitUtil
    try:
        if browserName.lower() == "ie":
            driver = webdriver.Ie(executable_path=ieDriverFilePath)
        elif browserName.lower() == "chrome":
            driver = webdriver.Chrome()
        elif browserName.lower() == "firefox":
            driver = webdriver.Firefox(executable_path=firefoxDriverFilePath)
        waitUtil = WaitUtil(driver)
    except Exception as e:
        raise e
Пример #7
0
def open_browser(browserName, *arg):
    global driver, waitUtil
    try:
        if browserName.lower() == "chrome":
            chrome_options = Options()
            chrome_options.add_experimental_option(
                "excludeSwitches", ["ignore-certificate-errors"])
            driver = webdriver.Chrome(executable_path=chromeDriverFilePath,
                                      chrome_options=chrome_options)
        else:
            driver = webdriver.Firefox(executable_path=firefoxDriverFilePath)
        waitUtil = WaitUtil(driver)
    except Exception as e:
        raise e
class Test_login(object):
    """
    """
    @pytest.fixture(scope="class", autouse=True)
    def prepare(self, driver, env):
        with allure.step("测试数据准备:"):
            pass

        @allure.step("测试数据数据清理:")
        def fin():
            """
            Clean up test environment after testing
            """
            pass

    case, parameter = obj.getElementObject("login")

    @pytest.mark.run(order=1)
    @allure.step(title='登录')
    @pytest.mark.parametrize("case,elements_data", parameter, ids=case)
    def test_login(self, env, driver, case, api, elements_data):
        with allure.step("邮箱登录"):
            url_login = env['host']['ke'] + api['account']['login']
            visit_url(url_login)
            time.sleep(5)
            try:
                assert_title("登录-有道精品课")
                waitutil = WaitUtil(driver)
                username_obj = elements_data["userName"]
                waitutil.visibilityOfElementLocated(username_obj[0],
                                                    username_obj[1])
                userName = getElement(driver, username_obj[0], username_obj[1])
                userName.send_keys(username_obj[2])

                pwd_obj = elements_data["pwd"]
                pwd = getElement(driver, pwd_obj[0], pwd_obj[1])
                pwd.send_keys(pwd_obj[2])

                login_button_obj = elements_data["loginbutton"]
                loginbutton = getElement(driver, login_button_obj[0],
                                         login_button_obj[1])

                loginbutton.click()
                time.sleep(5)
            except Exception as e:
                capturePic = capture_screen(driver)
                logging.debug("失败的截图:{}".format(capturePic))
                error_info = traceback.format_exc()
                logging.debug("error info is:{}".format(error_info))
Пример #9
0
def open_browser(browserName, *arg):
    #打开浏览器
    global driver, waitUtil
    if browserName.lower() == 'ie':
        driver = webdriver.Ie(executable_path=ieDriverFilePath)
    elif browserName.lower() == 'chrome':
        chrome_options = Options()
        chrome_options.add_experimental_option("excludeSwitches",
                                               ["ignore-certificate-errors"])
        driver = webdriver.Chrome(executable_path=chromeDriverFilePath,
                                  chrome_options=chrome_options)
    else:
        driver = webdriver.Ie(executable_path=firefoxDriverFilePath)
    #driver对象创建成功后,创建等待类实例对象
    waitUtil = WaitUtil(driver)
Пример #10
0
def open_browser(browserName, *arg):
    # 打开浏览器
    global driver, waitUtil
    try:
        if browserName.lower() == 'chrome':
            # 创建Chrome浏览器的一个Options实例对象
            chrome_options = Options()
            # 添加屏蔽 --ignore-certificate-errors提示信息的设置参数项
            chrome_options.add_experimental_option(
                "excludeSwitches", ["ignore-certificate-errors"])
            driver = webdriver.Chrome(chrome_options=chrome_options)
        else:
            driver = webdriver.Firefox()
        waitUtil = WaitUtil(driver)
    except Exception as e:
        raise e
Пример #11
0
def open_browser(browserName, *args):
    global driver, waitUtil
    try:
        if browserName.lower() == "chrome":
            chrome_options = Options()
            chrome_options.add_experimental_option(
                "excludeSwitches", ["ignore-certificate-errors"])
            driver = webdriver.Chrome(executable_path=chromeDriverFilePath,
                                      chrome_options=chrome_options)

        else:
            print("你用的不是Chrome浏览器,暂时不支持别的浏览器")
        waitUtil = WaitUtil(driver)
        return driver
    except Exception as e:
        raise e
def open_browser(browserName, *arg):
    global driver, waitUtil
    try:
        if browserName.lower() == 'ie':
            driver = webdriver.Ie(executable_path=ieDriverFilePaht)
        elif browserName.lower == 'chrome':
            chrome_option = Options()
            # 添加屏蔽,提示信息的设置参数项
            chrome_option.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
            driver = webdriver.Chrome(executable_path=chromeDriverFilePath,chrome_options=chrome_option)
        else:
            driver = webdriver.Firefox()
        # 创建等待类实例
        waitUtil = WaitUtil(driver)
    except Exception as e:
        raise e
Пример #13
0
def open_browser(browserName, *arg):
    global driver, waitUtil
    try:
        if (browserName.lower() == 'ie'):
            # driver = webdriver.Ie(executable_path=ieDriverFilePath)
            pass
        elif browserName.lower() == 'chrome':
            chrome_options = Options()
            # 添加屏蔽 --ignore-certificate-errors提示信息的设置参数项
            chrome_options.add_experimental_option(
                "excludeSwitches", ["ignore-certificate-errors"])
            driver = webdriver.Chrome(executable_path=chromeDriverFilePath,
                                      chrome_options=chrome_options)
        else:
            # driver = webdriver.Firefox(executable_path=filefoxDriverFilePath)
            pass
        waitUtil = WaitUtil(driver)
    except Exception, e:
        raise e
Пример #14
0
def open_browser(browserName,*arg):
    # 打开浏览器
    global driver,waitUtil
    try:
        # browserName.lower()=='firefox'
        # #创建firefox浏览器的一个options实例对象
        # firefox_options=Options()
        # #添加屏蔽——ignore—certificate—errors提示信息设置参数项
        # firefox_options.add_experimental_option(
        #     "excludeSwitches",
        #     ["ignore-certificate-errors"])
        # driver=webdriver.Firefox(
        #     executable_path=firefoxDriveFilePath,
        #     firefox_options=firefox_options)

        # 创建一个FirefoxOptions实例,用于存放自定义配置
        option = Options()

        # 设置浏览器打开新标签页而不是打开新窗口
        option.set_preference('browser.link.open_newwindow',3)
        option.set_preference('browser.link.open_newwindow.restriction',0)
        option.set_preference('browser.link.open_newwindow.override.external',3)

        # 设置为0表示下载到桌面,1表示下载到默认路径,2表示下载到自定义路径
        option.set_preference('browser.download.folderList', 0)
        # 在开始下载时是否显示下载管理器
        option.set_preference('browser.download.manager.showWhenStarting', False)
        # 设置为False会把下载框进行隐藏
        option.set_preference('browser.download.useWindow', False)
        # 默认为True,设置为False表示不获取焦点
        option.set_preference('browser.download.focusWhenStarting', True)
        # 对所给文件类型不再弹出提示框进行询问,直接保存到本地磁盘
        option.set_preference('browser.helperApps.neverAsk.saveToDisk'\
        ,'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,vnd.ms-excel,application/octet-stream')
        # 下载完成后不显示下载完成提示框
        option.set_preference('browser.download.manager.showAlertOnComplete', True)
        # 启动浏览器时通过firefox_options参数将自动配置添加到FirefoxOptions对象中
        driver = webdriver.Firefox(executable_path=firefoxDriveFilePath,firefox_options=option)
        waitUtil=WaitUtil(driver)
    except Exception,e:
        raise e
Пример #15
0
def open_browser(browserName,*arg):
    global driver,waitUtil
    try:
        if browserName .lower() =='ie':
            driver = webdriver.Ie(executable_path= ieDriverFilePath )
        elif browserName.lower() == 'chrome':
            chrome_options = Options()
            chrome_options.add_argument('disable-infobars') #去除“chrome正受到自动化测试。。。”的弹出提示框
            chrome_options.add_argument('disable-popup-blocking') #禁用弹窗拦截
            '''
            可能会有用:禁用下载时的安全提示
            download_dir = "/pathToDownloadDir"
            preferences = {"download.default_directory": download_dir,
                           "directory_upgrade": True,
                           "safebrowsing.enabled": True}
            chrome_options.add_experimental_option("prefs", preferences)
            '''
            driver = webdriver.Chrome(executable_path= chromeDriverFilePath ,chrome_options= chrome_options )
        waitUtil = WaitUtil(driver)
    except Exception as e:
        raise e
                capturePic = capture_screen(driver)
                logging.debug("失败的截图:{}".format(capturePic))
                error_info = traceback.format_exc()
                logging.debug("error info is:{}".format(error_info))

    case, parameter = obj.getElementObject("datainfo_rename")

    @pytest.mark.run(order=2)
    @allure.step(title='账户设置更改昵称')
    @pytest.mark.parametrize("case,elements_data", parameter, ids=case)
    def test_rename(self, env, api, driver, case, elements_data):
        with allure.step("更改昵称"):
            url_rename = env['host']['ke'] + api['account']['rename']
            driver.get(url_rename)
            try:
                waitutil = WaitUtil(driver)
                nickname_obj = elements_data["nickname"]
                waitutil.visibilityOfElementLocated(nickname_obj[0],
                                                    nickname_obj[1])
                nicknameelement = getElement(driver, nickname_obj[0],
                                             nickname_obj[1])
            except TimeoutException as e:
                # 捕获TimeoutException异常
                logging.debug("error info is:{}".format(traceback.print_exc()))
            except NoSuchElementException as e:
                # 捕获NoSuchElementException异常
                logging.debug("error info is:{}".format(traceback.print_exc()))
            except Exception as e:
                # 捕获其他异常
                logging.debug("error info is:{}".format(traceback.print_exc()))
            else:
Пример #17
0
def TestSendMailWithAttachment():

    driver = webdriver.Firefox(executable_path="C:\\WebDriver\\geckodriver")
    driver.maximize_window()

    driver.get("http://mail.126.com")
    time.sleep(5)
    assert u"126网易免费邮" in driver.page_source

    wait = WaitUtil(driver)
    wait.frameToBeAvailableAndSwitchToIt('xpath',"//iframe[@name='']")
    username = getElement(driver,"xpath","//input[@name='email']")
    username.send_keys("minwu126")
    passwd = getElement(driver, "xpath", "//input[@name='password']")
    passwd.send_keys("wuli8228680")
    passwd.send_keys(Keys.ENTER)
    time.sleep(10)
    assert u"网易邮箱" in driver.title

    driver.switch_to.default_content()
    time.sleep(5)

    addressBook = wait.visibilityOfElementLocated("xpath","//div[text()='通讯录']")
    addressBook.click()
    newContact = wait.visibilityOfElementLocated("xpath","//span[text()='新建联系人']")
    newContact.click()

    contactName = wait.visibilityOfElementLocated("xpath","//a[@title='编辑详细姓名']/preceding-sibling::div/input")
    contactName.send_keys("LILY")
    email = getElement(driver,"xpath","//*[@id='iaddress_MAIL_wrap']//input")
    email.send_keys("*****@*****.**")
    getElement(driver,"xpath","//span[text()='设为星标联系人']/preceding-sibling::span/b").click()

    mobile=getElement(driver,"xpath","//*[@id='iaddress_TEL_wrap']//dd//input")
    mobile.send_keys("18888888891")

    getElement(driver,"xpath","//textarea").send_keys(u"朋友") #备注
    getElement(driver,"xpath","//span[text()='确 定']").click()
    time.sleep(2)

    assert u"*****@*****.**" in driver.page_source
    print(u"添加成功")
    time.sleep(3)
    getElement(driver,"xpath","//div[.='首页']").click()
    time.sleep(2)
    element = wait.visibilityOfElementLocated("xpath","//span[text()='写 信']")
    element.click()
    print(u"写信")

    receiver = getElement(driver,"xpath","//div[contains(@id,'_mail_emailinput')]//input")

    receiver.send_keys("*****@*****.**")
    subject = getElement(driver,"xpath","//div[@aria-label='邮件主题输入框,请输入邮件主题']/input")
    subject.send_keys(u"新邮件")
    attachment=getElement(driver,"xpath","//div[@title='点击添加附件']/input[@size='1' and @type='file']")
    attachment.send_keys("d:\\a.txt")

    time.sleep(5)

    wait.frameToBeAvailableAndSwitchToIt("xpath","//iframe[@tabindex=1]")
    body= getElement(driver,"xpath","/html/body")
    body.send_keys(u"发给自己的一封信")

    driver.switch_to_default_content()

    getElement(driver,"xpath","//header//span[text()='发送']").click()
    print(u"开始发送邮件")
    time.sleep(3)
    assert u"发送成功"in driver.page_source
    driver.quit()