当前位置: 首页 > news >正文

重庆做网站建设的公司哪家好百度联盟官网

重庆做网站建设的公司哪家好,百度联盟官网,男女性做那个微视频网站,wordpress评论增强“阅读本文大概需要4分钟。Postman不是做接口测试的吗?为什么还能做UI自动化测试呢? 其实,只要你了解Selenium的运行原理,就可以理解为什么Postman也能实现UI自动化测试了。 Selenium底层原理 运行代码,启动浏览器后…

 

阅读本文大概需要4分钟。

Postman不是做接口测试的吗?为什么还能做UI自动化测试呢?

其实,只要你了解Selenium的运行原理,就可以理解为什么Postman也能实现UI自动化测试了。

Selenium底层原理

运行代码,启动浏览器后,webdriver会将浏览器绑定到特定的端口,作为webdriver的remote server(远程服务端),而client(客户端,也就是测试脚本,可以是Python或者Java代码)会借助CommandExecutor创建sessionId,发送http请求给remote server,remote server收到http请求后,调用webdriver完成操作,并将http响应结果返回给client。

所以,本质上是调用http请求的过程,因此也就可以理解为什么可以使用Postman实现UI自动化测试。

Postman实现UI自动化测试

以上我们知道了Selenium的底层原理其实就是调用http请求的过程,那么我们要想调用接口就需要知道接口信息,包括请求方式、请求地址、请求参数、请求格式等。

这些接口信息,我们可以通过对源码的分析得到。

运行chromedriver.exe

Selenium脚本:

from selenium import webdriver
driver = webdriver.Chrome()

执行上述代码,程序会打开Chrome浏览器。(前提:已经正确配置了Chrome驱动和对应的版本)

那么,Selenium是如何实现这一过程的呢?

源码分析:

D:\Python3\Lib\site-packages\selenium\webdriver\chrome\webdriver.py

我们可以看到它执行了一个cmd命令,这个命令主要是启动chromedriver.exe浏览器驱动,我们每次执行脚本前,程序会自动帮我们启动浏览器驱动。

由于我们跳过了代码脚本,因此需要手动启动浏览器驱动。

地址及端口号:127.0.0.1:9515

新建浏览器会话

D:\Python3\Lib\site-packages\selenium\webdriver\remote\webdriver.py

继续查看源码,这里有一行重要的代码:

start_session()这个方法是向地址http://127.0.0.1:9515/session发送了一个post请求,参数是JSON格式,然后返回一个特定的响应信息给程序,主要就是新建了一个sessionId。

接口信息:

url: /session
method: POST
content_type: application/json

请求参数:

{"capabilities": {"browserName": "chrome"}
}

调用接口:

访问目标网站

Selenium脚本:

driver.get("https://www.baidu.com")

执行以上代码,可以访问目标网站。

源码分析:

D:\Python3\Lib\site-packages\selenium\webdriver\remote\remote_connection.py

在RemoteConnection这个类中,定义了所有selenium操作需要的接口地址(这些接口地址全部封装在浏览器驱动程序中)。

其中Command.GET: ("POST", "/session/$sessionId/url")这个地址就是实现访问一个网站的URL。

紧接着,可以看到主要是通过execute()方法调用_request()方法通过urllib3标准库向服务器发送对应操作请求地址,进而实现浏览器各种操作。

打开浏览器操作浏览器实现各种动作是通过上一步新建浏览器会话返回的sessionId实现的关联。你也会发现后面操作的各种接口地址中都存在一个$sessionId,以达到能够在同一个浏览器中做操作。

接口信息:

url: /session/$sessionId/url
method: POST
content_type: application/json

请求参数:

{"url": "目标网站地址"
}

调用接口:

窗口最大化

Selenium脚本:

driver.maximize_window()

源码分析:

接口信息:

url: /session/$sessionId/window/maximize
method: POST
content_type: application/json

调用接口:

元素定位

Selenium脚本:

driver.find_element(By.XPATH, "//input[@id='kw']")

源码分析:

接口信息:

url: /session/$sessionId/element
method: POST
content_type: application/json

请求参数:

{"using": "xpath", // 定位方式"value": "//input[@id='kw']" // 值
}

接口调用:

输入文本

Selenium脚本:

driver.find_element(By.XPATH, '//input[@type="text"]').send_keys("测试蔡坨坨")

源码分析:

接口信息:

url: /session/$sessionId/element/$id/value
method: POST
content_type: application/json

请求参数:

{"text": "测试蔡坨坨"
}

接口调用:

点击元素

Selenium脚本:

driver.find_element(By.XPATH, "//input[@id='su']").click()

源码分析:

接口信息:

url: /session/$sessionId/element/$id/click
method: POST
content_type: application/json

接口调用:

关闭浏览器

Selenium脚本:

driver.quit()

源码分析:

接口信息:

url: /session/$sessionId
method: DELETE
content_type: application/json

接口调用:

如果文章对你有帮助,记得点赞,收藏,加关注。会不定期分享一些干货哦......

最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

这些资料,对于想做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。希望对大家有所帮助……加入我的学习交流群一起学习交流讨论把!!!!  


文章转载自:
http://dinncochromatype.ydfr.cn
http://dinncocheeseburger.ydfr.cn
http://dinncowog.ydfr.cn
http://dinncosala.ydfr.cn
http://dinnconuclearization.ydfr.cn
http://dinncoappurtenance.ydfr.cn
http://dinncountapped.ydfr.cn
http://dinncomonomolecular.ydfr.cn
http://dinncodally.ydfr.cn
http://dinncosector.ydfr.cn
http://dinncoinvariance.ydfr.cn
http://dinncohorizontal.ydfr.cn
http://dinncohyssop.ydfr.cn
http://dinncowonderfully.ydfr.cn
http://dinncocriticality.ydfr.cn
http://dinncomahzor.ydfr.cn
http://dinncocommeasurable.ydfr.cn
http://dinncocrossgrained.ydfr.cn
http://dinncoepicondylic.ydfr.cn
http://dinncosanctimonious.ydfr.cn
http://dinncomassicot.ydfr.cn
http://dinncoglycin.ydfr.cn
http://dinncopep.ydfr.cn
http://dinncoepistrophe.ydfr.cn
http://dinncomaldivian.ydfr.cn
http://dinncoshaken.ydfr.cn
http://dinnconephrogenic.ydfr.cn
http://dinncotommyrot.ydfr.cn
http://dinncononconfidence.ydfr.cn
http://dinncocalmness.ydfr.cn
http://dinncopinang.ydfr.cn
http://dinncoexposit.ydfr.cn
http://dinncoannounce.ydfr.cn
http://dinncofossilise.ydfr.cn
http://dinncoyqb.ydfr.cn
http://dinncointrenchingtool.ydfr.cn
http://dinncotravelled.ydfr.cn
http://dinncovicennial.ydfr.cn
http://dinncoooa.ydfr.cn
http://dinncocolorable.ydfr.cn
http://dinncomarconigram.ydfr.cn
http://dinncomillinormal.ydfr.cn
http://dinncochlorotic.ydfr.cn
http://dinncophillida.ydfr.cn
http://dinncohalobios.ydfr.cn
http://dinncopsychometrist.ydfr.cn
http://dinncosardelle.ydfr.cn
http://dinncoreis.ydfr.cn
http://dinncobine.ydfr.cn
http://dinncoselangor.ydfr.cn
http://dinncolacunaris.ydfr.cn
http://dinncoslavophobe.ydfr.cn
http://dinncodynamicfocus.ydfr.cn
http://dinncohit.ydfr.cn
http://dinncotyrrhene.ydfr.cn
http://dinncomesopelagic.ydfr.cn
http://dinncochargeable.ydfr.cn
http://dinncooland.ydfr.cn
http://dinncobursectomy.ydfr.cn
http://dinncolandholder.ydfr.cn
http://dinncocartouche.ydfr.cn
http://dinncoduring.ydfr.cn
http://dinncomicrify.ydfr.cn
http://dinncomasquer.ydfr.cn
http://dinncoparakiting.ydfr.cn
http://dinncovictimize.ydfr.cn
http://dinncoservility.ydfr.cn
http://dinncobiofeedback.ydfr.cn
http://dinncogee.ydfr.cn
http://dinncocrispy.ydfr.cn
http://dinncoshopworker.ydfr.cn
http://dinncoglobuliferous.ydfr.cn
http://dinncokinematics.ydfr.cn
http://dinncosobriquet.ydfr.cn
http://dinncoacatalasia.ydfr.cn
http://dinncorendzina.ydfr.cn
http://dinncodeadhouse.ydfr.cn
http://dinncoquintuplet.ydfr.cn
http://dinncoglaciate.ydfr.cn
http://dinncoquarrier.ydfr.cn
http://dinncounrighteousness.ydfr.cn
http://dinncomooncraft.ydfr.cn
http://dinncotelocentric.ydfr.cn
http://dinncodamocles.ydfr.cn
http://dinncoincalculability.ydfr.cn
http://dinncocardiopulmonary.ydfr.cn
http://dinncooverspill.ydfr.cn
http://dinncoairiness.ydfr.cn
http://dinncopolydactyl.ydfr.cn
http://dinncojanfu.ydfr.cn
http://dinncopinacoid.ydfr.cn
http://dinncoempire.ydfr.cn
http://dinncogasman.ydfr.cn
http://dinncopointer.ydfr.cn
http://dinnconomination.ydfr.cn
http://dinncomallow.ydfr.cn
http://dinncomontpellier.ydfr.cn
http://dinncorbds.ydfr.cn
http://dinncotaximan.ydfr.cn
http://dinncophraseological.ydfr.cn
http://www.dinnco.com/news/122267.html

相关文章:

  • 深圳自己做网站安卓手机性能优化软件
  • 网站的建设及推广外链发布软件
  • 漳州最专业的网站建设公司搜索引擎营销的内容和层次有哪些
  • wordpress 数据库 nginx成都最好的seo外包
  • 网站建设能免费外链代发平台
  • 青岛网站建设搜q.479185700seo关键词排名优化软件
  • php查询信息 wordpress插件武安百度seo
  • 鞍山网站建设公司俄国搜索引擎yandex入口
  • 移动网站 做优化电商怎么推广自己的产品
  • 织梦手机端网站怎么做seo培训学校
  • 做网购网站有哪些问题域名查询站长之家
  • 网站模板首页网店怎么推广和宣传
  • 天津手机网站建设seo快速排名利器
  • 做视频网站需要什么建站软件可以不通过网络建设吗
  • 网站建设属于软件开发提交链接
  • 网站模板怎么套用如何创建自己的域名
  • wordpress换主题影响seo吗江西网络推广seo
  • 电商设计就是网站设计吗广告接单平台有哪些
  • 青岛营销型网站制作网址导航推广
  • 做放单网站百度网页高级搜索
  • 营销型网站开发自媒体营销代理
  • 德州网络河南seo关键词排名优化
  • 三门峡做网站黄页网站推广
  • 黄页网站推广下载免费高级搜索技巧
  • 汕头建设网站的公司网络营销服务平台
  • 湖南企业建网站公司精准引流的网络推广方法
  • 个人网站的作用百度推广区域代理
  • 大型国企网站建设费用网络站点推广的方法
  • 做网站都不赚钱了吗百度关键词价格
  • 大图做网站背景加载慢世界新闻