Forum Xamarin Test Cloud (Read Only)

Invoking getDrawableState() in a UITest (Android)

AnneKingmaAnneKingma USUniversity ✭✭

Hi everyone,

I'm trying to use AppQuery's Invoke() method to invoke the native Android method getDrawableState() on some elements. According to Android documentation, this method returns an integer array:
So I thought it should be this:

app.Query(c => c.Class("CheckView").Invoke("getDrawableState").Value<int[]>())

But this gives me an error:

Error while performing Query(Class("CheckView").Invoke("getDrawableState").Value<Int32[]>())
Exception: System.InvalidOperationException: Actual type 'Array' not compatible with declared type 'System.Int32[]'. Value: [
  at Xamarin.UITest.Shared.Json.JsonTranslator.ConvertToSimpleType[T] (Newtonsoft.Json.Linq.JToken jToken) <0x7bf3b40 + 0x001bf> in <filename unknown>:0 
  at Xamarin.UITest.Shared.Json.JsonTranslator.<DeserializeArray`1>m__0[T] (Newtonsoft.Json.Linq.JToken c) <0x7bf3af8 + 0x00027> in <filename unknown>:0 
  at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[TSource,TResult].MoveNext () <0x3200000 + 0x000ef> in <filename unknown>:0 
  at System.Linq.Buffer`1[TElement]..ctor (IEnumerable`1 source) <0x7e52d0 + 0x001a8> in <filename unknown>:0 
  at System.Linq.Enumerable.ToArray[TSource] (IEnumerable`1 source) <0x7e5210 + 0x00047> in <filename unknown>:0 
  at Xamarin.UITest.Shared.Json.JsonTranslator.DeserializeArray[T] (Newtonsoft.Json.Linq.JArray jArray) <0x7bf36e0 + 0x000f7> in <filename unknown>:0 
  at Xamarin.UITest.Android.AndroidGestures.Query[T] (Xamarin.UITest.Queries.AppTypedSelector`1 selector) <0x7be10f0 + 0x0035f> in <filename unknown>:0 
  at Xamarin.UITest.Android.AndroidApp+<Query>c__AnonStorey2`1[T].<>m__0 () <0x7bdfd50 + 0x0007f> in <filename unknown>:0 
  at Xamarin.UITest.Utils.ErrorReporting.With[T] (System.Func`1 func, System.Object[] args, System.String memberName) <0x7bdf9f8 + 0x00034> in <filename unknown>:0 
Exception: Error while performing Query(Class("CheckView").Invoke("getDrawableState").Value<Int32[]>())

What am I doing wrong? Is the Java int[] different from the C# int[]? This approach works fine when the return value is an integer like with getCurrentTextColour (see ).

I've found a way around this issue, so I don't really need to solve it anymore, I'm just curious why it's not working the way I expected it to.

Sign In or Register to comment.