ITeye博客

Selenium Basics

macsu · 2009-07-13 11:48 · 自动化测试 · Markdown

开始– 选择你自己的Selenium 工具 大部分人开始于Selenium-IDE.这也是我们推荐的。这是一种简单的方式来熟悉Selenium命令. 你可以在几分钟内开发你第一个脚本. Selenium-IDE也很容易安装。 你也可以在Selenium-IDE跑你自己的脚本.这很容易用所以推荐给缺少技术的用户.IDE准许你开发和跑测试用例却不需要你有程序开发背景.Selenium-IDE 提供了一个优秀的选择用于训练自动化测试的初学者.一个熟悉web应用测试的测试人员可以很容易的使用Selenium-IDE进行自动化测试 一些测试任务太复杂以至于Selenium-IDE无法执行.当用到程序逻辑的时候Selenium-RC必须被用到. 例如测试需要遍历每个元素需要通过程序逻辑来做. Selenium-IDE不支持循环和条件. 另外Selenium-Core是另外一种方式.他可以跑测试脚本通过html接口TestRunner.html. 这是一种原始的方法来执行Selenium命令.像IDE一样受到很多限制,不支持遍历. Selenium-Core不能在http和https协议之间切换,Selenium-IDE 和Selenium-RC使用的人数更多,拥有更多的支持。Selenium-Core未来很可能废弃掉。

介绍elenium 命令 Selenium 命令 – Selenese Selenium提供了超出想象的丰富命令用于测试web应用.这个命令集合叫做 selenese.这些命令本质上创建了一门测试语言. 在seleness里面,可以根据htmltag 测试ui元素的存在。例如特定的内容,链接,输入框,筛选框,提交表单,表格数据。还可以测试窗口大小,鼠标位置,弹出窗口,ajax更能,弹出窗口,事件响应等web应用功能。命令手册列出了所有可能的命令。

一个命令就是告诉Selenium去“做什么”. Selenium 命令来源于三个层面: 行为,存取器,和断言 • 行为 是改变应用状态的命令。他们类似于 “点击一个链接” 和 “选择一个选项”. 如果性能失败或者产生错误,测试执行会失败. 很多行为被加上了 “AndWait” 后缀例如 “clickAndWait”。这个后缀告诉Selenium 这个行为会让浏览器请求一次服务端,并且等待一张新页面载入。 • 存取器 examine检查应用状态和存结果到变量中,例如“storeTitle”. 他们也使用与自动生成断言. • 断言 类似于存取器, 但是它验证应用状态是否相同与我们期望的。例如 “make sure the page title is X” and “verify that this checkbox is checked”. 所有Selenium断言 可以被归为三类: “断言”, “验证”, and ” 等待”. 例如, 你可以“assertText”, “verifyText” and “waitForText”. 当断言失败,测试停止.当验证失败,测试会记录下错误,继续执行. This allows a single “assert” to ensure that the application is on the correct page, followed by a bunch of “verify” assertions to test form field values, labels, etc. “waitFor” commands wait for some condition to become true (which can be useful for testing Ajax applications). They will succeed immediately if the condition is already true. However, they will fail and halt the test if the condition does not become true within the current timeout setting (see the setTimeout action below). Script Syntax Selenium commands are simple, they consist of the command and two parameters. For example: verifyText //div//a Login The parameters are not always required. It depends on the command. In some cases both are required, in others one parameter is required, and still in others the command may take no parameters at all. Here are a couple more examples: goBackAndWait verifyTextPresent Welcome to My Home Page type id=phone (555) 666-7066 type id=address1 ${myVariableAddress} The command reference describes the parameter requirements for each command. Parameters vary, however they are typically • a locator for identifying a UI element within a page. • a text pattern for verifying or asserting expected page content • a text pattern or a selenium variable for entering text in an input field or for selecting an option from an option list. Locators, text patterns, selenium variables, and the commands themselves are described in considerable detail in the section on Selenium Commands. Selenium scripts that will be run from Selenium-IDE may be stored in an HTML text file format. This consists of an HTML table with three columns. The first column is used to identify the Selenium command, the second is a target and the final column contains a value. The second and third columns may not require values depending on the chosen Selenium command, but they should be present. Each table row represents a new Selenium command. Here is an example of a test that opens a page, asserts the page title and then verifies some content on the page:

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。