Xamarin.UITest : Test Label,Image and Button is in Center

I have to test if image ,Label and Button is in Center and what will be the font of Text?

Answers

  • XigmondXigmond USMember ✭✭✭

    simply do your comparison process using your elements WidthRequest/HeightRequest and X/Y after your page is shown.

  • ana_riana_ri Member ✭✭

    @Xigmond said:
    simply do your comparison process using your elements WidthRequest/HeightRequest and X/Y after your page is shown.

    can you elaborate as I am new to this...

  • JohnHardmanJohnHardman GBUniversity mod

    @ana_ri said:
    I have to test if image ,Label and Button is in Center and what will be the font of Text?

    Just one thought - if you are working in a commercial environment, unless you have more test automation resources available than developer resources, I would advise automating tests of functionality rather than presentation.

    As for your actual question, you need to find the position of the VisualElement on the page and the Width (not WidthRequest) of the VisualElement. Finding the position is not just a case of getting the X property, as it is relative to the parent element, not relative to the page. If you search the forum you will find existing answers as to how to find the position relative to the page, as that question has been answered more than once before. Once you have the correct position and the Width, it's just a piece of simple maths to do the test, remembering to allow for rounding errors (do not do a test for equality of two doubles). TBH - it's probably not worth automating that test (as per my first comment above) unless you have time on your hands.

  • XigmondXigmond USMember ✭✭✭

    @ana_ri said:

    @Xigmond said:
    simply do your comparison process using your elements WidthRequest/HeightRequest and X/Y after your page is shown.

    can you elaborate as I am new to this...

    Each Element has X, Y, Width and Height Properties
    first you need to name your elements ... something like this in Xaml : <Image x:name="myImg" ....
    and then you can access this ImageView in C# like this : var img_x = myImg.X;

    and then you can do your process to compare the positions and ...

Sign In or Register to comment.