三、 Assertions
允许用户去检查当前状态。两种模式: Assert 和 Verify, 当Assert失败,则退出测试;当Verify失败,测试会继续运行。
assertLocation, assertTitle
assertLocation(relativeLocation)
判断当前是在正确的页面 verifyLocation /mypage
assertLocation /mypage
assertTitle(titlePattern)
检查当前页面的title是否正确 verifyTitle My Page
assertTitle My Page
assertValue
assertValue(inputLocator, valuePattern)
- 检查input的值
- 对于 checkbox或radio,如果已选择,则值为"on",反之为"off" verifyValue nameField John Smith
assertValue document.forms[2].nameField John Smith
assertSelected, assertSelectedOptions
assertSelected(selectLocator, optionSpecifier)
检查select的下拉菜单中选中的选型是否和optionSpecifer(Select选择选项器)的选项相同 verifySelected dropdown2 John Smith
verifySelected dorpdown2 value=js*123
assertSelected document.forms[2].dropDown label=J*Smith
assertSelected document.forms[2].dropDown index=0
assertSelectOptions(selectLocator, optionLabelList)
- 检查下拉菜单中的选项的文本是否和optionLabelList相同
- optionLabelList是以逗号分割的一个字符串 verifySelectOptions dropdown2 John Smith,Dave Bird
assertSelectOptions document.forms[2].dropdown Smith,J,Bird,D
assertText
assertText(elementLocator,textPattern)
- 检查指定元素的文本
- 只对有包含文本的元素生效
- 对于Mozilla类型的浏览器,用textContent取元素的文本,对于IE类型的浏览器,用innerText取元素文本 verifyText statusMessage Successful
assertText //div[@id='foo']//h1 Successful
assertTextPresent, assertAttribute
assertTextPresent(text)
检查在当前给用户显示的页面上是否有出现指定的文本 verifyTextPresent You are now logged in
assertTextPresent You are now logged in
assertAttribute(.{}elementLocator@attributeName.{}, ValuePattern)
检查当前指定元素的属性的值 verifyAttribute txt1@class bigAndBlod
assertAttribute document.images[0]@alt alt-text
verifyAttribute //img[@id='foo']/alt alt-text
assertTextPresent, etc.
assertTextPresent(text)
assertTextNotPresent(text)
assertElementPresent(elementLocator) verifyElementPresent submitButton
assertElementPresent //img[@alt='foo'] assertElementNotPresent(elementLocator)
assertTable
assertTable(cellAddress, valuePattern)
- 检查table里的某个cell中的值
- cellAddress的语法是tableName.row.column, 注意行列序号都是从0开始 verifyTable myTable.1.6 Submitted
assertTable results0.2 13