ruby - Watir 平等测试

标签 ruby cucumber watir

正在进行 Cucumber/Watir 测试以测试图像旋转器/循环是否正常工作。我的策略是通过 css 类获取旋转器中的事件图像并将其转储到变量中。然后我单击下一步按钮并通过 css 类在旋转器中抓取事件图像(现在应该是一个新图像)并将其转储到第二个变量中。然后我应该可以说 img_rot_1 != img_rot_2 并让测试返回 true 或 false。这是我遇到麻烦的部分。

我是 Ruby 的新手,所以我可能会遗漏一些简单的东西。这是测试。

require 'step_definition/setup'

test_setup = Wsetup.new 'http://loginurl', 'uname', 'pass' # browser object created here as # test_setup.b
img_rot_1 = String.new
img_rot_2 = String.new 

When /^I click the next image button$/ do
  test_setup.do_login
  test_setup.b.goto('http://psu.dev1.fayze2.com/node/56')
  img_rot_1  = test_setup.b.li(:class => 'flex-active-slide').img.src
  test_setup.b.link(:class => 'flex-next').click
end

Then /^the rotator should move to the next image$/ do
  img_rot_2  = test_setup.b.li(:class => 'flex-active-slide').img.src
  img_rot_1 != img_rot_2
end

img_rot_1 != img_rot_2 和 img_rot_1 == img_rot_2 都通过了 - 那么我错过了什么?

最佳答案

我认为如果你想访问在一个步骤中从另一个步骤创建的变量,你必须使用实例变量。

类似于:

When /^I click the next image button$/ do
  # more code here
  @img_rot_1  = test_setup.b.li(:class => 'flex-active-slide').img.src
end

Then /^the rotator should move to the next image$/ do
  img_rot_2  = test_setup.b.li(:class => 'flex-active-slide').img.src
  @img_rot_1.should_not == img_rot_2
end

关于ruby - Watir 平等测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13121769/

相关文章:

ruby - 到达文件的 cucumber 末尾(EOFError)

css - 使用 Watir 在 td 中单击链接

mysql - PG::Error : 结果已被清除 Rails 序列化

ruby - 重用 cucumber 步骤

ruby-on-rails - ruby rails : serialize Hash incredibly slow

java - Cucumber Java - ExtendedCucumberOptions 在 Runner 类中不执行任何操作(报告)

ruby - 使用 Selenium 多次出现 "Basic Authentication"弹出窗口

java - 如何在 cucumber 中编写空字符串和非空字符串的正则表达式

ruby-on-rails - Ruby on Rails - PUT 方法创建额外的参数条目

google-chrome - 从 teamcity 启动时使用 ChromeDriver 时出错