*** 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
我不知道正确的关键字或执行此操作的方法(因为我是这个机器人框架的初学者)
*** 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,并检查指示错误答案的元素是否可见。几乎总是你的测试应该有这样的结构
- 设置
- 做事
- 检查东西
- 拆卸
http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html 有关于Selenium2Library不同关键字的文档,https://code.google.com/p/robotframework/wiki/HowToWriteGoodTestCases 将教你一些关于如何在RF中编写好的测试用例。
我不确定我是否正确理解了你的问题。您究竟想如何测试单选按钮?您是否只想断言它们确实存在并单击它们?
也许你可以考虑使用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开发人员之一。