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!")
  • 相关阅读:
    git clone --early EOF
    weex 小结 -- <list>
    weex 小结 --官方扩展组件
    weex 小结--内建模块
    viewPager 的可滑动 Title
    viewPager + fragment
    onInterceptTouchEvent / onTouchEvent响应事件的详析
    startActivity跳转失败而且没有异常信息
    ios2048
    插入排序
  • 原文地址:https://www.cnblogs.com/ff-gaofeng/p/12670279.html
Copyright © 2011-2022 走看看