Abhinav
Abhinav

Reputation: 39932

How to click on custom ActionbarSherlock views with Robotium

I am writing test cases for my app using Robotium. The app uses ActionbarSherlock for porting the Actionbar on versions prior to 4.0. However the ActionBar items always seem elusive to get hold of. I tried to use this project - https://github.com/atermenji/robotium-actionbarsherlock but didn't have much luck with custom actionbars. I tried the following code:

solo.clickOnVisibleActionbarItem(com.vtcreator.android360.R.id.notification_icon);

R.id.notification_icon is a button defined in the custom action bar layout.

Anyone with experience of both Robotium and ABS?

Upvotes: 2

Views: 1878

Answers (3)

Rams_QA
Rams_QA

Reputation: 121

This is the better way to handle :

This Should work along with lib robotium-actionbarsherlock @ https://github.com/atermenji/robotium-actionbarsherlock

if (Build.VERSION.SDK_INT < 11) 
 solo.clickOnActionBarHomeButtonCompat();
else 
 solo.clickOnActionBarHomeButton();

Upvotes: 0

Rams_QA
Rams_QA

Reputation: 121

In my current project which makes use of Action Bar to place Back Key and three action menu items as Image Buttons, following code worked fine -

// Selecting Back function button on Action Bar
// com.main.myapp is the package name of the main application which is under test.
ActionBarView actionBar = (ActionBarView)solo.getView(com.main.myapp.R.id.abs__action_bar);
ImageView backUpKey = (ImageView)actionBar.findViewById(com.main.myapp.R.id.abs__home);
solo.clickOnView(backUpKey);

// Click on Tools Icon on Action Bar Menu
solo.clickOnImageButton(2);

Upvotes: 3

jerieljan
jerieljan

Reputation: 415

Since you have source code access anyway, you can choose to access the ActionBar item on a view level.

View actionbarItem1 = solo.getView(R.id.notification_icon);
solo.clickOnView(actionbarItem1);

Upvotes: 6

Related Questions