托斯卡难题73589用RBFW解决。(扫描字符串文字(<string>)时失败:语法错误:EOL)

2024-06-16 09:58:25 发布

您现在位置:Python中文网/ 问答频道 /正文

为了帮助te测试社区了解测试工具的差异,我尝试创建一个范围,就像Flur Funk对Tosca所做的那样。 (我曾在项目中x次使用Tosca)

现在我用机器人框架解决了同样的难题。 (稍后我会把它们放到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


Tags: tohttpstestbrowsercomiddatetimevar
1条回答
网友
1楼 · 发布于 2024-06-16 09:58:25

这里有一个解决方案——别忘了在视频中记下我的名字;)

它使用SeleniumLibrary,包括xpath和;css选择器,用于&;IF块和直接变量访问($varvs${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

有一个角落的情况会使它无法工作-把这个留给你;)

相关问题 更多 >