calabash-android 将 contentDescription 传递到自定义步骤定义中

calabash-android passing in contentDescription into custom step definition

我正在尝试将 contentDescription 传递到自定义步骤定义中,但收效甚微,而且我不确定自己能否做到,那里的帮助很少,所以我有点迷茫。

所以我启动了 calabash-android console 然后 start_test_server_in_background then query("TextView") 其中returns textView中的一个元素列表,在这个列表中是contentDescription,每个都有一个字符串值,e.g "thisIsValue"

现在我在我的功能文件中写了一个步骤:

然后我触摸 contentDescription "thisIsValue" text

我的自定义步骤方法的语法是:

然后 /^I touch contentDescription text (\d+)$/ do |text, contentDescription| tap_when_element_exists("contentDescription contentDescription:#{arg1}")

我开始认为对于表单上相同文本的多个值来说,传递 contentDescription 是不可能的,由于在我们的实例中生成 xamarin 表单的方式,使用 ID 是不可能的,另一种选择是在索引上,但是这并不是很好的前进。

谢谢大家。

格雷姆

关于您的步骤定义的详细信息很少。

  1. (\d+) 正则表达式表示您只查找 contentDescription 中包含数字的元素。
  2. 您正在传递第一个值(上面提到的仅数字值),然后期望传递两个值(textcontentDescription)。
  3. 您应该点击 TextViewImageView* 等类型的元素,但您想要点击 contentDescription 元素。
  4. 您想要点击具有 contentDescription 且值为 arg1 的元素,但您的块中有 none arg1
  5. 不要忘记查询中 contentDescription 值周围的撇号。

因此,您的步骤定义可能应该如下所示:

Then /^I touch contentDescription text: (.*?)$/ do |arg1|
  tap_when_element_exists("TextView contentDescription:'#{arg1}'")
end

@kjuri - 你的解决方案现在已经奏效了,看来在我的 windows 环境设置中它正在查看不正确的步骤定义,我清除了文件夹并重新开始 - 基本上打开它并再次关闭!非常感谢您对此的耐心等待,以及您的帮助……非常感谢。总结这个工作:

然后 /^I touch the contentDescription "(.*?)" text$/ do |text| tap_when_element_exists("RadioButton contentDescription:'#{text}'") 结束