How can I return the results after running a keyword?
Example:
mykey word [Arguments] input
${results}= getme input
But I want to use these results:
${results} = mykey word newinput
How can I return the results after running a keyword?
Example:
mykey word [Arguments] input
${results}= getme input
But I want to use these results:
${results} = mykey word newinput
Robot Frameworkユーザーガイドでは、キーワードから値を返す方法について説明しています。ユーザーキーワードの戻り値を参照してください。
短いバージョンは次のとおりです。キーワードに変数を設定し、[return]
テストケース設定を使用してその変数を返します。
次に例を示します。
*** Keywords ***
mykey word
[Arguments] ${input}
${string}= set variable the string is "${input}"
[return] ${string}
*** Test Cases ***
Call custom keyword and get result
${results}= mykey word newinput
Should be equal ${results} the string is "newinput"
Robotには、キーワードのどこからでも値を明示的に返すためのいくつかのキーワードも用意されています。
[戻る] を使用して結果を返します。
例は次のとおりです。
Time Stamp
[Return] ${time_stamp}
${secs}= Get Time epoch
${time}= Get Time
${time_stamp}= Convert To String ${secs}
Time Stamp
${time_stamp} の値がキーワードに格納されます。
最も簡単な方法は、推奨される [Return] タグをキーワードの最後に使用することですが、他の方法もあります。
キーワード Set Global Variable を使用すると、キーワード自体から何も返さなくても、実行されたキーワードの外部で変数にアクセスできるようになります。これは、メインの変数リストが乱雑になるのを避け、バックグラウンドでいくつかの変数を保持したい場合に便利ですが、グローバル変数と同じくらい注意して使用してください。