Selenium3 有哪些变化?

其实相对于与Selenium2,Selenium3没有做太多的改动。下面给出官方的文档说明,供参考。

参考文档:https://seleniumhq.wordpress.com/2013/08/28/the-road-to-selenium-3/

  1. “We aim for Selenium 3 to be “a tool for user-focused automation of mobile and web apps”,Developers from projects such as Appium, ios-driver and selendroidwill be working on the suite of tests to enable this.”
  2. “Selenium 3 will see the removal of the original Selenium Core implementations, and consequently we’ll be deprecating the RC APIs too,the original implementation will be available as a download, but it will no longer be actively developed once we release 3.0.”

所以对于Selenium3来说最大的变动可能就是更加专注于手机和web的测试,尤其是手机的支持,因为你晓得的,现在更多的是移动的时代。

对于Selenium2中对于RemotControl的实现我看了下Selenium3的源码发现确实不在支持,而更多的转向了W3C standard,不是独成一套Selenium自己的WebDriver API.关于这个需要插如一下有关W3C WebDriver的知识。

有关W3C WebDriver

参考文档: https://www.w3.org/TR/webdriver/,https://www.w3.org/testing/Activity,https://github.com/w3c/webdriver

W3C组织制定了一套浏览器自动化的规范叫做WebDriver,这套规范规定了所有的浏览器生产商都必须遵守这个规范。其实定义了好多的遵循的接口和WebDriver的概念。对于Chrome,Firefox,Opera,Safari.etc他们都需要遵守这个规范并且实现规范里面的接口,这些实现一般都是伴随浏览器的开发进行的。

所以你应该明白了,Selenium不管是WebDriver还是RemoteWebDriver都是W3C WebDriver的一种实现而已。真正的核心浏览器的交互在对应的浏览器的WebDriver上,其实你有了对应的浏览器的WebDriver,参考W3C的标准接口文档HTTP-based wire protocol你就可以单独实现浏览器的操作。就是Client-Server的沟通。所有支持的命令列表如下:

举个ChromeDriver的例子。。。

  • 首先我们找到ChromeDriver ,这个自然到chromium项目上去下载就好了。

https://sites.google.com/a/chromium.org/chromedriver/这里也有很多详细的接口的说明,这里的接口说明跟上面的W3C的接口说明差不多。你需要针对不同的浏览器下载对应的版本。下面我以下载的一个win版本的为例(下载地址:http://chromedriver.storage.googleapis.com/2.23/chromedriver_win32.zip )

WebDriver的使用                                                                  

1.1 查看下chromedriver.exe提供给我们的一些可用的命令。

里面的使用很详细,这里我们只需要使用一个参数来启动ChromeDriver的server, –port ,命令如下:chromedriver.exe –port 9514,或者直接不输入端口直接回车,界面命令如下:

启动后chromedriver会在本地的9514端口号上进行监听通信,根据不同的命令发送到浏览器上,浏览器进行交互。比如启动一个chrome浏览器对应的命令是session,单独的ChromeDriver的HTTP通信URI是:http://localhost:9514/session,对于通过RemoteWebDriver的URL是:http://localhost:9514/wd/hub/session

WebDriver -New Session

看一下这个说明: https://www.w3.org/TR/webdriver/#dfn-new-session,操作流程如下:

The remote end steps are:

  1. If the remote end is an intermediary node, take implementation-defined steps that either result in returning an error with error code session not created, or in returning a success with data that is isomorphic to that returned by remote ends according to the rest of this algorithm.

  2. If the maximum active sessions is equal to the length of the list of active sessions, return error with error code session not created.

  3. If there is a current user prompt, return error with error code session not created.

  4. Let capabilities be the result of getting a property named "capabilities" from the parameters argument.

  5. Let capabilities result be the result of processing capabilities with capabilities as an argument.

  6. If capabilities result is an error, return error with error code session not created.

  7. Let capabilities be capabilities result’s data.

  8. Let session id be the result of generating a UUID.

  9. Let session be a new session with the session ID of session id.

  10. Set the current session to session.

  11. Append session to active sessions.

上面的流程已经在最新的Selenium WebDriver中实现了。所有启动一个浏览器做的session操作可以参考如下核心Selenium代码逻辑。

1. 第一步设置chromeDriver的路径后面代码用到:System.setProperty("webdriver.chrome.driver", "chromedriver.exe");

2. 第二步构建一个命令行对象用于执行chromedriver.exe的命令:

org.openqa.selenium.remote.service.DriverService.Builder.build()

public DS build() {
     if (port == 0) {
       port = PortProber.findFreePort(); //可用的端口号,例如232323,那么后面用到的命令就是:chromedriver.exe –port 232323
     }

if (exe == null) {
       exe = findDefaultExecutable();
     }

ImmutableList<String> args = createArgs();

return createDriverService(exe, port, args, environment);
   }

1. 核心selenium命令执行类:org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriver(CommandExecutor, Capabilities, Capabilities)

public RemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities,
      Capabilities requiredCapabilities) {
    this.executor = executor;

init(desiredCapabilities, requiredCapabilities);

if (executor instanceof NeedsLocalLogs) {
      ((NeedsLocalLogs)executor).setLocalLogs(localLogs);
    }

try {
      startClient(desiredCapabilities, requiredCapabilities);
    } catch (RuntimeException e) {
      try {
        stopClient(desiredCapabilities, requiredCapabilities);
      } catch (Exception ignored) {
        // Ignore the clean-up exception. We'll propagate the original failure.
      }

throw e;
    }

try {
      startSession(desiredCapabilities, requiredCapabilities);
    } catch (RuntimeException e) {
      try {
        quit();
      } catch (Exception ignored) {
        // Ignore the clean-up exception. We'll propagate the original failure.
      }

throw e;
    }
  }

