web 网站
QTP、selenium
pc端软件
用的少
移动端
appium
用于完成web网页自动化测试,
selenium(化学元素:硒), 不得不提QTP的工具,2004年左右开始出现,qtp(汞)收费的,不开源,所以就使用成本比较高,
硒可以解汞的毒
2016年出现的这个版本,
selenium IDE:提供了将操作转换为代码的功能,会记录人的动作,转换为selenium代码
selenium webdriver: 提供了控制浏览器执行的功能
selenium Grid: 提供了分布式执行测试用例的能力
注意:
谷歌、火狐、edge、ie(已经被放弃)、欧朋) 3.0的时候浏览器都由各自浏览器厂商开发
提供了相对定位的功能
selenium Grid:支持k8s上部署
pip install selenium==3.14
谷歌、火狐、edge
根据浏览器版本下载 edge(https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/)
谷歌的驱动下载网站打不开,所以要使用淘宝的备用地址
http://chromedriver.storage.googleapis.com/index.html
http://npm.taobao.org/mirrors/chromedriver/
查看浏览器版本 ↓,我的版本为107.0.5304.88
创建D:\tools\driver 将驱动放到这个路径中去
要将这个路径添加到环境变量path 中 D:\tools\driver , 添加之后需要重启电脑 才能生效
下面展示一些 代码片
。
from selenium import webdriver# 打开一个浏览器
chrome = webdriver.Chrome()# 浏览器最大化
chrome.maximize_window()#隐式等待
chrome.implicitly_wait(10)# 打开网页
chrome.get("http://127.0.0.1:8080")chrome.find_element_by_css_selector('input[placeholder="请输入账号"]').send_keys("admin")
chrome.find_element_by_css_selector('input[placeholder="请输入密码"]').send_keys("123456")chrome.find_element_by_css_selector('button[class="el-button login-submit el-button--primary el-button--small"]').click()
from selenium import webdriver
import time
driver = webdriver.Edge()
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("http://172.16.3.153:8888/EasyBuy/Home?action=index")
# driver.find_element_by_css_selector('a[href="/EasyBuy/Login?action=toLogin"]').click()driver.find_element_by_xpath('//a[@href="/EasyBuy/Login?action=toLogin"]').click()
time.sleep(2)
driver.find_element_by_id('loginName').send_keys("admin")
driver.find_element_by_id("password").send_keys("123456")
driver.find_element_by_css_selector('input[οnclick="login();"]').click()
上一篇:【刷题】二叉树遍历思路解析