Calabash iOS:如何使用query命令获取值 [英] Calabash iOS: how to get value using query command

查看:115
本文介绍了Calabash iOS:如何使用query命令获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用query命令获取每个类的值。
下面是我得到的示例UI组件:

I'm trying to get the value of every class using query command. Below is the sample UI component that I get:

[0] {
          "class" => "UITabBarSwappableImageView",
             "id" => "imageView-34",
           "rect" => {
        "center_x" => 288,
               "y" => 522,
           "width" => 48,
               "x" => 264,
        "center_y" => 538,
          "height" => 32
    },
          "frame" => {
             "y" => 2,
         "width" => 48,
             "x" => 6,
        "height" => 32
    },
          "label" => nil,
    "description" => "<UITabBarSwappableImageVie....>"

在Android上,我可以用它来列出类组件的所有值:

On Android, I can just use this to list all the values of class components:

query("*", :class)

但是,我似乎无法在iOS上使用相同的命令。
我得到这个结果:

However, I can't seem to use the same command on iOS. I get this as the result:

irb(main):135:0> query "*", :class
[
    [ 0] nil,
    [ 1] nil,
    [ 2] nil,
    [ 3] nil
]

我知道有了标签,我可以使用:accessibilityLabel来完成这项工作,但不是当我试图从类/ id /等中获取价值时。

I know that with the labels, I can use :accessibilityLabel to do the job, but not when I try to get value from class/id/etc.

有人可以解释一下吗?

推荐答案

简答:'class'不是UIView实例上的选择器

Short answer: 'class' is not a selector on UIView instances

长答案:

# query( < look for some views >, < selector on the views found > )

# look for buttons marked 'big button' and call 'isSelected' selector on them
query("button marked:'big button'", :isSelected")

# look for labels marked 'title' and call 'text' selector on them
query("label marked:'title'", :text)

# look for all views and call 'class' selector on them
# whoops!  'class' is not a selector on UIView instances
query "*", :class

退后一步,我想我知道是什么您正在尝试 - 获取可见的全面视图列表。

Taking a step back, I think I know what you are trying to do - get a comprehensive list of views that are visible.

查看 https://github.com/jmoody/briar/blob/master/lib/briar/irbrc.rb

示例输出在此处: https://gist.github.com/jmoody/8031917

不是在查询中调用'class',而是迭代查询返回的结果并查找'class'键的值。

Instead of calling 'class' in the query, iterate over the results returned by query and look for the value of the 'class' key.

query('*').map { |result| result['class'] }

这篇关于Calabash iOS:如何使用query命令获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