1

I have created a suffix for any test data I use in my test cases, for instance when adding an account you must enter a name for it, I use the static text "test" and then add the suffix to the end of this, this is what I do for all fields.

However, I need to check that this data has been saved correctly and is displayed correctly during these test cases so I need to somehow make Robot Framework remember this suffix I've generated. So far in my test cases I've just been using set variable after generating the data with faker, but obviously this is contained within the keyword, how could I make it so that this generated data is accessible for the duration of my testing session (until all tests, in the folder are finished)?

My code at the minute:

*** Test Cases ***
Valid Login
    Open Browser To Login Page
    ${num}=    Random Int
    ${suffix}=    set variable    ${num}

    Input Text    username    ${suffix}

To reiterate, I then want to check this ${suffix} value in another test case

Thanks in advance!

Edit:

Test suite file

*** Test Cases ***
Valid Login
    Open Browser To Login Page
    Fill field    a11y-username    ${MYNUM}

Resource file

*** Variables ***
${MYNUM}      

*** Keywords ***
Suite Setup
    ${MYNUM}=    Random Int
    Set Suite Variable  ${MYNUM}
4

1 回答 1

2

“设置套件变量”关键字。我将创建一个套件设置(如果您的文件夹中有多个文件用于不同的测试,则在init .txt 文件中)创建此 ${suffix} 并使其可用于套件中的所有测试:

${num}=  Random Int
${SUFFIX}=  set suite variable  ${num}

注意:我使用大写字母表示该变量的范围比本地更大

于 2014-07-22T14:22:20.583 回答