zoukankan      html  css  js  c++  java
  • python webdriver关键字框架

    关键字框架推荐使用eval,不使用exec

    eval()函数有返回值,exec()函数无返回值

    teststep.txt

    open||chrome
    visit||https://www.126.com
    click||switchAccountLogin
    sleep||3

    主程序脚本

    keyword.py

    #encoding=utf-8
    from selenium import webdriver
    import time

    with open("teststep.txt") as fp:
    teststeps = fp.readlines()

    driver = ""

    def open(browser_name):
    global driver
    if "ie" in browser_name:
    driver = webdriver.Ie(executable_path = "e:\IEDriverServer")
    elif "chrome" in browser_name:
    driver = webdriver.Chrome(executable_path = "e:\chromedriver")
    else:
    driver = webdriver.Firefox(executable_path = "e:\geckodriver")

    def visit(url):
    global driver
    driver.get(url)

    def click(id):
    try:
    driver.find_element_by_id(id).click()
    except:
    print("click fail!")
    raise

    def sleep(times):
    time.sleep(int(times))

    for teststep in teststeps:
    action = teststep.split("||")[0] #action = "open"
    value= teststep.split("||")[1].strip() #value= "chrome"
    try:
    command = "%s("%s")" %(action,value) # 拼接函数func(参数1,参数2)"open("chrome")"
    eval(command) #利用eval()执行函数 open("chrome")
    except:
    print("执行",command,"有异常")

    print ("DONE!")
  • 相关阅读:
    C++并发编程实战---阅读笔记
    设计模式---命令模式
    图解HTTP(六)HTTP首部
    HTTP 状态码
    使用VS2012调试Dump文件
    如何设置C++崩溃时生成Dump文件
    boost::asio::io_service类
    boost::asio 同步&异步例子
    boost::bind
    c++并发编程之原子操作的实现原理
  • 原文地址:https://www.cnblogs.com/ff-gaofeng/p/12670279.html
Copyright © 2011-2022 走看看