Calabash - 如何比较标签中给定 ID 的文本?

Calabash - how to compare text from label with given id?

我想断言 Calabash 查询具有给定 ID 的标签的结果。但是 'assert' 方法在 Calabash 中似乎不存在。我测试了一个 iOS 应用程序。

我的代码:

Then(/^arrival date has been changed to day after departure date$/) do
    departure_date_day = query("label marked:'departure_date_day'", :text).first
    arrival_date_day = query("label marked:'arrival_date_day'", :text ()).first
    # assert arrival_date_day.to_i == departure_date_day.to_i + 1
end

如何操作?

此致,

迈克尔

这些方法存在于基础 Ruby 堆栈中,而不是 Calabash。您可以在此处找到 Ruby 的断言方法: http://ruby-doc.org/stdlib-2.0/libdoc/minitest/rdoc/MiniTest/Assertions.html

更多信息在这里: https://github.com/seattlerb/minitest

我个人喜欢 Ruby 的 'should' 语法,而不是使用断言。首先安装这个 gem:

gem install rspec-expectations

然后在 features/support/env.rb:

require 'rspec/expectations'

最后,你可以这样断言:

departure_date_day.should eq query("label marked:'departure_date_day'", :text).first

Should 已被弃用,取而代之的是 expect()。我还是更喜欢应该……更多信息在这里:http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/