中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

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

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

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

徐闻县| 子长县| 清涧县| 鄂州市| 都匀市| 昌宁县| 潞西市| 兴文县| 云阳县| 亳州市| 辽源市| 湟中县| 皋兰县| 夹江县| 阿克| 祁东县| 白河县| 周宁县| 綦江县| 北京市| 丹东市| 广汉市| 吉隆县| 奇台县| 泊头市| 嵊泗县| 镇平县| 阳西县| 锦屏县| 同仁县| 永善县| 徐闻县| 蓬莱市| 鄂伦春自治旗| 榆树市| 永和县| 怀仁县| 宽甸| 阳山县| 五原县| 五指山市|