Question

I just got started with Robotium and tried a first very simple test, but experience some problem which I can't explain / doesn't seem logic to me.

I have a TabHost with an ActivityGroup and a toggle button on each activity that's displayed in the tabhost content section. When I press the toggle button, the tab content area changes to another activity (mTabHost.setCurrentTab(Intent intent);). Every activity holds such a toggle button, always with a label "Toggle". When I click the toggle button on the seconds activity, it will switch back to the first (all inside the tab content area).

|-----------------|
| TabHost |       | 
|-----------------| 
|                 | 
| Toggle-Button   | 
|                 | 
| (ActivityGroup: | 
| Activities      | 
| change in here) |
|                 | 
|-----------------|

Now, manually this all works fine, but the robotium test doesn't. When I attempt to click the toggle button on the second activity, I get an error message "junit.framework.AssertionFailedError: View can not be clicked!"

This is my test - very simple and small:

    solo.sleep(5000);
    solo.waitForActivity("StartTabsActivity", 10000);

    solo.clickOnButton("Toggle");
    // this will swap the activity inside the tabhost content section

    solo.sleep(5000);
    solo.waitForActivity("StatusListActivity", 5000);

    solo.assertCurrentActivity("Expected StatusList activity", "StatusListActivity");

    LogUtils.logD("robotium: button label: " + solo.getButton(1).getText()); 
    // ... outputs: robotium: button label: Toggle

    LogUtils.logD("robotium: button clickable: " + solo.getButton(1).isClickable()); 
    // ... outputs: robotium: button clickable: true

    solo.clickOnButton("Toggle");   
    // ... throws: junit.framework.AssertionFailedError: View can not be clicked!

What I don't understand here: I am checking that the button with "Toggle" label exists and is clickable, nevertheless, I'm getting an error saying "This view cannot be clicked.". And there's only one "Toggle" button in the respective current activity.

Related to this question I have another minor one: When I work with TabHost + ActivityGroup, will "solo.getCurrentActivity()" always return the embedded activity of the ActivityGroup, not the outer one? Can solo still access elements of the outer activity though? In my above case though, the toggle button is always part of the inner/embedded activity - in case that matters here.

Was it helpful?

Solution

Just got reply from robotium dev, that this is an issue that will be fixed in Robotium 1.8. See Here

OTHER TIPS

You can use this one:

solo.clickOnView(solo.getView("Toggle"))

or:

solo.clickOnView(solo.getView(R.id.B))

Instead you can go for JUnit Automation itself provided by Android. You can easily send KeyEvents to select the menu option & finish the task.

All you need to do is create a JUnit test case method in the test code which selects the menu option. Follow these methods below:-

  • Launch Activity in the test method
  • send keyevent menu click to the activity. When the Menu options are displayed send Up, Down, Left & Right keyevents to get the focus on the option & send keyevent DPAD CENTER.

Hope this well solve your problem. But before this you have to know a bit of JUnit & test framework available in Android sdk..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top