calabash / calabash-ios

Calabash for iOS
Other
1.81k stars 369 forks source link

Device Agent can not find a button by index #1177

Open kristinaste opened 8 years ago

kristinaste commented 8 years ago

Hi, I'm struggling to adapt my test to Xcode 8 with Device Agent. I'm trying to touch an alert button with Device Agent, but when there are more than one button, it only manages to touch/query the first one.

calabash-ios 0.20.0> device_agent.query({type: "button"})
DEBUG: HTTP: get http://192.168.2.2:27753/1.0/health {:retries=>1, :timeout=>0.5}
DEBUG: DeviceAgent says, "Calabash is ready and waiting."
DEBUG: Sending query with parameters:

{
  "type": "button"
}

DEBUG: HTTP: post http://192.168.2.2:27753/1.0/query {:retries=>100, :timeout=>10}
[
    [0] {
          "enabled" => true,
               "id" => "Cancel",
          "hitable" => true,
             "rect" => {
                 "y" => 353,
                 "x" => 52.5,
            "height" => 44,
             "width" => 135
        },
            "label" => "Cancel",
             "type" => "Button",
        "hit_point" => {
            "x" => 120,
            "y" => 375
        },
          "test_id" => 393
    },
    [1] {
          "enabled" => true,
               "id" => "Delete",
          "hitable" => true,
             "rect" => {
                 "y" => 353,
                 "x" => 187.5,
            "height" => 44,
             "width" => 135
        },
            "label" => "Delete",
             "type" => "Button",
        "hit_point" => {
            "x" => 255,
            "y" => 375
        },
          "test_id" => 395
    }
]
calabash-ios 0.20.0> device_agent.query({type: "button", index:1})
DEBUG: HTTP: get http://192.168.2.2:27753/1.0/health {:retries=>1, :timeout=>0.5}
DEBUG: DeviceAgent says, "Calabash is ready and waiting."
DEBUG: Sending query with parameters:

{
  "type": "button",
  "index": 1
}

DEBUG: HTTP: post http://192.168.2.2:27753/1.0/query {:retries=>100, :timeout=>10}
[]

It looks like the index part in device_agent.query({type: "TextField", index:1}) doesn't work

jmoody commented 8 years ago
# Incorrect
device_agent.query({type: "button"})

# Correct
device_agent.query({type: "Button"})

type: "TextField"

Why are you mentioning TextField in this context?

kristinaste commented 8 years ago

Because it is an example usage I've seen on the wikipage https://github.com/calabash/calabash-ios/wiki/DeviceAgent

I've tried also with Button, but the result is the same, I can not select the second query result

calabash-ios 0.20.0> device_agent.query({type: "Button"})
DEBUG: HTTP: get http://192.168.2.5:27753/1.0/health {:retries=>1, :timeout=>0.5}
DEBUG: DeviceAgent says, "Calabash is ready and waiting."
DEBUG: Sending query with parameters:
{
  "type": "Button"
}
DEBUG: HTTP: post http://192.168.2.5:27753/1.0/query {:retries=>100, :timeout=>10}
[
    [0] {
          "enabled" => true,
               "id" => "Cancelar",
          "hitable" => true,
             "rect" => {
                 "y" => 342,
                 "x" => 52.5,
            "height" => 44,
             "width" => 135
        },
            "label" => "Cancelar",
             "type" => "Button",
        "hit_point" => {
            "x" => 120,
            "y" => 364
        },
          "test_id" => 479
    },
    [1] {
          "enabled" => true,
               "id" => "Vaciar",
          "hitable" => true,
             "rect" => {
                 "y" => 342,
                 "x" => 187.5,
            "height" => 44,
             "width" => 135
        },
            "label" => "Vaciar",
             "type" => "Button",
        "hit_point" => {
            "x" => 255,
            "y" => 364
        },
          "test_id" => 481
    }
]
calabash-ios 0.20.0> device_agent.query({type: "Button", index:1})
DEBUG: HTTP: get http://192.168.2.5:27753/1.0/health {:retries=>1, :timeout=>0.5}
DEBUG: DeviceAgent says, "Calabash is ready and waiting."
DEBUG: Sending query with parameters:
{
  "type": "Button",
  "index": 1
}
DEBUG: HTTP: post http://192.168.2.5:27753/1.0/query {:retries=>100, :timeout=>10}
[]
jmoody commented 8 years ago

Is this a Privacy alert or an alert that this presented by SpringBoard (update iOS version, no SIM card, etc.)?

Or is this an alert that your application is presenting?

kristinaste commented 8 years ago

It is an alert my application shows, before I was using uia('target.frontMostApp().alert().defaultButton().tap();') and uia('target.frontMostApp().alert().cancelButton().tap();') to be able to press both alert buttons

jmoody commented 8 years ago

I will investigate.

However, you should not need to use DeviceAgent at all - the Core#query and Core#touch methods should work if this is an alert that is not presented by SpringBoard.

touch("* marked:'Cancelar'")
jmoody commented 8 years ago

@sbalajieie I have removed you comment because it did not relate to this issue.

jmoody commented 8 years ago

Reproduced.

jmoody commented 8 years ago

@jescriba This would be a good one to investigate in DeviceAgent.

jescriba commented 8 years ago

@jmoody I haven't been able to reproduce this on the latest device agent with UIAlertViews from the smoke-test-app.