Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Wait Until Keyword Succeeds" doesn't execute the whole keyword

This is a bit of a wall of text, but I'm trying to keep it as short as possible.

The situation: I'm opening a website, which displays a task and a loading bar. The loading bar can display either digits for 0-100%, Done or Stopped at 0-100%. The Idea: I use "Get Text" to read the loading bar and check if its either "done" or "stopped". To ignore the percentage, I only want the first part of the Text( only "stopped" for example). I repeat the keyword with "Wait Until Keyword Succeeds" until the text is either stopped or done.

The Code:

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' 

I log the status to check if it works. It does. The console shows 0%, 0%, stopped at 0% etc But this is the only output I get. Neither does it show the first_word variable, nor the test message. It seems to break at split String

What I tried to fix it:

    ${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}

In case there is an issue with the read text, I used a simple string. Only 'Robot is nor working' appears on the console.

    #${split} =    Fetch From Left    ${test_text}    ${SPACE}
    #Log to Console    \n ${split}

Using Fetch From Left. Same Error. I tried both Fetch and Split in a different test suit. Both worked, so the syntax should be correct.

    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    120 min     120 sec    Check Progress Status    ${task_progress_bar}

Ignoring errors and increasing the time interval to 2minutes.

No matter what I do, the console only displays:

'Robot is not working'

'Robot is not working'

'Robot is not working'

or "Stopped at 0%" respectively. My guess is that "Wait Until Keyword Succeeds" somehow loops before the whole "check progress status" is executed. Or the String Split breaks the keyword, but I'm out of ideas why this could happen. I would really appreciate some help. Thank you.

Edit: As suggested here are the missing xpaths I'm using. Since I replaced them with a simple string (see fix attempt 2) and it doesn't work either, I don't think this is part of the problem. Anyway:

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

With ${task_name} just being the name, which is displayed left of the progress bar (e.g. Process 1)

like image 539
Saccarine Avatar asked Oct 15 '22 01:10

Saccarine


2 Answers

I think there might be a few tiny problems that might snowball into a non-working keyword. I'm not 100 % sure my changes will fix the overall problem, but I'd start with them and see where I get.

When I execute:

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

I get one error:

No keyword with name '@{words}[1]' found.

So I fix this:

${first_word} =     Set Variable    @{words}[1]

and execute the same test case again. Now I get two warnings:

[ WARN ] Accessing variable items using '@{words}[1]' syntax is deprecated. Use '${words}[1]' instead.
[ WARN ] Ignoring space after '\n' is deprecated. For more info see: https://github.com/robotframework/robotframework/issues/3333

I'm using RF 3.2.1, which might play a role here.

I fix these two again, so the whole test case looks like this:

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

Now I get is into the console, which seems like a desired output here.

I also noticed in your example:

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' 

Where does ${test_string} come from? It's not initialized anywhere in the keyword, nor it's an argument. Make sure the variable exists.

like image 63
pavelsaman Avatar answered Oct 22 '22 09:10

pavelsaman


Inside the keyword, this syntax:

${first_word} =     @{words}[1] 

is invalid - to do variable assignment you have to have a keyword call, that returns a value. So change it to:

${first_word} =     Get From List    ${words}    1

, or

${first_word} =     Set Variable    ${words[1]}

By the way, lists are 0-based so index 1 will get the 2nd element in it - I hope this is your intent.

like image 22
Todor Minakov Avatar answered Oct 22 '22 10:10

Todor Minakov