美文网首页测试员的那点事软件测试软件测试
浅谈关于selenium和webdriver原理的二三事

浅谈关于selenium和webdriver原理的二三事

作者: 六月雨June | 来源:发表于2019-01-17 18:35 被阅读49次

    相信大多数从事自动化测试童鞋都听过selenium和webdriver,但面试时候问起关于它们的原理和机制你们又是否可以说出一二来?

    笔者曾经就掉进过坑里,于是抓紧又重新认识一遍selenium和webdriver。

    什么是selenium?

    selenium主要用于web应用程序的自动化测试,这个大家都知道。但它同时其实还支持所有基于web的管理任务自动化。selenium不是由单独的工具构成,其实是由一些插件、类库共同组成,每个部分又各有特点和应用场景。

    selenium 1.0 = selenium IDE + selenium Grid + selenium RC

    selenium IDE:实现简单的浏览器操作的录制和回放。

    selenium Grid:实现多台机器上和异构环境中运行测试用例。

    selenium RC:可作为代理服务器去访问应用。

    selenium 2.0 = selenium 1.0 + Webdriver(selenium和webdriver两个独立项目的合并堪称完美)

    Webdriver:通过原生浏览器支持或浏览器扩展来直接控制浏览器。

    Ubuntu环境搭建selenium

    笔者最近在用腾讯云服务器搭建测试环境,采用了Ubuntu。由于Ubuntu自身就自带python,所以还算很方便的。在Ubuntu的python3下安装setuptools和pip,分别采用下面的命令:

    之后还要用pip来安装selenium,命令如下:

    webdriver的定义与规范

    W3C对webdriver做出了定义与规范:

    WebDriver is a remote control interface that enables introspection and control of user agents. It provides a platform- and language-neutral wire protocol as a way for out-of-process programs to remotely instruct the behavior of web browsers.

    Provided is a set of interfaces to discover and manipulate DOM elements in web documents and to control the behavior of a user agent. It is primarily intended to allow web authors to write tests that automate a user agent from a separate controlling process, but may also be used in such a way as to allow in-browser scripts to control a — possibly separate — browser.

    webdriver是一个远程控制界面,支持反省和用户代理的控制权。该webdriver API 通过通信协议和一组接口发现页面上DOM元素中定义的操作。

    测试大神虫师举了个例子特别好:webdriver可以理解成对操作浏览器和页面元素的一套插板和插头的“国标”,不同编程语言都可以按照这套标准来实现自己语言的webdriver库。

    本期先到这里,待续。


    读更多的好书,拍更美的照片,写更酷的代码,遇见更有趣的人,愿望是实现从IT菜鸟到全栈工程师的蜕变。

    相关文章

      网友评论

        本文标题:浅谈关于selenium和webdriver原理的二三事

        本文链接:https://www.haomeiwen.com/subject/olwidqtx.html