2017-04-14 9 views
2

条件の1つが真である場合に渡される条件を確認する必要があります。Robot FrameworkのキーワードにOR条件を使用するにはどうすればよいですか?

キーワード私が使いたいように以下の通りである:場合実行キーワードを使用し

Page Should Contains Element //some xpath OR 
Page Should Contains Element //some xpath OR 
Page Should Contains Element //some xpath OR 
Page Should Contains Element //some xpath 

が、それはあなたが持つXPathの結果セットに参加することができます

答えて

4

が動作していません| ORと同等のことをする。

${count} Get Matching Xpath Count //div[@prop='value'|//table[@id='bar']|//p 
Run Keyword If ${count} > 0 Some Keyword 

あなただけのXPathのどれが見つからない場合に失敗する場合

は:

Page Should Contain Element xpath=//div[@prop='value'|//table[@id='bar']|//p 
+0

あなたの助けombre42 @ありがとうございました:) 私は再びあなたの答えから おかげで、私の質問のための代替ソリューションを見つけました:) – Umesh

+0

私が探していて、あなたがここにあなたのソリューションを投稿場合、それは偉大だったでしょう@Umesh – Shnigi

+0

@ Shnigi私は、オンラインか、オフラインか、離れているか、ビジーであるかをユーザの状態をチェックしたいと思っていました。しかし、後で、私は "Get Xpath Count"を使ってステータスと共にユーザーの数を表示しました。 $ {USERS_ONLINE}一致するXpathを取得する// div [@ class = 'participants-list'] // span [$ {USERS_ONLINE}のユーザーをログに記録する $ {USERS_OFFLINE}一致するXpathを取得する// div [@ class = 'participants-list'] // span [@ class = 'status unavailable] '] $ {USERS_OFFLINE}人のユーザーをオフラインでログに記録する – Umesh

1

何あなたが尋ねるするRun Keyword And Return Status呼び出しの組み合わせで行うことができます。

${el1 present}= Run Keyword And Return Status  Page Should Contains Element //some xpath1 
${el2 present}= Run Keyword And Return Status  Page Should Contains Element //some xpath2 
${el3 present}= Run Keyword And Return Status  Page Should Contains Element //some xpath3 
${el4 present}= Run Keyword And Return Status  Page Should Contains Element //some xpath4 

Run Keyword If not ${el1 present} or not ${el2 present} or not ${el3 present} or not ${el4 present} Fail None of the elements is present on the page 

この方法は簡単ですが、それは最適ではない - それは最初が存在することができるにもかかわらず、すべての要素をチェックし、第二、第三及び第四のためにチェックする必要はありません。それはRun Keyword Ifと呼ばれるキーワードの値を返すことを利用し

${some element present}= Run Keyword And Return Status  Page Should Contains Element //some xpath1 
${some element present}= Run Keyword If not ${some element present} Run Keyword And Return Status  Page Should Contains Element //some xpath2 ELSE Set Variable ${some element present} 
${some element present}= Run Keyword If not ${some element present} Run Keyword And Return Status  Page Should Contains Element //some xpath3 ELSE Set Variable ${some element present} 
${some element present}= Run Keyword If not ${some element present} Run Keyword And Return Status  Page Should Contains Element //some xpath4 ELSE Set Variable ${some element present} 

Run Keyword If not ${some element present} Fail None of the elements is present on the page 

:この(非常にexpresive)のバージョンがあることでしょう。

要約すると、すべての条件(Page Should Contain Element)をチェックする必要がある場合(この例ではandに接続されている対応する論理条件で、orではなく)をチェックする必要があります。
2番目の場合は1つで十分で、残りのものが真であると判断された場合は残りの部分をチェックしないでください。

関連する問題