开发者

Conditional statements in Ruby watir

开发者 https://www.devze.com 2023-03-18 11:41 出处:网络
so I am completely new to watir. And I am basically trying to implement a conditional text checker. I am creating a testclass using watir. So for now; assuming we are given this simple example in whic

so I am completely new to watir. And I am basically trying to implement a conditional text checker. I am creating a testclass using watir. So for now; assuming we are given this simple example in which I have a global variable @target. And depending on what @target['color'] is, I want to check for a different string. This is how I would be doing it right now:

Browser.text.include?
 if @target['color'] == "red"
   "You got rubies."
 elsif @targe开发者_运维问答t['color'] == "green"
   "You got plants"
 else
   "You got nothing"
 end

I get syntax errors around the "red"/"green". And sometimes even on elsif

Any help would be appreciated. A good link to an article especially. I haven't found anything on conditionals of this sort. Makes me think that its not possible.

I also tried doing it with the Browser.text.include? inside the conditional branches. That did not work either.


Try

Browser.text.include? case @target['color']
    when "red" then "You got rubies."
    when "green" then "You got plants"
    else  "You got nothing"
end
0

精彩评论

暂无评论...
验证码 换一张
取 消