当前位置:网站首页>Do you understand how the Selenium automated testing framework works?
Do you understand how the Selenium automated testing framework works?
2022-08-11 04:42:00 【Soft Test Small Watermelon】
目录
一、Selenium是什么?
In a word from the official website:Selenium automates browsers. That's it!简单来讲,Selenium是一个用于Web应用程序自动化测试工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作浏览器一样.支持的浏览器包括IE,Firefox,Safari,Chrome等.Selenium 不仅仅是一个工具或 API,It also makes up many tools
(Translation software is used above,Some translations are inaccurate,Please read at your own discretion)
WebDriver
如果你开始使用桌面网站或移动网站测试自动化,那么你将使用 webdriverapi. Webdriver 使用浏览器厂商提供的浏览器自动化 api 来控制浏览器和运行测试. 这就好像是一个真正的用户在操作浏览器. 由于 WebDriver 不需要使用应用程序代码编译其 API,因此它不具有侵入性. 因此,您测试的应用程序与实时推送的应用程序相同.
IDE
Ide (集成开发环境)是您用来开发 Selenium 测试用例的工具. 它是一个易于使用的 Chrome 和 Firefox 扩展,并且通常是开发测试用例的最有效的方法. 它使用现有的 Selenium 命令记录用户在浏览器中的操作,参数由该元素的上下文定义. 这不仅是一个节省时间的方法,也是学习 Selenium 脚本语法的一个很好的方法.
Grid
Selenium Grid 允许您跨不同平台在不同的机器上运行测试用例. 触发测试用例的控制位于本地端,当触发测试用例时,它们将由远程端自动执行.
在 WebDriver 测试开发之后,您可能需要在多个浏览器和操作系统组合上运行测试. 这就是Grid出现的地方.
二、Selenium History
2004年,诞生了Selenium Core,Selenium Core是基于浏览器并且采用JavaScript编程语言的测试工具,运行在浏览器的安全沙箱中,设计理念是将待测试产品、Selenium Core和测试脚本均部署到同一台服务器上来完成自动化测试的工作.
2005年,Selenium RC诞生,就是selenium1 ,这个时候,Selenium Core其实是Selenium RC的核心.Selenium RC让待测试产品、Selenium Core和测试脚本三者分散在不同的服务器上.(测试脚本只关心将HTTP请求发送到指定的URL上,selenium本身不需要关心HTTP请求由于什么程序编程语言编写而成),Selenium RC包括两部分:一个是Selenium RC Server,一个是提供各种编程语言的客户端驱动来编写测试脚本
2007年,Webdriver诞生,WebDriver的设计理念是将端到端测试与底层具体的测试工具分隔离,并采用设计模式Adapter适配器来达到目标.WebDriver的API组织更多的是面向对象.
2008年,selenium2诞生,selenium2其实是selenium rc和webdriver的合并,合并的根本原因是相互补充各自的缺点
2009年,selenium3诞生,这个版本剔除了selenium rc , 主要由 selenium webdriver和selenium Grid组成, 我们日常使用的其实就是selenium webdriver,至于selenium grid是一个分布式实现自动化测试的工具
三、Selenium原理
本文所讲的Selenium是指Selenium Webdriver,Selenium WebDriver与RC的功能相同,and contains the original1.x绑定.It involves language bindings and the implementation of individual browser control code.这通常被称为“WebDriver”,有时也被称为Selenium 2.Selenium 1.0 + WebDriver = Selenium 2.0
WebDriverDesigned in a simpler and more concise programming interface,同时解决了Selenium-RC APIsome limitations.
与Selenium1.0相比,WebDriver是一个紧凑的面向对象的API
It drives the browser more efficiently,并克服了Selenium 1.x的限制,This affects our functional test coverage,Such as file upload or download,Popups and dialogs
在用SeleniumCorrespondence must be introduced when conducting automated testsjar包,比如selenium-server-standalone-2.46.0.jar,selenium-java-2.47.1.jar,3+The above versions may vary,我们看到有个sever这么一个jar包,这个jar包就是Selenium服务,serverThe client can be any browser asremote server,Responsibility is to deal withclientrequest and act accordingly,clientis the script we run,responseThe specific content depends on the content of the request,我们以firefox为例,如下图所示
四、Selenium工作过程总结:
- selenium client(Java等语言编写的自动化测试脚本)初始化一个service服务,通过Webdriver启动浏览器驱动程序
- 通过RemoteWebDriver向浏览器驱动程序发送HTTP请求,浏览器驱动程序解析请求,打开浏览器,并获得sessionid,如果再次对浏览器操作需携带此id
- 打开浏览器,绑定特定的端口,把启动后的浏览器作为webdriver的remote server
- 打开浏览器后,所有的selenium的操作(访问地址,查找元素等)均通过RemoteConnection链接到remote server,然后使用execute方法调用_request方法通过urlib3向remote server发送请求
- 浏览器通过请求的内容执行对应动作
- 浏览器再把执行的动作结果通过浏览器驱动程序返回给测试脚本
五、remote server端的这些功能是如何实现的呢?
浏览器实现了webdriver的统一接口,client就可以通过统一的restful的接口去进行浏览器的自动化操作.
目前webdriver支持ie, chrome, firefox等主流浏览器,The main reason for this is that these browsers implement itwebdriverVarious interfaces agreed upon.
Take a chestnut that opens a browser:
package com.Demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ExampleForFirefox {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox 24\\firefox.exe");
WebDriver driver = new FirefoxDriver();
System.out.println("https://www.cnblogs.com/mrjade/");
driver.get("https://www.cnblogs.com/mrjade/");
}
}
六、附:
各版本Chrome下载地址:Google Chrome 64bit Windows版_chrome浏览器,chrome插件,谷歌浏览器下载,谈笑有鸿儒
Selenium Chrome版本与chromedriverCompatible version comparison table:2019 Selenium Chrome版本与chromedriverCompatible version comparison table_YOYO测试的博客-CSDN博客_chrome对应selenium版本
各版本ChromeDriver下载地址:http://npm.taobao.org/mirrors/chromedriver/
边栏推荐
- "3 Longest Substring Without Repeating Characters" on the 17th day of LeetCode brushing
- Where can machine learning be applied?What is machine learning useful for?
- Word2021 中的图片保存后就变模糊了
- 「转」“搜索”的原理,架构,实现,实践,面试不用再怕了
- Dry goods: The principle and practice of server network card group technology
- Map中的getOrDefualt方法
- [Web3 series development tutorial - create your first NFT (9)] How to view your NFT in the mobile wallet
- 自研能力再获认可,腾讯云数据库入选 Forrester Translytical 报告
- 网络安全培训机构哪家好?排名怎么选择?
- [C Language] Getting Started
猜你喜欢
"125 Palindrome Verification" of the 10th day string series of LeetCode brushing questions
"3 Longest Substring Without Repeating Characters" on the 17th day of LeetCode brushing
Word2021 中的图片保存后就变模糊了
Apache初体验
Which one to choose for mobile map development?
洛谷P2150 寿司晚宴
Where can machine learning be applied?What is machine learning useful for?
Jetson Orin platform 4-16 channel GMSL2/GSML1 camera acquisition kit recommended
Three 】 【 yolov7 series of actual combat from 0 to build training data sets
Self-research capability was recognized again, and Tencent Cloud Database was included in the Forrester Translytical report
随机推荐
洛谷P2150 寿司晚宴
Map中的getOrDefualt方法
源代码加密技术浅析
堆排序 和冒泡排序
send_sig: 内核执行流程
分层架构&SOA架构
LeetCode814 Math Question Day 15 Binary Tree Series Value "814 Binary Tree Pruning"
map and set - natural search and lookup semantics
"239 Sliding Window Maximum Value" on the 16th day of LeetCode brushing
力扣——旋转数组的最小数字
LeetCode刷题第12天二叉树系列之《104 二叉树的最大深度》
标识密码技术在 IMS 网络中的应用
走出迷宫的最短路径
每日一题-滑动窗口
Callable实现多线程
I wrote some code in my resume, but I still can't pass the interview
【yolov7系列三】实战从0构建训练自己的数据集
LeetCode刷题第10天字符串系列之《125回文串验证》
如何将360全景图导出高清短视频分享到视频平台上?
视觉任务种常用的类别文件之一json文件