91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

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

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

關鍵字驅動模式 實現登錄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

鲁山县| 色达县| 汨罗市| 蕉岭县| 喜德县| 界首市| 开远市| 罗甸县| 平陆县| 富民县| 兰州市| 山丹县| 曲沃县| 会昌县| 海口市| 宾阳县| 越西县| 湛江市| 布拖县| 内江市| 姚安县| 双峰县| 潼南县| 广安市| 铜山县| 徐汇区| 阿尔山市| 前郭尔| 阜康市| 青海省| 秭归县| 萍乡市| 丰宁| 滕州市| 彭阳县| 钟山县| 玛纳斯县| 桃江县| 碌曲县| 嘉荫县| 信阳市|