以上的代码完成了如下的操作:

1. 初始化desiredCapabilities对象,这是发送到客户端的JSON 数据,

2. 启动一个session,这里包含一个判断,如果这是一个NEW_SESSION,那么会在上面构建的chromedriver上启动chromedriver然后在发送session命令。后台操作HTTP请求用到的是Apache HttpClient的API.

上面说明下WebDriver的通信是HTTP的协议,因此这里所有的通信都是通过JSON Wired进行沟通的RESTFul格式。也就是说所有的沟通都是一次RESTFul的request和response的过程。

参考如下Selenium的说明: https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#command-summary

JSON Request:

JSON Response:

转载于:https://www.cnblogs.com/alterhu/p/5743344.html

Selenium3笔记-WebDriver源码初探相关推荐

  1. Spring-bean的循环依赖以及解决方式___Spring源码初探--Bean的初始化-循环依赖的解决

    本文主要是分析Spring bean的循环依赖,以及Spring的解决方式. 通过这种解决方式,我们可以应用在我们实际开发项目中. 什么是循环依赖? 怎么检测循环依赖 Spring怎么解决循环依赖 S ...

  2. okhttp3源码初探

    okhttp3源码初探 简介 GET请求 使用 源码阅读 发起请求 eventListener的由来 真正的网络请求 拦截器 RetryAndFollowUpInterceptor拦截器 Bridge ...

  3. sheng的学习笔记-Vector源码分析

    概述 Vector底层也是数组,跟ArrayList很像(先看下ArrayList,再看Vector会很轻松),ArrayList可参考下文,并且由于效率低,已经被淘汰了,大概瞅瞅得了 sheng的学 ...

  4. Dinky0.7.0源码初探

    Dinky0.7.0源码初探 1. Dinky简介 ​ 2022年11月25,Dinky0.7.0发布了: ​ Dinky为 " Data Integrate No Knotty " ...

  5. 使用Mahout搭建推荐系统之入门篇3-Mahout源码初探

    2019独角兽企业重金招聘Python工程师标准>>> 用意: 希望了解Mahout中数据的存储方式, 它如何避免java object带来的冗余开销.学完知识,要进行些实战 去分析 ...

  6. python源码笔记_python源码学习笔记(一)

    (一)python对象的基本实现 众所周之,python是个极其简洁高效的脚本语言,其设计思维之简洁,编写之简单,已成公认.想着深入了解内部机制,探索一下源代码,并记录一些东西.诚然,人总是健忘的,因 ...

  7. yolov1-v5学习笔记及源码解读

    目录 深度学习网络分类 评价指标 原理 yolov1 yolov2 yolov3 yolov4 yolov5 源码解读(v3为例) 深度学习网络分类 深度学习经典检测方法 通常分为 two-stage ...

  8. x265笔记_4_CompressCTU源码分析

    文章目录 Before `compressCTU` `compressCTU` 输入参数 处理流程 重要变量 `m_parame` `rd_level` `amp`和`rect` 重要函数 `comp ...

  9. 呕心沥血苦战6个月,熬夜总结的这份Java0基础进阶架构师视频+笔记+课件+源码资料,快快收藏手慢无

    每天都有初学者询问该如何学习,如何快速学习,因精力有限不能一一回复请见谅,现系统整理一套java初学者最佳的学习方法.路线.大纲及视频资料,并对一些过期的知识点进行剔除!如Struts2,hibern ...

  10. 狂神说SpringCloud学习笔记(附带源码和笔记)

    狂神说Spring Cloud Netflix笔记-01(服务注册与发现) 狂神说Spring Cloud Netflix笔记-02(Eureka集群的搭建 ) 狂神说Spring Cloud Net ...

最新文章

  1. NIO详解(七):进程间通信(MappedByteBuffer)
  2. Find First and Last Position of Element in Sorted Array
  3. mac os 切换网络优先级
  4. SAP 电商云 Spartacus UI 的交货模式 Delivery Mode 设计
  5. 二十二、PHP框架Laravel学习笔记——集合的使用
  6. 山东外贸职业学院王彩霞老师网上考试系统及c语言考试题库》,2015年山东外贸职业学院单招考试内容...
  7. php GD库文字居中,PHP GD ttftext居中对齐
  8. Zune WIFI无线同步教程
  9. Python:计算KDJ指标
  10. mac上传文件到ftp服务器,mac上传文件到ftp服务器
  11. css字体设置为白色,css怎么将字体设置成白色
  12. vue项目添加音乐播放插件
  13. ps 套索工具抠图实例
  14. 流程引擎之compileflow简介
  15. 微信 “空白昵称” 新方法来啦!
  16. Esxi6.7安装TinyCoreLinux
  17. 再读杨绛_RWERWERWE_96921_新浪博客
  18. 东周列国志之春秋——简记
  19. linux质控命令,RNA-seq摸索:2.sra下载数据→fastqc质控→hisat2/bowtie2/STAR/salmon比对→Samtools格式转换→IGV可视化结果...
  20. 瑞云服务云|天正电气服务云系统项目顺利验收

热门文章

  1. 从零实现深度学习框架——逻辑回归简介
  2. 真正决定你成败的,是时间管理!
  3. 阿里、Uber都在用的Flink你了解多少?
  4. 促促促,如何确保系统扛得住 | 《尽在双11》抢鲜预览
  5. 博文视点大讲堂第44期——招聘真相全揭秘 圆满结束
  6. Google广告优化与工具
  7. 读这样的文章才能清楚什么是RIA
  8. 55欧式空间02——标椎正交基、Schmidt 正交化、正交矩阵、欧氏空间的同构、QR分解
  9. Hadoop-RPC底层实现与解析
  10. HMM:隐马尔科夫模型 - 预测和解码