jim
jim

Reputation: 9138

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?

Upvotes: 1

Views: 2139

Answers (4)

Renas
Renas

Reputation: 1919

If you try to click on a button that is not drawn/visible on the screen, Robotium will fail the test case.

Upvotes: 1

Hans Cappelle
Hans Cappelle

Reputation: 17495

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.

Upvotes: 1

Paul Harris
Paul Harris

Reputation: 5819

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 e.g. 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!

Upvotes: 0

Claas Wilke
Claas Wilke

Reputation: 1991

As far as I know, you can press the buttons if they are drawn, even if they are not visible. E.g., 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).

Upvotes: 0

Related Questions