机器人框架:有没有更好的方法来测试菜单中的项目?

时间:2017-07-09 23:46:59

标签: automation robotframework

我正在编写一个测试来验证网页菜单是否包含所有必需的项目,因此我创建了一个名为“验证菜单”的关键字,其中包含以下几个项目:

Verify Menu
  Wait Until Element Is Visible     ${menu}
  Page Should Contain Element       ${home menu item}
  Element Text Should Be            ${home menu item}  Home
  Page Should Contain Element       ${products menu item}
  Element Text Should Be            ${products menu item}  Products
  Page Should Contain Element       ${brands menu item}
  Element Text Should Be            ${brands menu item}  Brands
  Page Should Contain Element       ${find us menu item}
  Element Text Should Be            ${find us menu item}  Find us
  Page Should Contain Element       ${our history menu item}
  Element Text Should Be            ${our history menu item}  Our History
  Page Should Contain Element       ${contact us menu item}
  Element Text Should Be            ${contact us menu item}  Contact Us

我知道这是一个关键字实现,而不是测试本身的一部分,但是,它对我来说看起来有些混乱。

有更好的方法吗?

1 个答案:

答案 0 :(得分:1)

在我看来,Wait Until Element Is Visible可以确定页面已满载。然后,Page Should Contain ElementElement Text Should Be的后续组合将用于验证元素。

我个人认为Page Should Contain Element也包含在Element Text Should Be中。它将失败并提供类似的消息。

也就是说,如果你想保留二人组,但不再使用额外的代码行,那么请选择自定义关键字:

Verify Menu
  Wait Until Element Is Visible     ${menu}
  Validate Element            ${home menu item}  Home
  Validate Element            ${products menu item}  Products
  Validate Element            ${brands menu item}  Brands
  Validate Element            ${find us menu item}  Find us
  Validate Element            ${our history menu item}  Our History
  Validate Element            ${contact us menu item}  Contact Us

*** Keywords ***
Validate Element
    [Arguments]    ${identifier}    ${value}
    Page Should Contain Element       ${identifier}
    Element Text Should Be            ${identifier}    ${value}