简体   繁体   中英

Robotium - detect objects drawn off screen

So I made a change to my Android app last week and inadvertently made some buttons get drawn outside the screen.

I could see the objects off screen in Eclipse alright and no errors were thrown but when the app ran the buttons were not visible (off screen).

Just wondering will Robotium catch this or will the buttons still be "pressable".

My question is, given the above scenario, I run a Robotium test to select a button that is no longer drawn/visible inside the screen. Will Robotium still be able to select the button and pass the test or will it fail becuase the button is no longer on screen?

Visibility

The visibility option is asserted with a snippet like below. Note that getVisibility will return an integer from 0=VISIBLE to 8=GONE with 4=INVISIBLE. More information at Android API Javadoc for View .

int expectedValue = 0; // 0=VISIBLE, 4=INVISIBLE, 8=GONE
assertEquals("Message when assert failed", expectedValue, 
    solo.getView(your.project.package.R.id.someViewId).getVisibility());

LocationOnScreen

Visibility will not always be enough to check if something is visible or not on the screen. Something can be visible while drawn off the screen or with a negative width. To verify that you can use the getLocationOnScreen() method . It will return the x and y coordinates (in that order) of the view on the screen. An example:

int] location = new int[2]; // this will hold the x and y position
// retrieve coordinates
solo.getView(your.project.package.R.id.someViewId).getLocationOnScreen(location);
// and check if possitive or whatever fits your needs
assertTrue("Message when assert failed", location[0] >= 0 && location[1] >= 0);

This should properly detect your off screen buttons.

如果您尝试单击屏幕上未绘制/不可见的按钮,Robotium 将使测试用例失败。

As far as I know, you can press the buttons if they are drawn, even if they are not visible. Eg, you can press buttons in a scrollable view of which only some parts are visible. The important thing for robotium is that is can find the buttons you want to click somethere within the views of the current activity (it somehow internally traverses the view and searches for widgets in all its subwidgets).

Robotium can press buttons off the screen but depending on how you search for the button it may or may not find it. Confusing right?

Robotium internally sometimes checks for the visibility of Views before returning them eg when you ask for all the buttons, but if you use different techniques or findById() then it will not in fact perform the same checks. You can however just use the visibility checks that are inside robotium in order to validate that it is visible or not!

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