TypechoJoeTheme

Misty rain的博客

统计

python ui自动化框架 2:统一配置文件,读取配置文件,统一打开浏览器方法

2021-12-20
/
80 评论
/
788 阅读
/
正在检测是否收录...
12/20

本节讲解:统一项目的配置文件,方便统一修改,然后读取配置文件

新建项目
使用PyCharm新建一个普通项目:uitest(项目名称)

新建config目录,然后新建config.ini文件

#  配置测试要使用的浏览器和要测试的网站url

[browserType]
#browserName = Firefox
browserName = Chrome
#browserName = IE

[testServer]
URL = https://www.baidu.com/

配置公共类
1、新建commont目录
2、将“公共类”(3)个复制到commont目录:gettime.py(时间) getfileposition.py(文件) getlog.py(日志)
3、新建log目录(用来存放log日志)

读取config
1、在commont目录下新建browser_engine.py(浏览器统一配置文件),读取browser和url

config = configparser.ConfigParser()
file_path = file.getrootpath() + '/config/config.ini'
config.read(file_path)
# config.read(file_path,encoding='UTF-8'), 如果代码有中文注释,用这个,不然报解码错误
browser = config.get("browserType", "browserName")
url = config.get("testServer", "URL")

2、在browser_engine.py中新建open_browser来完成打开浏览器操作

"""
@Author:Misty rain(ZhangHao)
@E-mail:676817831@qq.com
@FileName:browser_engine.py
@Software:PyCharm
@Desc:
"""
import configparser
from selenium import webdriver
import commont.getfileposition as file
import commont.getlog as log

logger = log.logger


def open_browser(driver, text):
    config = configparser.ConfigParser()
    file_path = file.getrootpath() + '/config/config.ini'
    config.read(file_path)
    # config.read(file_path,encoding='UTF-8'), 如果代码有中文注释,用这个,不然报解码错误
    browser = config.get("browserType", "browserName")
    url = config.get("testServer", "URL")
    logger.info("您测试需要的URL: %s" % url)
    logger.info("您测试需要的模块:" + text)
    if browser == "Firefox":
        driver = webdriver.Firefox()
        logger.info("您测试需要的浏览器:Firefox")

    elif browser == "Chrome":
        driver = webdriver.Chrome()
        logger.info("您测试需要的浏览器:Chrome")

    elif browser == "IE":
        driver = webdriver.Ie()
        logger.info("您测试需要的浏览器:IE")
    driver.get(url)
    driver.maximize_window()
    logger.info("浏览器窗口最大化")
    driver.implicitly_wait(10)
    logger.info("10秒")
    return driver

该方法集成了log和file文件位置的公共方法。
调用open_browser传入当前类、要测试的模块text 来打开浏览器
调用quit_browser来关闭浏览器。

ui自动化
朗读
赞(7)
版权属于:

Misty rain的博客

本文链接:

http://101.42.223.25/index.php/archives/51/(转载时请注明本文出处及文章链接)

评论 (80)
  1. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  2. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  3. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  4. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  5. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  6. 1 作者
    Windows 10 · Google Chrome

    1Ft89Pk92O

    2022-04-28 回复
  7. 1 作者
    Windows 10 · Google Chrome

    %0abcc:009247.351-135830.351.e1d9e.19110.2@bxss.me

    2022-04-28 回复
  8. 0FxVyzRV 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  9. ../../../../../../../../../../../../../../etc/passwd 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  10. 1 作者
    Windows 10 · Google Chrome

    MqPdRDwW

    2022-04-28 回复
  11. 1 作者
    Windows 10 · Google Chrome

    1*1

    2022-04-28 回复
  12. 1 作者
    Windows 10 · Google Chrome

    1*1

    2022-04-28 回复
  13. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  14. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  15. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    WGOT(9611)

    2022-04-28 回复
  16. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    VtBW(9434)

    2022-04-28 回复
  17. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    1xRk(9512)

    2022-04-28 回复
  18. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    BK6Z(9497)

    2022-04-28 回复
  19. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  20. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  21. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  22. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  23. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  24. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  25. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    qW6j(9927)

    2022-04-28 回复
  26. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    aNy7(9859)

    2022-04-28 回复
    1. 1pHLZaeqxO 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    2. 1 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    3. 1 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    4. 1 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    5. -1 OR 2+731-731-1=0+0+0+1 -- 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    6. vtoUsguf 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    7. ../../../../../../../../../../../../../../etc/passwd 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    8. 1 作者
      Windows 10 · Google Chrome
      @1

      1DHKd5cVNAO

      2022-04-28 回复
    9. -1 OR 2+751-751-1=0+0+0+1 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    10. ${9999459+9999152} 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    11. 1%0abcc:009247.351-330822.351.d61ab.19110.2@bxss.me 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    12. 1&n939598=v948624 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    13. http://some-inexistent-website.acu/some_inexistent_file_with_long_name%3F.jpg 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    14. SomeCustomInjectedHeader: injected_by_wvs 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    15. HttP://bxss.me/t/xss.html?%00 作者
      Windows 10 · Google Chrome
      @1

      1

      2022-04-28 回复
    16. 1 作者
      Windows 10 · Google Chrome
      @1

      555

      2022-04-28 回复
  27. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    Vr71(9156)

    2022-04-28 回复
  28. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    JvcV(9285)

    2022-04-28 回复
  29. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  30. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  31. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  32. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  33. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  34. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  35. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  36. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  37. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  38. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  39. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  40. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  41. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  42. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  43. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  44. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  45. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  46. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  47. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  48. 1 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  49. 1 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  50. -1 OR 2+220-220-1=0+0+0+1 -- 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  51. -1 OR 2+332-332-1=0+0+0+1 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  52. -1' OR 2+57-57-1=0+0+0+1 -- 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  53. -1' OR 2+357-357-1=0+0+0+1 or 'oFOuXloO'=' 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  54. the 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  55. 1 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  56. 1 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  57. 1 作者
    Windows 10 · Google Chrome

    5w7IDjAZ' OR 914=(SELECT 914 FROM PG_SLEEP(15))--

    2022-04-28 回复
  58. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    JI2j(9630)

    2022-04-28 回复
  59. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    ErlR(9416)

    2022-04-29 回复
  60. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-29 回复
  61. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-29 回复
  62. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-29 回复
  63. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-29 回复
  64. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-29 回复

备案号: 浙ICP备2021040483号