1

我正在尝试在 xamarin 表单上的单选按钮上执行按下事件。单选按钮的索引为 0 到 5。

如果我运行query("RadioButton", :contentDescription) 这将返回 6 个单选按钮(索引 0 到 5)。单选按钮没有唯一的文本,因为它们属于一组两个按钮,因此此处的索引值 2 到 5 是 RadioGroup 组的子项,所有文本标签都相同。

我想要做的是在具有特定索引的单选按钮上设置一个按下事件。

在我拥有的功能文件中:然后我按 RadioButton number 0

我创建了一个名为的自定义步骤定义radio_button_steps.rb并将其保存到默认的 calabash-android 步骤定义文件夹

<driveLetter>:\Ruby193\lib\ruby\gems\1.9.1\gems\calabash-android-0.5.8\lib\calabash-android\steps

的语法radio_button_steps.rb是:

Given /^I press the "([^\"]*)" RadioButton$/ do |text|
  tap_when_element_exists("android.widget.RadioButton {text CONTAINS[c] '#{text}'}")
end

Then /^I press RadioButton number (\d+)$/ do |index|
  tap_when_element_exists("android.widget.RadioButton index:#{index.to_i-1}")
end

结果返回:

Then(/^I press RadioButton number (\d+)$/) do |arg1|
  pending # express the regexp above with the code you wish you had
end

我试图将索引值放在带有双引号或单引号或不带引号的功能文件中,但仍然出现错误。现在我完全迷失了......

有人有什么想法吗?

4

1 回答 1

2

在查询中,您使用如下索引 query("RadioButton index:0")

所以你的步骤 def 中的方法看起来像这样

tap_when_element_exists("RadioButton index:#{arg1}")

编辑:对不起,我重读了你的问题,我之前并没有真正回答过。要让您的 then 步骤开始工作,您需要有一个带有该行的功能文件

Then I press RadioButton number 1

看起来你已经尝试过了,所以这不是问题。实际的错误是说 calabash 看不到您编写的步骤定义。Calabash 使用 cucumber,它是处理场景和步骤定义等的位。Cucumber 在项目的“功能”目录中的任何位置查找步骤定义。如果您在此处创建一个文件并将您的步骤定义放入其中,那么它应该可供您的测试运行使用。

于 2015-04-27T08:54:24.323 回答