内容简介:最近在学习selenium自动化测试相关的内容,所以将实际准备情况做一记录,Selenium是一款适用于Web应用程序的便携式软件测试框架。 Selenium为编写测试提供了一个回放工具,无需学习测试脚本语言。它还提供了一种测试领域特定的语言,用于编写包括C#,Groovy,Java,Perl,PHP,Python,Ruby和Scala等多种流行编程语言的测试。Selenium官网地址:
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:\Users\Administrator\AppData\Local\Programs\Python\Python36中,但是推荐放置在scripts目录中:C:\Users\Administrator\AppData\Local\Programs\Python\Python36\Scripts
完成以上工作,我们就可以进行测试使用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并结束了此次测试,如果是exit()只是关闭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自动化测试的准备工作~
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- Appium自动化(1) - 环境准备详细教程
- php – Laravel:一般错误:1615准备好的声明需要重新准备
- 详解Openstack环境准备
- 深度有趣 | 02 准备工作
- 2019 面试准备 - 图片
- 如何准备JS迁移
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Designing for Emotion
Aarron Walter / Happy Cog / 2011-10-18 / USD 18.00
Make your users fall in love with your site via the precepts packed into this brief, charming book by MailChimp user experience design lead Aarron Walter. From classic psychology to case studies, high......一起来看看 《Designing for Emotion》 这本书的介绍吧!