1 / 17

Web 系统功能测试工具: Selenium

Web 系统功能测试工具: Selenium. Selenium 是 ThoughtWorks 专门为 Web 应用而开发的功能测试工具。 Selenium 使用 JavaScript 和 Iframes 在浏览器嵌入自动化测试引擎,可以在任何支持 JavaScript 的浏览器中进行工作,模拟用户在浏览器中进行的操作。.

lavina
Download Presentation

Web 系统功能测试工具: Selenium

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web系统功能测试工具:Selenium

  2. Selenium是ThoughtWorks专门为 Web 应用而开发的功能测试工具。Selenium使用JavaScript和Iframes在浏览器嵌入自动化测试引擎,可以在任何支持JavaScript的浏览器中进行工作,模拟用户在浏览器中进行的操作。

  3. 1. Selenium的优势:1)它是开源的2)简单,易于安装,易于工作3)提供Selenium IDE ,一个FireFox plugin,能自动记录用户的操作,生成测试脚本。生成的测试脚本可以基于Selenium RC放入Java,C#,Ruby的单元测试用例中自动运行。selenium ide是selenium的唯一可以在浏览器窗口上记录用户行为的组件4)除了火狐上的事件外不会记录你电脑上的任何其他事件5)Selenium支持多种浏览器,能够运行与多种操作系统,因此更容易帮助测试人员发现应用程序在不同浏览器上的兼容性问题。通过在不同浏览器中运行测试,更容易发现浏览器的不兼容性;6)通过编写模仿用户操作的 Selenium 测试脚本,可以从终端用户的角度来测试应用程序;可以操作 Web 页面上的各种元素,诸如:点击按钮、输入文本框,以及断言 Web 页面上存在某些文本与 Web 元素等。

  4. 7)测试用例调用实际的浏览器(如IE、FireFox)来执行测试。和有些开源方案自行实现Web解释引擎相比,实际的浏览器能模拟更多用户交互和JS语法。 8) SELENIUM录制的脚本比较灵活,因为它生成的是PERL的脚本程序。作为几乎最为强大和最广泛使用语言之一,PERL这种程序给予我最大的灵活性和控制度。

  5. 2. 需要的软件1)Firefox,Selenium IDE 插件,Firebug 插件。2)Selenium RC3)XPather4)JDK5)Eclipse6)SQL server 2000

  6. 3. Selenium 是ThroughtWorks 公司一个强大的开源Web 功能测试工具系列􀂄1)Selenium 可以使用录制工具录制脚本,测试页面。2)Selenium 可以生成类html 代码,java 代码,ruby 代码等。3)Selenium 录制工具根据id 属性定位html 元素4)Selenium IDE 仅支持Selenium 语言。5)Selenium RC 支持很多语言,如:C#,Java,Python,Ruby 等。

  7. 4.使用Selenium IDE插件1) Firefox工具栏,打开Selenium-IDE插件,如下图:

  8. 2)选择插件界面中右上角红色录制按钮(开始录制、停止录制都是此按钮),如下图,这里录制登陆集中管理工具的过程。 2)选择插件界面中右上角红色录制按钮(开始录制、停止录制都是此按钮),如下图,这里录制登陆集中管理工具的过程。

  9. 3)录制完成后,点击回放按钮可以对刚刚录制的脚本进行回放,这里可以调整回放速度。 4)可以将录制的脚本转换成C#, Java,PHP, Ruby,Perl, Groovy, Python等语言,这里选择Java,如下图:

  10. 5. Selenium-RC的使用1)启动Server: 通过命令行的方式用如下的命令来启动你的Selenium Server:java -jar selenium-server.jar 这个命令将启动Selenium服务器,可以带参数启动,如java –jar selenium-server.jar -interactive为以交互模式启动2)打开Eclipse,建立Test Project3)将selenium-java-client-driver.jar导入此project的classpath 4)将Selenium-IDE录制好的html脚本转换成java文件,导入新建的project(可能需要稍作修改,如添加assert判断用例是否测试通过),或直接使用selenium-java-client API编写测试用例。本工具同时支持Junit和TestNg测试框架5)在Java IDE 或命令行执行编写好的测试用例

  11. 6. XPather1)Xpath: 是XML 的查询语言,必须注意要以"//"开头。2)Xpath checker:查看根据你写的xpath 是否可以找到对应的element。注: 一般和firebug 一起用。用firebug来看html源代码,然后估计源代码才能写xpath。3)也可以通过XPath checker来定位element。

  12. 7. 与 SQL 的连接的程序String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=aaa"; String userName = "sa"; String userPwd = "123456"; Connection dbConn = null; try { Class.forName(driverName); dbConn = DriverManager.getConnection(dbURL, userName, userPwd); System.out.println("Connection Successful!"); }catch (Exception e) { e.printStackTrace(); }

  13. 8. 定位弹出窗口1)通过xpath得到href的属性,例如对于一段HTML代码:<a target=“newwindow” href=“relative_URL”>click here</a> :String url = selenium.getAttribute (“a[text()=‘click here’]@href ”); 2)然后使用OpenWindow(URL, ID) 和 selectWindow(ID)就选中了子窗口,然后可以在上面进行操作,比如验证文字存在,输入数据之类的

  14. 9.文本框Text box1)向文本框中填写信息type(java.lang.String locator, java.lang.String value)例如:selenium.type(“username”, “jingya_12”);2)取出某个文本框中已经填写的信息java.lang.StringgetValue(java.lang.String locator)例如:selenium.getValue("//input[@id='username']");3)判断某文本框是否可编辑booleanisEditable(java.lang.String locator)例如:selenium.isEditable("//input[@name='addProfileLastName']");

  15. 10.下拉框 Drop down list1)向下拉框中选值select(java.lang.String selectLocator, java.lang.String optionLocator)例如:selenium.select("//table[@id='gxsz']/tbody/tr[3]/td[2]/select", "index=0");2)取出某个下拉框中已经选择的值java.lang.StringgetSelectedLabel(java.lang.String selectLocator)例如: selenium.getSelectedLabel("//table[@id='gxsz']/tbody/tr[3]/td[2]/select");3)取出某个下拉框中所有的选项java.lang.String getSelectOptions (java.lang.String selectLocator)例如: selenium.getSelectOptions("//div[@id='mysearch_tips']/select")

  16. 11.按钮或链接Button & Link1)单击click(java.lang.String locator)例如: selenium.click("//table[@id='gxsz']/tbody/tr[1]/td[2]/input[@id='s1_1']");

  17. 12.取元素的特定属性值和text的值1)取某个元素的特定属性值java.lang.String getAttribute(java.lang.String attributeLocator)例如: selenium.getAttribute (“//img[@name=‘picName’]@style”)2)取某元素的text 值java.lang.String getText(java.lang.String locator)例如: selenium.getText("//center/div[@id='main']/div[@id='center']/div[1]/strong[2]");

More Related