android - 使用 calabash-android 获取元素的颜色

标签 android ruby calabash

我的 Android 应用程序中有一个文本字段(EditView),如果它的值无效或为空,它会更改颜色(边框)。在这种情况下,标签(TextView)也会改变它的颜色。

当我尝试使用 query 获取 TextView 时,我看到以下内容:

[0] {
                    "id" => "field_lable",
               "enabled" => true,
    "contentDescription" => nil,
                 "class" => "android.widget.TextView",
                  "text" => "Name",
                  "rect" => {
        "center_y" => 198.5,
        "center_x" => 51.0,
          "height" => 27,
               "y" => 185,
           "width" => 82,
               "x" => 10
    },
           "description" => "android.widget.TextView@a28btb00"
}

如果我需要获取文本,我可以使用 query("TextView id:'field_label'", :text)

Calabash中有没有办法获取TextView的颜色?

最佳答案

不幸的是,这在 Android 中是不可能的。

在 Android 中,Views(还有 TextView)几乎可以将任何东西作为背景,而不仅仅是颜色(位图、形状、渐变颜色等) 。因此,无法获取 View 的背景颜色(不会存储)。

这不是Calabash的限制,而是Android系统的限制。您可以获取 Android View 的任何可访问属性。

可以在TextView上查询以下颜色(没有背景):

  • 文本颜色:currentTextColor
  • hintTextColor :hintTextColor
  • 高亮颜色:highlightColor
  • 阴影颜色:shadowColor

关于android - 使用 calabash-android 获取元素的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21185624/

相关文章:

ruby - 需要所有正则表达式匹配,而不仅仅是第一个

gradle - 如何将XProc用作gradle中的副本过滤器?

ios - 如何在 mac OS 中使用 calabash-ios 测试 ipa 文件?

java - 将微调器数组中的选定值传递给另一个 Android 类

android - TestFairy 构建 apk 后初始化 fragment 上的 VerifyError

ruby - 如何在 Ruby 的哈希文字中将 heredoc 与其他键值对分开?

css - 我无法在 WebView 上下文中查询

android - 谷歌方向和语音导航

android - 为什么支持FragmentManager.saveFragmentInstanceState(selectedFragment)!! = 空

ruby-on-rails - 路由错误 - 在 rails 中使用 activerecord-reputation-system gem 时没有路由匹配 [GET] 错误