1

I'm trying to validate the existence of a UIButton that is initially disabled continueButton.isEnabled = false.

When I check the tree in calabash-ios console I get the following result

[UIWindow] 
  [UIView]   
    [UIView]     
      [MyProject.GradientView]       
      [UIImageView] [id:logo-1] [label:Logo 1]       
      [UIImageView] [id:logo-2] [label:Logo 2]       
      [MyProject.UnderlinedTextField] [label:Email] [text:]       
        [UITextFieldLabel] [label:EMAIL] [text:EMAIL]         
        [UIAccessibilityTextFieldElement] [label:Email] [text:EMAIL]         
      [UIButton] [label:Let's go]       
        [UIButtonLabel] [label:LET'S GO] [text:LET'S GO]         
true

However, when I try to use query("button") I get an empty array. If the button is enabled and use query again the result is:

[
    [0] {
                          "id" => nil,
                 "description" => "<UIButton: 0x7fcdc8f1b6b0; frame = (23 571; 329 63); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x608000228b20>>",
                       "label" => "Let's go",
                       "frame" => {
                 "y" => 571,
                 "x" => 23,
             "width" => 329,
            "height" => 63
        },
        "accessibilityElement" => true,
                       "value" => nil,
                       "alpha" => 1,
                     "enabled" => true,
                     "visible" => 1,
                    "selected" => false,
                       "class" => "UIButton",
                        "rect" => {
                   "y" => 571,
            "center_x" => 187.5,
            "center_y" => 602.5,
                   "x" => 23,
               "width" => 329,
              "height" => 63
        }
    }
]

Why a disabled button is not listed when using query? Is there any way to validate if a button exists regardless of its enable state?

UPDATE

When using query ("all button") as suggested by jmoody I'm able to get the button listed.

[
    [0] {
                          "id" => nil,
                 "description" => "<UIButton: 0x7fe05ad18000; frame = (23 571; 329 63); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x60000022d940>>",
                       "label" => "Lets go",
                       "frame" => {
                 "y" => 571,
                 "x" => 23,
             "width" => 329,
            "height" => 63
        },
        "accessibilityElement" => true,
                       "value" => nil,
                       "alpha" => 1,
                     "enabled" => false,
                     "visible" => 0,
                    "selected" => false,
                       "class" => "UIButton",
                        "rect" => {
                   "y" => 571,
            "center_x" => 187.5,
            "center_y" => 602.5,
                   "x" => 23,
               "width" => 329,
              "height" => 63
        }
    }
]
Diego A. Rincon
  • 747
  • 1
  • 8
  • 25

2 Answers2

1

When the button is disabled, is it physically visible?

  # All buttons regardless of visibility.
  query("all button")

  # Ask every button if is enabled.
  query("all button", :isEnabled)

  # Filter buttons by disabled
  query("all button isEnabled:0")

Why a disabled button is not listed when using query?

Calabash uses a visibility heuristic to determine if a view is visible.

At first glance, it does not look like Calabash asks anything about whether a UIControl is enabled or disabled to determine if a view is visible.

jmoody
  • 2,480
  • 1
  • 16
  • 22
  • Thank you for your response. I update the question with the results of `query("all button")`. As you can see the button is within the screen bounds and it has an alpha value of 1. I don't understand why `visible` changed to `0`` – Diego A. Rincon Jan 27 '17 at 16:12
  • @jmoody, +1 I have the same issue, the button is visible, when enabled state changes it gets invisible in the eyes of calabash. Thus I am unable to check for visibility (the button can be either hidden, disabled or enabled, so the checks don't seem to work when it's disabled... ) – igrek Apr 27 '17 at 14:07
0

I have the same issue, but I can suggest a workaround:

  1. specify different accessibilityIdentifier for the button when it's hidden or visible, something like my_super_button_hidden, when it's hidden and my_super_button_visible otherwise
  2. always use all keyword in your button query
  3. examine visibility by checking accessibilityIdentifier
  4. examine enabled state as you did before

checked on ruby 2.4.0, run_loop 2.3.1

igrek
  • 1,415
  • 1
  • 12
  • 27