selenium Remote Server 实现原理
selenium作为一个出色的web automation框架,被越来越多的企业采用究其原因,框架设计的比较remarkable,
作为一个开源的框架,能够开辟出一套协议,以至于针对app测试的appium采取相同的strategy。使用的是webdriver protocol的扩展版。
为什么说这个框架设计的比较好?究竟好在哪里?
先从表面上看:
- selenium automation framework 支持多语言,java、python、c#、JavaScript、Perl、ruby ...... 测试工具中,能支持这么多语言还不牛逼么 ?QTP/UFT才只支持vbs
- 跨平台支持windows/linux/Mac OS
- 支持grid
- 拥有page object model和page factory
以上,均是不可多得的设计,那么问题又来了,为什么selenium支持那么多语言,怎么实现的?
我想,我给出的答案是协议,selenium remote server/webdriver/appium等完全遵循webdriver json protocol
通过json协议实现跨语言跨平台。如果想了解更多webdriver的Json协议,请参考http://www.w3.org/TR/webdriver/
如果你也要使用restful 自己测试一下下载使用restclient-ui-3.5-jar-with-dependencies.jar
让我们来验证这一点,首先你需要一个restful client 和一个chromew ebdriver,selenium-server-standalone-2.48.0.jar
在cmd起remote server
java -Dwebdriver.chrome.driver="chromedriver.exe" -jar selenium-server-standalone-2.48.0.jar

启动成功,接下来打开浏览器:打开http://localhost:4444/wd/hub/static/resource/hub.html
1.创建session
2.打开百度
3.创建截图

那么这个过程是在怎么实现呢?
看webdriver 的protocol
第一步创建session:Post http://127.0.0.1:4444/wd/hub/session
如果不想使用默认的,可以通过post desiredCapabilities
这样设置body
{ "desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"platform": "ANY",
"version": "55"
}
}
可使用上面的办法,拿到session ID
第二步:打开百度
发送Post http://localhost:4444/wd/hub/session/85a32b0f-e617-449a-bcea-8c84ffa2c5f4/url
Body:
{
"url":"http://www.baidu.com"
}

第三步:findElement By id
发送Post http://localhost:4444/wd/hub/session/85a32b0f-e617-449a-bcea-8c84ffa2c5f4/element
{
"using": "id",
"value": "kw"
}

也可以使用xpath
{
"using": "xpath",
"value": "//input[@id='kw']"
}
第三步:输入selenium 从上一步获取element ID为1
发送 Post http://localhost:4444/wd/hub/session/935821aa-6074-4fc9-bd26-eedf483d6c9d/element/1/value
Body
{
"value": [
"selenium"
]
}

总结:
selenium remote sever 其实就是通过webdriver Json与浏览器交互,这也就介绍了为什么selenium能够实现支持各种语言,
不管是java python 等,都是通过selenium API翻译成Json 与浏览器进行交互。掌握了webdriver protocol 可以通过自己直接写request来
实现与浏览器交互

selenium Remote Server 实现原理的更多相关文章
- org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or br
WARN <init>, HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF R ...
- selenium及webdriver的原理
主要内容转自:http://blog.csdn.net/ant_ren/article/details/7968582和http://blog.csdn.net/ant_ren/article/det ...
- org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launch IE
1.在启动ie浏览器前先加入属性设置一项: DesiredCapabilities ie = DesiredCapabilities.internetExplorer(); ie.setCapabil ...
- Selenium2学习-037-WebUI自动化实战实例-IE浏览器显示比例问题:org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 94%. It should be set to 100%
好久没有写博文了,今天在给部门新人演示 Selenium WebDriver 启动其支持的各种浏览器时,启动 IE 时总是无法打开对应的百度网址,页面如下所示:
- WebService:The remote server returned an error: (400) Bad Request
开发工具:VS2010.开发组件:WebService.运行环境:Windows 今天一个同事在进行计费接口联调试时,发现了一个非常奇怪的问题:接口在家里环境测试,一切正常,但是部署到现网环境之后,连 ...
- [解决问题]selenium.remote.UnreachableBrowserException 异常分析并解决问题
I have a set of automations that work fantastically in Firefox and Chrome, and I'd like to launch an ...
- CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.
今天,在用icinga服务器端测试客户端脚本时,报如下错误: [root@mysql-server1 etc]# /usr/local/icinga/libexec/check_nrpe -H 192 ...
- appium运行报错.<init>(Lorg/openqa/selenium/remote/ErrorCodes;Z)V
最近这几天就在学习appium,搭建环境就耗费了很多时间,不得不承认自己够笨的了,然后我把环境搭建好,写完脚本的时候,就报这个错了,当时是从某个群里直接下载的demo,不得不吐槽说,够坑的,是能跑通, ...
- System.Net.WebException : The remote server returned an error: (415) UNSUPPORTED MEDIA TYPE
I am having problems with a bit of code that accesses a restful web service. Running this code, it e ...
随机推荐
- Django session cookie 上传文件、详解
session 在这里先说session 配置URL from django.conf.urls import patterns, include, url from django.contrib i ...
- 一次基于etcd的分布式锁自动延时失败问题的排查
今天在测试基于etcd的分布式锁过程中,在测试获取锁后,释放之前超出TTL时长的情况下自动延长TTL这部分功能,在延长指定key的TTL时总是返回404错误信息,在对目标KEY更新TTL时目标KEY已 ...
- https简介/原理/部署【转】
转自: http://han.guokai.blog.163.com/blog/static/136718271201211631456811/ http://www.barretlee.com/bl ...
- my computer
把08年买的电脑换了,自己买的配件装的,狂拽酷炫叼炸天. 配置清单: CPU :英特尔至强E3-1230 V2 主板 :华硕P8Z77-V LX LX2 机箱 :撒哈拉海盗贼王Z6游戏机箱(白色限量版 ...
- phpexcel 字符串转码
问题状况:在导入excel的时候会出现 PHPExcel_RichText Object ( [_richTextElements:PHPExcel_RichText:] => PHPExcel ...
- UITextField set placeholderColor and UITextField set clearButton Image
self.usernameTextField.tintColor = [UIColor whiteColor]; [self.usernameTextField setValue:UIColorFro ...
- mysql myisam简单分表设计
一般来说,当我们的数据库的数据超过了100w记录的时候就应该考虑分表或者分区了,这次我来详细说说分表的一些方法.目前我所知道的方法都是MYISAM的,INNODB如何做分表并且保留事务和外键,我还不是 ...
- sublime 安装插件GitGutter报错,git binary cannot be found等等
今天给sublime text安装插件GitGutter的时候,居然报错了,网上查找了下解决方法,在此记录下.因为本博主的电脑是windows的,所以这里只能提供windows的方法啦. 解决方法很简 ...
- [c#基础]关于const和readonly常见的笔试题剖析
引言 有那么几天没更新博客了,发现到了不得不写的地步,总是有那么个声音在强迫自己,虽然工作很累,但是有些东西不写出来,不能原谅自己.今天为什么总结这两个关键字的区别,总觉得这两个关键字的用法用的太习惯 ...
- EntityFramework 优化建议
Entity Framework目前最新版本是6.1.3,当然Entity Framework 7 目前还是预览版,并不能投入正式生产环境,估计正式版16年第一季度会出来,了解过EF7的部分新特性后, ...