zoukankan      html  css  js  c++  java
  • Python3+Selenium3自动化测试-(准备)

    Python3+Selenium3自动化测试-(准备)

    最近在学习selenium自动化测试相关的内容,所以将实际准备情况做一记录,

    # 系统:win10(64位)
    # 浏览器:Chrome(67.0)、Firefox(61.0)、IE
    # python版本:3.6.5
    # Selenium:3.13.0

    Selenium简介

    Selenium是一款适用于Web应用程序的便携式软件测试框架。 Selenium为编写测试提供了一个回放工具,无需学习测试脚本语言。它还提供了一种测试领域特定的语言,用于编写包括C#,Groovy,Java,Perl,PHP,Python,Ruby和Scala等多种流行编程语言的测试。

    Selenium官网地址:https://www.seleniumhq.org/

    Python安装

    python官网地址:https://www.python.org/

    从python官网下载对应版本的python安装包,正常安装,需要注意的是需要将python加入环境变量中,可在安装的界面选择将Python加入环境变量中。

    环境变量设置:

    我的电脑>>属性>>高级系统设置>>环境变量中编辑用户变量和系统变量

    Selenium的安装与测试

    Selenium安装

    使用python可直接利用pip进行安装selenium

    启动cmd,注意:需要以管理员身份运行

    pip install -U selenium

    浏览器驱动driver安装

    浏览器驱动driver的下载

    driver的下载应该是比较坑的部分,一定需要注意浏览器版本。

    selenium官网进入下载界面,这个时候请往下拉,虽然第三方的浏览器都不是selenium官方开发的,但是你可以在selenium官网找到selenium支持的浏览器相对应的驱动driver下载链接,因为我在本地使用的浏览器版本都是比较新的,所以对应的driver版本也都下载最新版即可。

    这里还是粘上三大浏览器的下载链接:

    Google Chrome driver:https://sites.google.com/a/chromium.org/chromedriver/downloads

    Mozilla GeckoDriver:https://github.com/mozilla/geckodriver/releases

    Internet Explorer Driver:http://selenium-release.storage.googleapis.com/3.13/IEDriverServer_x64_3.13.0.zip

    浏览器驱动driver的安装

    下载下来的zip文件解压至python安装目录中,可以放置在:C:UsersAdministratorAppDataLocalProgramsPythonPython36中,但是推荐放置在scripts目录中:C:UsersAdministratorAppDataLocalProgramsPythonPython36Scripts

     完成以上工作,我们就可以进行测试使用selenium驱动浏览器了

    测试驱动浏览器

    CMD中启动python并从selenium引入webdriver包

    from selenium import webdriver

    驱动chrome浏览器

    Ch_driver = webdriver.Chrome()
    Ch_driver.get("https://www.google.com")
    Ch_driver.quit() # 使用quit()关闭了chrome并结束了此次测试,如果是close()只是关闭chrome,后台仍在进行。

    驱动Firefox浏览器

    Fi_driver = webdriver.Firefox()
    Fi_driver.get("https://www.google.com")
    Fi_driver.quit()

    驱动IE浏览器

    Ie_driver = webdriver.Ie()
    Ie_driver.get("https://www.google.com")
    Ie_driver.quit()

    看起来都正常驱动浏览器并打开了网页,这样我们就完成了selenium自动化测试的准备工作~

  • 相关阅读:
    【tips】Clion添加Qt gui绘制快捷方式
    conda配置安装pytorch tensorflow-gpu
    用当前最新版vs2019编译opencv最新版4.3.0遇到的问题---
    cuda报错: nvcc fatal : Host compiler targets unsupported OS
    C++中结构体与类的区别(struct与class的区别)
    cmake
    Windows 下配置Boost MPI
    VC----MFC对象的创建总结
    VC++、MFC最好的开源项目
    机械设计人员怎么学习电控?
  • 原文地址:https://www.cnblogs.com/lvzb86/p/9262153.html
Copyright © 2011-2022 走看看