Sac*_*ine 5 python robotframework
这有点像一堵文字墙,但我试图让它尽可能短。
情况:我正在打开一个网站,该网站显示一个任务和一个加载栏。加载栏可以显示 0-100%、完成或停止在 0-100% 的任一数字。想法:我使用“获取文本”来读取加载栏并检查它是“完成”还是“停止”。要忽略百分比,我只想要文本的第一部分(例如仅“停止”)。我用“等待关键字成功”重复关键字,直到文本停止或完成。
编码:
Observe Task
Wait Until Keyword Succeeds 120 min 60 sec Check Progress Status ${task_progress_bar}
Check Progress Status
[Arguments] ${task_progress_bar}
${task_status} = Get Text ${task_progress_bar}
Log to Console \n ${task_status}
@{words} = Split String ${test_string} ${SPACE}
${first_word} = @{words}[1]
Log to Console \n ${first_word}
Log to Console 'this is a test message'
Run Code Online (Sandbox Code Playgroud)
我记录状态以检查它是否有效。确实如此。控制台显示 0%、0%、停止在 0% 等但这是我得到的唯一输出。它既不显示 first_word 变量,也不显示测试消息。它似乎在拆分字符串时中断
我试图解决的问题:
${test_string} Set Variable 'Robot is not working'
Log to Console \n ${test_string}
@{words} = Split String ${test_string} ${SPACE}
${first_word} = @{words}[1]
Log to Console \n ${first_word}
Run Code Online (Sandbox Code Playgroud)
如果读取文本有问题,我使用了一个简单的字符串。控制台上仅显示“机器人未工作”。
#${split} = Fetch From Left ${test_text} ${SPACE}
#Log to Console \n ${split}
Run Code Online (Sandbox Code Playgroud)
使用从左侧获取。同样的错误。我在不同的测试套装中尝试了 Fetch 和 Split。两者都有效,所以语法应该是正确的。
Run Keyword And Ignore Error Wait Until Keyword Succeeds 120 min 120 sec Check Progress Status ${task_progress_bar}
Run Code Online (Sandbox Code Playgroud)
忽略错误并将时间间隔增加到 2 分钟。
无论我做什么,控制台都只显示:
'Robot is not working'
'Robot is not working'
'Robot is not working'
Run Code Online (Sandbox Code Playgroud)
或分别“停在 0%”。我的猜测是,在执行整个“检查进度状态”之前,“等待关键字成功”以某种方式循环。或者字符串拆分打破了关键字,但我不知道为什么会发生这种情况。我真的很感激一些帮助。谢谢你。
编辑:正如这里建议的那样,我正在使用缺少的 xpath。由于我用一个简单的字符串替换了它们(请参阅修复尝试 2)并且它也不起作用,因此我认为这不是问题的一部分。反正:
direct xpath:
//*[@id="app"]/div/main/div/section/div[2]/div[2]/table/tbody/tr/td[2]/div/a/div/div[2]/span
xpath im using:
xpath=//tr[contains(., '${task_name}')]/td[2]/div/a/div/div[2]/span
Code snippet to read the text:
${task_progress_bar} = Set Variable xpath=//tr[contains(., '${task_name}')]/td[2]/div/a/div[2]/span
Run Code Online (Sandbox Code Playgroud)
${task_name} 只是名称,显示在进度条的左侧(例如进程 1)
我认为可能存在一些小问题,这些问题可能会滚雪球般地变成一个不起作用的关键字。我不能 100% 确定我的更改会解决整个问题,但我会从它们开始,看看我能得到什么。
当我执行时:
*** Test Cases ***
Split Example
${test_string} Set Variable 'Robot is not working'
@{words} = Split String ${test_string} ${SPACE}
${first_word} = @{words}[1]
Log to Console \n ${first_word}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
未找到名称为“@{words}[1]”的关键字。
所以我解决了这个问题:
${first_word} = Set Variable @{words}[1]
Run Code Online (Sandbox Code Playgroud)
并再次执行相同的测试用例。现在我收到两个警告:
[警告] 不推荐使用“@{words}[1]”语法访问变量项。请改用“${words}[1]”。
[警告] 不推荐使用忽略“\n”后的空格。有关更多信息,请参阅:https://github.com/robotframework/robotframework/issues/3333
我正在使用 RF 3.2.1,它可能在这里发挥作用。
我再次修复了这两个问题,所以整个测试用例如下所示:
*** Test Cases ***
Split Example
${test_string} Set Variable 'Robot is not working'
@{words} = Split String ${test_string} ${SPACE}
${first_word} = Set Variable ${words}[1]
Log to Console \n${first_word}
Run Code Online (Sandbox Code Playgroud)
现在我is进入控制台,这似乎是所需的输出。
我还在你的例子中注意到:
Check Progress Status
[Arguments] ${task_progress_bar}
${task_status} = Get Text ${task_progress_bar}
Log to Console \n ${task_status}
@{words} = Split String ${test_string} ${SPACE}
${first_word} = @{words}[1]
Log to Console \n ${first_word}
Log to Console 'this is a test message'
Run Code Online (Sandbox Code Playgroud)
从哪里来${test_string}?它没有在关键字中的任何地方初始化,也不是参数。确保变量存在。