【问题标题】:Radio Button testing in robotframework-selenium2 pythonrobotsframework-selenium2 python中的单选按钮测试
【发布时间】:2013-12-23 13:56:35
【问题描述】:
*** Variables ***

${URL}          http://myurl


*** Test Cases ***      username          password
#Here I'm getting problem How should i write test cases for radio button    

*** Keywords ***

Go To First Chapter
    Go To  ${URL}

Find Radio Buttons
    Select Radio Button  ID  True

我不知道正确的关键字或方法(因为我是这个机器人框架的初学者)

【问题讨论】:

    标签: python selenium selenium-webdriver robotframework


    【解决方案1】:
    *** Test Cases ***
    Answer False To All Questions On First Chapter
        [Setup]  Go To First Chapter
        Select Radio Button    SProgIntro_QSProgIntro_1    False
        Select Radio Button    SProgIntro_QSProgIntro_1    False
        Select Radio Button    SProgIntro_QSProgIntro_1    False
        Element Should Be Visible    SProgIntro_QSProgIntro_1_expl
        Element Should Be Visible    SProgIntro_QSProgIntro_2_expl
        Element Should Be Visible    SProgIntro_QSProgIntro_3_expl
    

    将在所有三个问题上选择 false,并检查指示错误答案的元素是否可见。几乎总是你的测试应该有这样的结构

    1. 设置
    2. 做事
    3. 检查资料
    4. 拆解

    http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html 有关于 Selenium2Library 不同关键字的文档,https://code.google.com/p/robotframework/wiki/HowToWriteGoodTestCases 将教你如何在 RF 中编写好的测试用例。

    【讨论】:

    • 这些图像位于 SProgIntro_QSProgIntro_X_expl 元素中,因此检查该父项是否可见将执行相同的操作。要验证该元素不可见,请使用 Element Should Not Be Visible。
    • 那么您面临的问题是什么?单击 True,检查所需元素是否可见。单击 False,检查所需元素是否可见。您需要的所有关键字都是选择单选按钮和元素应该是可见的。
    • 绿色和红色图片在 RF 可以检查的方面是否有所不同?也许您可以通过“获取元素属性”获取 src 并检查它是指向红色图标还是绿色图标。基本上它看起来像这样: ${src}= 获取元素属性 ${your_img}@src 不应该包含 ${src} 绿色 应该包含 ${src} 红色
    • 页面应该包含图片 css=#SProgIntro_QSProgIntro_1_corr img[src="/images/pics/pic_xMark.png"] 并且页面应该包含图片 css=#SProgIntro_QSProgIntro_1_corr img[src="/images/pics/ pic_checkMark.png"]
    • 再问一个问题,因为这是完全不同的事情。
    【解决方案2】:

    我不确定我是否正确理解了您的问题。您究竟想如何测试单选按钮?您是否只想断言它们确实存在并单击它们?

    也许您可以考虑使用 Helium - Python Selenium WebDriver 包装器,它使事情变得更容易:

    from helium.api import *
    start_chrome("http://pythoneval.zyante.com/ch01-introduction")
    # scroll down to view the radio buttons
    scroll_down(10)
    # assert radio button True exists for question "1"
    assert RadioButton("True", to_right_of=Text("1")).exists()
    # assert radio button False exists for question "1"
    assert RadioButton("False", to_right_of=Text("1")).exists()
    # select the "True" answer for question number "1"
    click(RadioButton("True", to_right_of=Text("1")))
    # this displays the alert sometimes, if alert exists dismiss it by pressing ENTER
    if Alert().exists():
        press(ENTER)
    

    同样,您可以参考单选按钮了解其他问题 - 无需使用 ID,例如 SProgIntro_QSProgIntro_1。您还可以使用 Python 的 unittest 库来编写完整的测试用例类并做出更复杂的断言。

    更多信息heliumhq.com

    披露:我是 Helium 开发人员之一。

    【讨论】:

      猜你喜欢
      • 2017-09-05
      • 2021-01-25
      • 2021-10-13
      • 2014-11-16
      • 1970-01-01
      • 2013-05-11
      • 1970-01-01
      • 2013-12-03
      • 1970-01-01
      相关资源
      最近更新 更多