python - 托斯卡谜题 73589 用 RBFW 解决。(失败:SyntaxError:扫描字符串文字时 EOL()
问题描述
为了帮助测试社区了解测试工具的差异,我尝试制作一个范围,就像 Flur-Funk 对 Tosca 所做的那样。(我在项目中使用了 Tosca 来缩短时间)
所以现在我解决了同样的难题,但后来使用了 Robot Framework。(稍后我会将它们放在 Youtube 上)
所以这个(困难的)难题我被卡住了:这是我到目前为止得到的:
*** Settings ***
# https://robotframework-browser.org/
Library Browser
Library DateTime
Library Collections
Library String
#Library SeleniumLibrary
#Library SeleniumLibrary
# https://robotframework.org/robotframework/latest/libraries/DateTime.html
# pip install DateTime
*** Variables ***
@{VALUES} | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
*** Test Cases ***
Example Test 73589
Browser.Open Browser https://obstaclecourse.tricentis.com/Obstacles/73589
${rijmetgetallen}= GET TEXT id=array
LOG TO CONSOLE ${rijmetgetallen}
${stripped}= STRIP STRING ${rijmetgetallen} characters=[,\'n]
${converted}= CONVERT TO LIST ${stripped}
FOR ${var} IN ${stripped}
Run Keyword If '${var}' == '1' Continue For Loop
Click id=b1
LOG TO CONSOLE ${var}
# ELSE Click id=tech
END
Click id=button1
Click id=button2
Get Text xpath=//body *= You solved this automation problem.
# used resources:
# https://www.tutorialspoint.com/robot_framework/robot_framework_working_with_variables.htm
这导致日志:
Example Test 73589 3
2
5
1
9
4
8
6
7
| FAIL |
Evaluating expression ''3
2
5
1
9
4
8
6
7' == '1'' failed: SyntaxError: EOL while scanning string literal (<string>, line 1)
------------------------------------------------------------------------------
0012 Test 73589 | FAIL |
你会如何解决这个问题?如何克服错误?
Tosca 工具的解决方案可以在这里找到:https ://www.youtube.com/watch?v=BcsuH8Q1x60
解决方案
这是一个解决方案 - 不要忘记在视频中感谢我;)
它使用 SeleniumLibrary、xpath 和 css 选择器、FOR 和 IF 块以及直接变量访问 ( $var
vs ${var}
)。
Tosca 73589
Open Browser https://obstaclecourse.tricentis.com/Obstacles/73589
Wait Until Element Is Visible xpath://div[@class="num"] # so the page is fully loaded
${total numbers}= Get Element Count xpath://div[@class="num"]
${iterations}= Evaluate ${total numbers} * ${total numbers}
${done}= Set Variable ${False}
FOR ${i} IN RANGE ${iterations}
${n1}= Get Text css:div.bubble > div:nth-child(1)
${n2}= Get Text css:div.bubble > div:nth-child(2)
IF int($n1) > int($n2)
Click Element xpath://button[@id="button1"]
Wait Until Element Does Not Contain css:div.bubble > div:nth-child(1) ${n1} # to be sure the UI has redrawn the numbers
# The list is going to change to ordered only after a swap,
# just advancing won't ever solve it; thus check for the "done" text value only here.
${text solved}= Get Text css:a#sample
${done}= Run Keyword And Return Status Should Not Be Equal As Strings ${text solved} KEEP SORTING
END
IF not $done
Click Element xpath://button[@id="button2"]
ELSE
Exit For Loop
END
END
Run Keyword If not $done Fail The list was not sorted for the maximum iterations!
[Teardown] Close Browser
有一个角落案例会使其无法正常工作 - 把这个留给你;)
推荐阅读
- c# - c#在图表区域外放置注释
- api - Cowin API 可以实时访问吗?
- html - 如何在html和css中获得相同高度的所有列
- jersey - 应用程序/Json 在 MultipartEntityBuilder 中转换为文本/纯文本
- python - 赋值前引用的局部变量“pts”
- flutter - 字符串列表在 POST REST api Dart/Flutter 中转换为单个字符串
- python-3.x - Django urls.py 设置
- python - 如何在 django admin 中更改标题/标签菜单
- scala - 在 Scala 中为我们的类创建隐式类是个好主意吗
- python - Pandas drop row santax 问题