0

I'm new to Robotframework and I've been trying to export the result of my test to excel, but I couldn't get the correct loop for writing the data to excel. the logic works that every time the element is present in the page, it will be log to the console. But at the same time, I want it to be written in excel.

With the current code, it's only failing, it couldn't recognize ${my_data}

I just put ..... to represent the codes that are not mentioned.

*** Test Cases ***
Check data of the web
    Open browser    ${url}    chrome
    : FOR    ${url}    IN    @{url_list}
    \    Go To    ${url}
    \    ${searched_script} =    Get Source
    \    Run Keyword And Continue On Failure    Should Contain    ${searched_script}    ${sample}
    \    Log to Console    ${url}
    \    @{site_data} =    Get WebElements 
    \    Loop data    @{site_data}
    \   Push all result to excel
    Close Browser

*** Keywords ***
Loop data
    [Arguments]    @{site_data}
    : FOR    ${site_data}    IN    @{site_data}
    \    Log    ${site_data}
    \    ${my_data}=    Get Element Attribute    ${site_data}    my_data_sample
    \    Continue For Loop If    $my_data is None
    \    Run Keyword And Continue on Failure    Should Contain    ${my_data}    hello_world
    \    Log To Console    ${my_data}  

Push all result to excel
    Create excel document doc_id=docname
    Write excel rows    1   0   @{my_data}  sheet    #my_data here is not passing the data from the loop
    Save Excel Document     test.xlsx

Justine
  • 105
  • 1
  • 17
  • 1
    Would be nice have:the actual error output, and what `${my_data}` should contain. – asprtrmp Sep 30 '19 at 10:44
  • Please create a [mcve]. – Bryan Oakley Sep 30 '19 at 13:02
  • I'm having this error: 20190930 15:44:49.668 : FAIL : Variable '${my_data}' not found. ${my_data} -- it should have all the captured elements in the loop. I updated my code. Please let me know if anything else needed. For example, the hello_world could have values Apple, Orange, Banana, therefore, the values that the console will log will be like this: hello_world:apple, and since it's a look, the next row can have hello_world:banana and so on. I want exact this to be log also in excel. Apology for my wrong choice of word example – Justine Sep 30 '19 at 14:06

1 Answers1

0

the problem in your example is that the variable is local to your test case, not to the test suite.

you need to add the following command to promote the value to test suite

Set Suite Variable ${my_data}