4

I'm writing a test using Xamarin.UITest and I want to examine the coloor of a specific UI button. From the Repl I can grab the button like this:

>>> app.Query(c => c.Button()).First()
Query for Button() gave 1 results.
{
    Id => "buttonGo",
    Description => "android.widget.Button{b312e568 VFED..C. ........ 26,234-454,314 #7f060033 app:id/buttonGo}",
    Rect => {
        Width => 428,
        Height => 80,
        X => 26,
        Y => 328,
        CenterX => 240,
        CenterY => 368
    },
    Label => null,
    Text => "Go!",
    Class => "android.widget.Button",
    Enabled => true
}

Unfortunately there doesn't seem to be any property that will give me the colour. Is there a way for me to pull more info from the button or another way to query that I could use to find the button color?


Update: So I'm making some progress, thanks to the recommendation to use Invoke. I'm now trying to do the following:

>>> app.Query(c => c.Button("buttonGo").Invoke("getBackground"))

Which should call getBackground and return me a background drawable but instead throws the following error:

Ignoring failed json serialisation of result of Query for Button("buttonGo").Invoke("getBackground"). Value was never requested
Query for Button("buttonGo").Invoke("getBackground") gave no results.
null

If I call getHeight everything works as expected so I'm a bit baffled here:

>>> app.Query(c => c.Button("buttonGo").Invoke("getHeight"))
Query for Button("buttonGo").Invoke("getHeight") gave 1 results.
[
    [0] 80
]
Adam Cooper
  • 8,077
  • 2
  • 33
  • 51

1 Answers1

-1

What you are looking for is AppQuery.Invoke See Xamarin.UITest documentation "Invoke a Method on an AppResult or UI Element"

Update:

I think you can't return complex types, but you can chain the Invoke calls. I your case that would be:

app.WaitForElement (c => c.Button ("buttonGo")); 
app.Query(c => c.Button("buttonGo").Invoke("getBackground").Invoke("getColor"));

This will return the color id of the button.

patridge
  • 26,385
  • 18
  • 89
  • 135
hertzi
  • 2,809
  • 2
  • 14
  • 13