Selenium 手册

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

SeleniumSeleniumSeleniumSelenium深入浅出By沈东良年2月目录Selenium教程............................................................................................................................1Selenium—Web界面测试工具.................................................................................................2需要的软件............................................................................................................................2SeleniumIDE的使用..............................................................................................................2SeleniumJava测试................................................................................................................2Selenium工作原理....................................................................................................................5Java执行Selenium测试.......................................................................................................5Selenium执行内部原理........................................................................................................6我应该使用哪种Selenium工具?...........................................................................................6SeleniumRemoteControl:服务器命令行参数.................................................................7Selenium中文参考手册............................................................................................................8Selenium与JavaScript.............................................................................................................18Selenium与EXT...................................................................................................................18Selenium执行Ext的例子:...........................................................................................18Selenium动态执行JavaScript的例子:............................................................................18SeleniumSeleniumSeleniumSelenium————WebWebWebWeb界面测试工具�Selenium可以使用录制工具录制脚本,测试页面。�Selenium可以生成类html代码,java代码,ruby代码等。�Selenium录制工具根据id属性定位html元素需要的软件1,安装Firefox,SeleniumIDE插件,Firebug插件。2,解压Selenium的selenium-remote-control包,得到一个服务器。3,获取selenium-java-client-driver.jar,用于java语言的Selenium开发。SeleniumSeleniumSeleniumSeleniumIDEIDEIDEIDE的使用1,FireFox--工具--selinumIDE2,点击录制按钮,开始记录一个测试。可以使用浏览器进行操作。最后点击SeleniumIDE的停止录制按钮。可以看到html,Java,Ruby等形式的脚本语言。可以执行。可以根据选择的浏览器,使用选择的浏览器执行脚本中的命令。SeleniumIDE除了记录Html请求和AJAX调用的操作。其他不涉及通讯的操作,也会被录制。其他的自动脚本录制工具,如WebLoad,LoadRunner都是只记录http请求,不能真正记录对页面的操作。3,脚本可以格式化为多种语言。这个是使用.js文件实现的。4,selinum使用xpath和css等选择html元素。SeleniumSeleniumSeleniumSeleniumJavaJavaJavaJava测试1,java项目中,加入selenium-java-client-driver.jar。2,启动selenium-remote-control服务器3,把SeleniumIDE录制的Selenium脚本转换成Java格式,Java代码复制到Java项目中。packagecom.example.tests;importcom.thoughtworks.selenium.*;importjava.util.regex.Pattern;publicclassNewTestextendsSeleneseTestCase{publicvoidsetUp()throwsException{setUp(*chrome);}publicvoidtestNew()throwsException{selenium.open(/);selenium.select(price,label=10-15万);selenium.select(bodywork,label=SUV/越野车);selenium.select(brand,label=B比亚迪);selenium.click(//form[@id='SBL']/div/div[2]/a/img);selenium.click(link=比亚迪F0);}}看一个真实的例子:publicpublicpublicpublicclassclassclassclassScrComplaintControllerTestextendsextendsextendsextendsDemo006ControllerTest{privateprivateprivateprivateIProcessHtmlServiceprocessHtmlService=newnewnewnewProcessHtmlService();/**下面是简单单独的测试***/@TestpublicpublicpublicpublicvoidvoidvoidvoidprepareAddCase(){thisthisthisthis.browser.open();Assert.assertEquals(prepareAddCase出错,新增個案,thisthisthisthis.browser.getTitle());}基类publicpublicpublicpublicclassclassclassclassDemo006ControllerTestextendsextendsextendsextendsSeleniumControllerTest{/***@throws@throws@throws@throwsjava.lang.Exception*/@BeforepublicpublicpublicpublicvoidvoidvoidvoidsetUp()throwsthrowsthrowsthrowsException{browser=newnewnewnewDefaultSelenium(localhost,4444,*iexplore,);browser.start();SeleniumLoginUtil.managerLogin(browser);}/***@throws@throws@throws@throwsjava.lang.Exception*/@AfterpublicpublicpublicpublicvoidvoidvoidvoidtearDown()throwsthrowsthrowsthrowsException{thisthisthisthis.browser.stop();}}publicpublicpublicpublicabstractabstractabstractabstractclassclassclassclassSeleniumControllerTest{protectedprotectedprotectedprotectedSeleniumbrowser;/***@throws@throws@throws@throwsjava.lang.Exception*/@BeforeClasspublicpublicpublicpublicstaticstaticstaticstaticvoidvoidvoidvoidsetUpBeforeClass()throwsthrowsthrowsthrowsException{}/***@throws@throws@throws@throwsjava.lang.Exception*/@AfterClasspublicpublicpublicpublicstaticstaticstaticstaticvoidvoidvoidvoidtearDownAfterClass()throwsthrowsthrowsthrowsException{}}在每一次JUnit测试之前应该执行:Seleniumbrowser=newnewnewnewDefaultSelenium(localhost,4444,*iexplore,);browser.start();结束时执行thisthisthisthis.browser.stop();Selenium类用来执行Selenium操作,控制浏览器执行Selenium指令。DefaultSelenium的构造器的参数是你连接的Selenium服务器的ip地址和端口,第三个参数是用来执行Seleni

1 / 20
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功