简体   繁体   中英

UI alignment check through Robotium for android App

I have an android app to test.I am using Robotium and Junit for UI testing. Suppose a page contain 5 UI elements ( Buttons ,icons etc). Now my question is how can i test the alignment of the UI icons.

Ex. i have a "mail compose icon" and i am running Junit test in a phone for a senario. Now i am running same test in another phone but in this the "mail compose icon" is showing in small size ; So will the test fail ? If not how can i ensure the size and alingment of UI elements is same in all the devices. If any mismatch occurs in size or alignment i want the test should fail.

How can i achieve that is there any other tool which can ensure the sanity of UI Elements?

Can you do this? well yes you can but I think it will be a lot of effort for minimal gain. When it comes to UI alignment etc i tend to find the small amount of manual checking involved is probably worth it.

If however you choose to ignore that...

You can find a views location by the two methods: getLocationInWindow() or getLocationOnScreen() which one you choose will depend on your layout i suggest you read about them.

Once you have picked the right one you will have its x and y co-ordinates, you will then want to check its width and or height using getWidth() and getHeight().

at this point I hope you will understand you can form a rectangle that shows the total size of the view and then use these values to compare against another views. So if you want to test all the left aligns are the same you would check each vies x value is the same, if you wanted to test they are aligned on the righthand side you would check they have the same x+ width value etc etc

int[] xy = new int[2];
view.getLocationOnScreen(xy); 
int viewWidth = view.getWidth();
int viewHeight = view.getHeight();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM