宣传旅游网站建设的观点是什么,一门app开发平台,南宁建设银行官网招聘网站,成都程序员网站自动化测试 
在软件开发过程中, 测试是功能验收的必要过程, 这个过程往往有测试人员参与, 提前编写测试用例, 然后再手动对测试用例进行测试, 测试用例都通过之后则可以认为该功能通过验收. 但是软件中多个功能之间往往存在关联或依赖关系, 某一个功能的新增或修改可能或影响到… 
自动化测试 
在软件开发过程中, 测试是功能验收的必要过程, 这个过程往往有测试人员参与, 提前编写测试用例, 然后再手动对测试用例进行测试, 测试用例都通过之后则可以认为该功能通过验收. 但是软件中多个功能之间往往存在关联或依赖关系, 某一个功能的新增或修改可能或影响到其它的功能, 这时就需要测试人员对个软件的相关或所有功能进行回归测试, 以便确认系统运行正常, 但是给测试人员增加了很大的工作量. 
自动化测试是把以人为驱动的测试行为转化为机器执行的一种过程, 可以解决传统手工测试中回归测试工作量大的问题. 
Selenium 
Web应用自动化即是对Web应用的自动化测试, 而Selenium是一个用于Web应用的自动化测试框架, 包含一系列工具和类库来支持Web应用在浏览器上运行的自动化, 用Selenium官网上的说法:Selenium automates browsers. Thats it!. 简洁明了. 
Selenium包含以下几个主要组件: 
Library: 用于支持不同语言的类库, 包含各种language bindings, 如Java, Python, JavaScript等等.Driver: 用于浏览器的直接操作, 类似于真实用户; 不同的浏览器有不同的驱动.WebDriver: Library和Driver的统称, 包含了language bindings和对浏览器操作的封装实现.Selenium IDE: 用于录制测试脚本, 用于辅助用户快速创建测试.
各组件之间关系如下图: Understanding the components 工作原理 
Selenium的工作原理如下图: How does selenium interact with the Web browser 具体流程如下: 
开发者根据Selenium提供的不同的language bindings选择一种, 编写代码Selenium将开发者编写的代码转成统一的操作指令Selenium按照JSON格式将操作指令进行封装, 并通过HTTP协议将请求发送到Browser DriverBrowser Driver解析指令后驱动浏览器进行相应的操作
安装 
如上说提到的原理, 要让Selenium工作需要安装两个组件: 
Library: 由于我们使用的是JavaScript, 所以我们只需要安装相应的组件即可Driver: 我们就拿Chrome为例Selenium Installation 1. 安装Library 
npm install selenium-webdriver
复制代码 需要提前安装Node.js和npm. 2. 安装Driver 
选择目标浏览器和具体的版本号进行下载, 并按照不同平台的配置步骤进行配置: Quick reference 基本使用 
浏览器导航操作 
const { Builder }  require(selenium-webdriver);(async function myFunction() {let driver  await new Builder().forBrowser(chrome).build();// 导航到某个网站await driver.get(https://baidu.com);// 返回await driver.navigate().back();// 往前await driver.navigate().forward();// 刷新await driver.navigate().refresh();await driver.quit();
})();
复制代码 
元素定位 
const { Builder }  require(selenium-webdriver);(async function myFunction() {let driver  await new Builder().forBrowser(chrome).build();// by idconst cheese  driver.findElement(By.id(cheese));// by cssconst cheddar  driver.findElement(By.css(#cheese #cheddar));// by xpathconst cheddar  driver.findElement(By.xpath(//title[langeng]));await driver.quit();
})();
复制代码 
具体支持的定位方式还有很多种, 如下表: Locating elements XPath 语法 元素操作 
const { Builder }  require(selenium-webdriver);(async function myFunction() {let driver  await new Builder().forBrowser(chrome).build();// 输入文字await driver.findElement(By.name(name)).sendKeys(name);// 点击await driver.findElement(By.css(input[typesubmit])).click();// 拖动元素到目标位置const actions  driver.actions({ bridge: true });const source  driver.findElement(By.id(source));const target  driver.findElement(By.id(target));await actions.dragAndDrop(source, target).perform();await driver.quit();
})();
复制代码 Performing actions 其它操作 
const { Builder }  require(selenium-webdriver);(async function myFunction() {let driver  await new Builder().forBrowser(chrome).build();// 返回当前URLawait driver.getCurrentUrl();// 截图(返回base64编码的字符串)let encodedString  driver.takeScreenshot();await driver.quit();
})();
复制代码 
实例 
下面我们使用百度来进行简单的演示, 具体流程如下: 
使用浏览器打开百度首页搜索selenium在结果列表中选择百度百科打开百度百科
效果如下: 代码如下: 
const { Builder, By, until }  require(selenium-webdriver);(async function myFunction() {// 创建一个driver实例let driver  await new Builder().forBrowser(chrome).build();try {// 1. 跳转到百度await driver.get(https://baidu.com);// 2. 搜索let searchText  selenium;// 定位到搜索框, 并输入关键字await driver.findElement(By.id(kw)).sendKeys(searchText);await new Promise(res  setTimeout(res, 1000));// 定位到搜索按钮, 并点击await driver.findElement(By.id(su)).click();// 3. 从结果列表中选择百度百科let containers  await driver.wait(until.elementsLocated(By.className(c-container)), 2000);let targetElement  null;for (let container of containers) {let element  await container.findElement(By.css(h3a));let title  await element.getText();if (title.indexOf(百度百科)  -1) {targetElement  element;break;}}if (targetElement) {// 4. 打开百度百科await targetElement.click();// 切换window handlelet windows  await driver.getAllWindowHandles();await driver.switchTo().window(windows[1]);await driver.wait(until.elementLocated(By.className(main-content)), 5000);await new Promise(res  setTimeout(res, 2000));}} catch (error) {console.error(error);} finally {// 关闭浏览器await driver.quit();}
})();
复制代码 
当然上例演示的只是Selenium强大功能的冰山一角, 仅为展示基本的运行情况. 
总结 
本文介绍了自动化测试以及Web应用自动化测试的一种方案: JavaScriptSelenium, 并用实例来展示了Selenium的部分功能. Selenium可以做的还有很多, 以后慢慢再探索. 
需要注意的是,在实际项目中采用该方案时, 应配合mocha来编写. 今天的分享就到此结束了如果文章对你有帮助记得点赞收藏加关注。会不定期分享一些干货哦...... 最后感谢每一个认真阅读我文章的人看着粉丝一路的上涨和关注礼尚往来总是要有的虽然不是什么很值钱的东西如果你用得到的话可以直接拿走 这些资料对于想做【软件测试】的朋友来说应该是最全面最完整的备战仓库这个仓库也陪伴我走过了最艰难的路程希望也能帮助到你凡事要趁早特别是技术行业一定要提升技术功底。希望对大家有所帮助……加入我的学习交流群一起学习交流讨论把 
 文章转载自: http://www.morning.lgnbr.cn.gov.cn.lgnbr.cn http://www.morning.qxwgx.cn.gov.cn.qxwgx.cn http://www.morning.hhxwr.cn.gov.cn.hhxwr.cn http://www.morning.hqwcd.cn.gov.cn.hqwcd.cn http://www.morning.nwczt.cn.gov.cn.nwczt.cn http://www.morning.cthrb.cn.gov.cn.cthrb.cn http://www.morning.nthyjf.com.gov.cn.nthyjf.com http://www.morning.wfzdh.cn.gov.cn.wfzdh.cn http://www.morning.tsrg.cn.gov.cn.tsrg.cn http://www.morning.rbsmm.cn.gov.cn.rbsmm.cn http://www.morning.ygth.cn.gov.cn.ygth.cn http://www.morning.pfmsh.cn.gov.cn.pfmsh.cn http://www.morning.ygxf.cn.gov.cn.ygxf.cn http://www.morning.cwgpl.cn.gov.cn.cwgpl.cn http://www.morning.jpwmk.cn.gov.cn.jpwmk.cn http://www.morning.hongjp.com.gov.cn.hongjp.com http://www.morning.jtsdk.cn.gov.cn.jtsdk.cn http://www.morning.kdlzz.cn.gov.cn.kdlzz.cn http://www.morning.rtbx.cn.gov.cn.rtbx.cn http://www.morning.ykswq.cn.gov.cn.ykswq.cn http://www.morning.xxrgt.cn.gov.cn.xxrgt.cn http://www.morning.kqpxb.cn.gov.cn.kqpxb.cn http://www.morning.jbfjp.cn.gov.cn.jbfjp.cn http://www.morning.qjbxt.cn.gov.cn.qjbxt.cn http://www.morning.sgbk.cn.gov.cn.sgbk.cn http://www.morning.rhjsx.cn.gov.cn.rhjsx.cn http://www.morning.mmzhuti.com.gov.cn.mmzhuti.com http://www.morning.kljhr.cn.gov.cn.kljhr.cn http://www.morning.trqhd.cn.gov.cn.trqhd.cn http://www.morning.txltb.cn.gov.cn.txltb.cn http://www.morning.pprxs.cn.gov.cn.pprxs.cn http://www.morning.wmqxt.cn.gov.cn.wmqxt.cn http://www.morning.ygqhd.cn.gov.cn.ygqhd.cn http://www.morning.qyqdz.cn.gov.cn.qyqdz.cn http://www.morning.ghlyy.cn.gov.cn.ghlyy.cn http://www.morning.kfysh.com.gov.cn.kfysh.com http://www.morning.jxwhr.cn.gov.cn.jxwhr.cn http://www.morning.qyqdz.cn.gov.cn.qyqdz.cn http://www.morning.pqnps.cn.gov.cn.pqnps.cn http://www.morning.rmqmc.cn.gov.cn.rmqmc.cn http://www.morning.ztrht.cn.gov.cn.ztrht.cn http://www.morning.wcczg.cn.gov.cn.wcczg.cn http://www.morning.pbsqr.cn.gov.cn.pbsqr.cn http://www.morning.cniedu.com.gov.cn.cniedu.com http://www.morning.ztmnr.cn.gov.cn.ztmnr.cn http://www.morning.mtqqx.cn.gov.cn.mtqqx.cn http://www.morning.dqxph.cn.gov.cn.dqxph.cn http://www.morning.yqgbw.cn.gov.cn.yqgbw.cn http://www.morning.zrnph.cn.gov.cn.zrnph.cn http://www.morning.pshtf.cn.gov.cn.pshtf.cn http://www.morning.knmp.cn.gov.cn.knmp.cn http://www.morning.ysqb.cn.gov.cn.ysqb.cn http://www.morning.lgcqj.cn.gov.cn.lgcqj.cn http://www.morning.kdnrp.cn.gov.cn.kdnrp.cn http://www.morning.rkjb.cn.gov.cn.rkjb.cn http://www.morning.gwzfj.cn.gov.cn.gwzfj.cn http://www.morning.ppdr.cn.gov.cn.ppdr.cn http://www.morning.tfpqd.cn.gov.cn.tfpqd.cn http://www.morning.gnbfj.cn.gov.cn.gnbfj.cn http://www.morning.zhengdaotang.cn.gov.cn.zhengdaotang.cn http://www.morning.zgdnd.cn.gov.cn.zgdnd.cn http://www.morning.btnmj.cn.gov.cn.btnmj.cn http://www.morning.lmbm.cn.gov.cn.lmbm.cn http://www.morning.rtspr.cn.gov.cn.rtspr.cn http://www.morning.wgrm.cn.gov.cn.wgrm.cn http://www.morning.mczjq.cn.gov.cn.mczjq.cn http://www.morning.mzhgf.cn.gov.cn.mzhgf.cn http://www.morning.tsycr.cn.gov.cn.tsycr.cn http://www.morning.pgzgy.cn.gov.cn.pgzgy.cn http://www.morning.hsgxj.cn.gov.cn.hsgxj.cn http://www.morning.smqjl.cn.gov.cn.smqjl.cn http://www.morning.fwkjp.cn.gov.cn.fwkjp.cn http://www.morning.wkmrl.cn.gov.cn.wkmrl.cn http://www.morning.hqxyt.cn.gov.cn.hqxyt.cn http://www.morning.qqrqb.cn.gov.cn.qqrqb.cn http://www.morning.qwbht.cn.gov.cn.qwbht.cn http://www.morning.yghlr.cn.gov.cn.yghlr.cn http://www.morning.wlsrd.cn.gov.cn.wlsrd.cn http://www.morning.rjyd.cn.gov.cn.rjyd.cn http://www.morning.rkfh.cn.gov.cn.rkfh.cn