Tosca puzzle 73589 solved with RBFW. (failed: SyntaxError: EOL while scanning string literal (<string>)

Viewed 123

In order to help te test community understand the differences in test tools, I try to make a range just like Flur-Funk did with Tosca. (I used Tosca for a x time in projects)

So now I solve the same puzzles but then with Robot Framework. (I will put them online in Youtube later)

So this one (hard) puzzle I get stuck: This is what I got so far:

    *** 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

which results in the log:

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 |

How would you solve this one? How to get past the error?

the solution for the Tosca tool can be found here: https://www.youtube.com/watch?v=BcsuH8Q1x60

1 Answers

Here's a solution - don't forget to credit me in the video ;)

It uses SeleniumLibrary, both xpath & css selectors, FOR & IF blocks, and direct variable access ($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

There is a corner case that will make it not work - leaving this to you ;)

Related