Robotframework per loop continua con il prossimo test
Ho sotto il codice:
*** Settings ***
Library OperatingSystem
Library Process
Library String
Test Template My Run Test
*** Variables ***
@{MyList}= item items
*** Test Cases ***
#name type profile file test
[XXXXX_1] General test.out Profile mode.out
[Tags] TEST-XXXXX
*** Keywords ***
My Run Test
[Documentation] Run the suite
[Arguments] ${type} ${profile} ${file} ${test}
: FOR ${data} IN @{MyList}
\ When data is ready
\ And tool is ran
\ And get was success
\ And test suite config is updated
\ And testing tool is again run
\ Then publish test status
data is ready
Log to Console "Data is ready"
tool is ran
Log to Console "tool is ran"
Run Keyword And Return Stop Test "This is fun"
get was success
Log to Console "get was success"
test suite config is updated
Log to Console "test suite config is updated"
testing tool is again run
Log to Console "testing tool is again run"
publish test status
Log to Console "publish test status"
Stop Test
[Arguments] ${msg}
Log To Console ${msg}
Fail ${msg}
Di conseguenza, sto eseguendo una serie di parole chiave per tutti gli elementi in un elenco utilizzando for loop. Ora ho una situazione in cui per un elemento nell'elenco una valutazione non è riuscita e devo contrassegnare quel test come fallimento ma desidero che la suite di test continui con gli elementi successivi nell'elenco.
Quindi supponiamo che ci siano 3 elementi nell'elenco e il caso di test fallisce per 2 secondi elementi nell'elenco, quindi il codice dovrebbe tornare al ciclo for principale [non continuare con un'altra parola chiave per il 2o elemento] e avviare il caso di test per il 3o elemento.
Quello che ho osservato è che l'uso della parola chiave Fail e altri interrompe l'intera suite di test. C'è un modo per raggiungere questo obiettivo?
Risposte
Se si estrae il ciclo for dal modello di test nel caso di test e si utilizza Templates with for loops , è possibile rendere le iterazioni indipendenti l'una dall'altra.
Ad esempio con le seguenti modifiche:
*** Test Cases ***
[XXXXX_1]
FOR ${data} IN @{MyList}
# list item type profile file test
${data} General test.out Profile mode.out
END
*** Keywords ***
My Run Test
[Documentation] Run the suite
[Arguments] ${data} ${type} ${profile} ${file} ${test}
When data is ready
And tool is ran
And get was success
And test suite config is updated
And testing tool is again run
Then publish test status
Questo sarebbe l'output:
