Xamarin.UITest:How to test the color of Boxview

I a app there is a BoxView in which Gray color is set.
I need to check the color of BoxView through Xamarin.Uitest

I have applied the following approach:
Assert.AreEqual(ConsoleColor.Gray, app.Query(x => x.Marked("BoxView").Invoke("getBackground").Invoke("getColor")));

It give error=> Message: Expected: Gray
But was: < -8355712 >

Answers

  • JohnHardmanJohnHardman GBUniversity mod

    Gray without any transparency in ARGB form is FF, 80, 80, 80.
    If you convert hex FF808080 to a signed decimal you get -8355712, so the correct value is being returned.
    I haven't looked to see how ConsoleColor.Gray is defined, but would assume from your error message that it is either a string or is being converted to a string before the Assert.AreEqual is being done. See if you can explicitly convert it the same form as the result of getColor before doing the Assert.AreEqual.

  • jezhjezh Member, Xamarin Team Xamurai

    @ana_ri
    You can reach out to App Center support by logging into https://appcenter.ms/apps
    and clicking the chat icon in the lower right corner of the screen. We support Xamarin.UITest there.
    Here's a screenshot if you're having trouble finding the chat icon: https://www.screencast.com/t/uF8S5o0o0

  • ana_riana_ri Member ✭✭

    @jezh said:
    @ana_ri
    You can reach out to App Center support by logging into https://appcenter.ms/apps
    and clicking the chat icon in the lower right corner of the screen. We support Xamarin.UITest there.
    Here's a screenshot if you're having trouble finding the chat icon: https://www.screencast.com/t/uF8S5o0o0

    That chat icon is not visible.

  • JohnHardmanJohnHardman GBUniversity mod
    edited September 2018

    @ana_ri

    @JohnHardman said:
    Gray without any transparency in ARGB form is FF, 80, 80, 80.
    If you convert hex FF808080 to a signed decimal you get -8355712, so the correct value is being returned.
    I haven't looked to see how ConsoleColor.Gray is defined, but would assume from your error message that it is either a string or is being converted to a string before the Assert.AreEqual is being done. See if you can explicitly convert it the same form as the result of getColor before doing the Assert.AreEqual.

    Ok, I've had a look at ConsoleColor.Gray. I'm not sure why you are using that. Surely your starting point should be Xamarin.Forms.Color.Gray? If so, you can use the following in your Assert.AreEqual instead of ConsoleColor.Gray

    ((System.Drawing.Color) Xamarin.Forms.Color.Gray).ToArgb()
    

    If you are going to be automating multiple color tests, you might want to add a helper function to make the test code shorter.

  • jezhjezh Member, Xamarin Team Xamurai

    @ana_ri
    You can register an account and login in. And the chat icon is in the lower right corner of the screen.

Sign In or Register to comment.