亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

關鍵字驅動模式 實現登錄qq郵箱并發送郵件的自動化測試

發布時間:2020-07-17 18:33:48 來源:網絡 閱讀:956 作者:qq5a16e6241946e 欄目:編程語言

測試數據文件
關鍵字驅動模式 實現登錄qq郵箱并發送郵件的自動化測試


測試腳本:
#encoding=utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By

#定義獲取excel所有行的方法
def get_rows(file_path):

    from openpyxl import load_workbook
    try:
        wb = load_workbook(file_path)
        sheet = wb.active
        rows = []
        for row in sheet.iter_rows():
            rows.append(row)
        return rows
    except Exception as e:
        print(e)

#定義獲取頁面元素的方法
def get_element(driver,locateType,locatorexpression):
    try:
        if locateType.lower() == "id":
            locateType = By.ID
        elif locateType.lower() == "xpath":
            locateType = By.XPATH

        element = driver.find_element(locateType,locatorexpression)
        #print(element)
        return element
    except Exception as e:
        raise e

#打開瀏覽器關鍵字
def open_browser(browser):
    global driver
    try:
        if browser.lower() == "chrome":
            driver = webdriver.Chrome(executable_path="e:\\chromedriver")
        elif browser.lower() == "firefox":
            driver = webdriver.Firfox(executable_path = "e:\\geckodriver")
    except Exception as e:
        raise e

#訪問指定網址關鍵字
def visit_url(url):
    global driver
    try:
        driver.get(url)
    except Exception as e:
        raise e

#輸入框輸入內容關鍵字   
def input_string(locateType,locatorexpression,content):
    global driver
    try:
        element = get_element(driver,locateType,locatorexpression)
        element.send_keys(content)
    except Exception as e:
        raise e

#點擊按鈕關鍵字
def click(locateType,locatorexpression):
    global driver
    try:
        element = get_element(driver,locateType,locatorexpression)
        element.click()
    except Exception as e:
        raise e

#暫停等待關鍵字
def pause(seconds):
    import time
    try:
        time.sleep(seconds)
    except Exception as e:
        raise e

#切換進入指定frame關鍵字      
def switch_to_frame(locateType,locatorexpression):
    global driver
    try:
        element = get_element(driver,locateType,locatorexpression)
        driver.switch_to.frame(element) 
    except Exception as e:
        raise e  
#從子frame切換回主frame關鍵字
def switch_to_parent_frame():
    global driver
    try:

        driver.switch_to.parent_frame() 
    except Exception as e:
        raise e      

#斷言關鍵字
def assert_word(assertWord):
    global driver
    try:
        assert assertWord in driver.page_source
    except Exception as e:
        raise e

#退出瀏覽器驅動,并關閉所有瀏覽器窗口關鍵字
def close_browser():
    global driver
    try:
        driver.quit()
    except Exception as e:
        raise e
#測試主函數,實現測試主邏輯
def main():
    import traceback
    try:
        test_file_path = "G:\\個人\\學習\\光榮之路\\自動化\\自動化練習\\testdata.xlsx"
        excel_rows = get_rows(test_file_path)
        #遍歷測試數據庫文件excel的每行
        for row in excel_rows[1:]:
            action = row[1].value
            locateType = row[2].value
            locatorExpression = row[3].value
            operateValue = row[4].value
            #print(action,locateType,locatorExpression,operateValue)
            #根據每行的內容拼接需要執行的關鍵字
            if locateType == None and locatorExpression == None and operateValue == None:
                command = "%s()"  %action
            elif locateType == None and locatorExpression == None and operateValue != None:
                if  isinstance(operateValue,int):
                    command = "%s(%d)" %(action,operateValue)
                else:
                    command = "%s('%s')" %(action,operateValue)
            elif locateType != None and locatorExpression != None and operateValue == None:
                command = "%s('%s','%s')" %(action,locateType,locatorExpression)
            elif locateType != None and locatorExpression != None and operateValue != None:
                command = "%s('%s','%s','%s')" %(action,locateType,locatorExpression,operateValue)
            print(command)
            try:
                #執行關鍵字函數
                eval(command)
            except Exception as e:
                print(traceback.print_exc())

    except Exception as e:
        print(e)
if __name__ == "__main__":
    main()
    #driver = webdriver.Chrome(executable_path = "e:\\chromedriver")
    #driver.get("http://mail.qq.com")
    #login_frame = driver.find_element(By.XPATH,'//iframe[@id="login_frame"]')
    #print(login_frame)
    #driver.switch_to.frame(login_frame)
    #username = driver.find_element(By.XPATH,'//input[@id="u"]')
    #username.send_keys("xxxx")
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

壶关县| 宝丰县| 奉新县| 航空| 内丘县| 策勒县| 靖边县| 伊吾县| 石棉县| 长垣县| 澳门| 外汇| 夏河县| 桐庐县| 平塘县| 庄河市| 靖安县| 文山县| 陕西省| 麦盖提县| 安义县| 巧家县| 宣汉县| 大姚县| 久治县| 北海市| 桑植县| 东安县| 南京市| 图们市| 瑞安市| 大化| 曲松县| 花垣县| 通辽市| 攀枝花市| 眉山市| 营口市| 静宁县| 宁国市| 彰化县|