2013-05-29

How to search items in Robotium?


In this article we are going to see how to search a Button or a text at an Android device while performing Unit Testing using robotium framework.

We need to initiate the Solo object. After initiation, we will uses solo to get those.

For Buttons : 
-To search a button with a specific text. It will scroll automatically.
solo.searchButton("ButtonToSearch");

-To search a button with a specific text and only if it is visible on the screen(true for visible).  It will scroll automatically if needed.
solo.searchButton("ButtonToSearch", true);

-To search a button with a specific text and minimum number matching (integer). It will scroll automatically if needed.
solo.searchButton("ButtonToSearch", 2);

-To search a button with a specific text ,minimum number matching (integer) and Visibility(true if it is visible on the scvreen). It will scroll automatically if needed. 
solo.searchButton("ButtonToSearch", 2, true );


-To search a Toggle button with a specific text. It will scroll automatically.
solo.searchToggleButton("ButtonToSearch");


-To search a Toggle button with a specific text and minimum number matching (integer). It will scroll automatically if needed.
solo.searchToggleButton("ButtonToSearch", 2);   

For Text : 
-To search a specific text in a text area(Edit text object). It will scroll automatically if needed. 
solo.searchEditText("SearchText");

-To search a specific text in full display. It will scroll automatically if needed.
solo.searchText("SearchText");

-To search a specific text in full display with Visibility(true to search in visible area on screen). It will scroll automatically if needed.
solo.searchText("SearchText", true);

-To search a specific text in full display with minimum number matching (integer) . It will scroll automatically if needed.
solo.searchText("SearchText", 2);

-To search a specific text in full display with minimum number matching (integer) and Scrolling option(true to enable scroll).
solo.searchText("SearchText", 2,true);


-To search a specific text in full display with minimum number matching (integer) ,Scrolling option(true to enable scroll). solo.searchText("SearchText", 2, true, true);

Note :
-All of these functions returns true if the search item is found, false on not found. So, it is useful for validating items on the screen.
-All text that are used as parameter, will be handled as Regular Expression searching.
-In all Match number,  0 means one or more expected matching

Thanks...:)

How to validate items in Robotium?

In this article we are going to see how to validate different items at an Android device while performing Unit Testing using robotium framework. Basically we will check whether the item present or not.

We need to initiate the Solo object. After initiation, we will uses solo to get those.

Check Box : 
-To validate(true/false) a with specific Index whether it is checked or not. 
solo.isCheckBoxChecked(0);
-To validate(true/false) a with specific text of the item whether it is checked or not. 
solo.isCheckBoxChecked("lebelText");

Radio Button :
-To validate(true/false) a with specific Index whether it is selected or not. 
solo.isRadioButtonChecked(0);

-To validate(true/false) a with specific text of the item whether it is selected or not.  
solo.isRadioButtonChecked("lebelText");
 
Spinner Menu / Sub Menu :
-To validate(true/false) if the specific text is selected in any Spinner in screen.So, it returns true if that text is present
solo.isSpinnerTextSelected("lebelText");

-To validate(true/false) if the specific text is selected in indexed (0 based) Spinner in screen. We are just specifying the spinner here.
solo.isSpinnerTextSelected(0, "lebelText");

Toggle Button : 
-To validate(true/false) a with specific Index whether it is checked or not. 
solo.isToggleButtonChecked(0);

-To validate(true/false) a with specific text of the item whether it is checked or not.
solo.isToggleButtonChecked("lebelText");


Text based compound button :

-To Check the specific Text is checked or not. It is used with checked text box or compound button.
solo.isTextChecked("lebelText");


Note : As all are validation functions , so each function returns Boolean value(true/false). So we can use them for conditional purpose.

...Thanks...:)

How to insert text / type in Robotium?

In this article we are going to see how to insert a text or data using at an Android device while performing Unit Testing using robotium framework. Android handles those keys like as soft key board.

We need to initiate the Solo object. After initiation, we will uses solo to get those.

-To enter a text to a specific editable text area (EditText object) . In here myEditText is the EditText item
solo.enterText(myEditText, "InputString");

-To enter a text to a index(0 based) of a editable text area 
solo.enterText(1,"MyString");

-To enter a text in a specific web element . Use any one By method to get web element.
solo.enterTextInWebElement(By.id("uid"), "shantonu");

Like as Entering Text,, we can type the text also. The basic difference, it will keep a delay as well as use different event in android.

-To type a text in a specific editable text area (EditText object)
 solo.typeText(myEditText, "StringToType");

-To type a text to a index(0 based) of a editable text area
solo.typeText(0, "StringToType");

-To enter a text in a specific web element . Use any one By method to get web element.
solo.typeTextInWebElement(By.id("uid"), "StringToType");


-To enter a text in a specific web element object. myWebElement is a web element object.
solo.typeTextInWebElement(myWebElement, "StringToType");


-To enter a text in a specific web element and index(0 based) of matches. Use any one By method to get web element.
solo.typeTextInWebElement(By.id("uid"), "StringToType", 0);

Thanks..:) 

How to drag in Robotium?

In this article we are going to see how to Drag an Item in robotium. Android provides seperate event for dragging.

We need to initiate the Solo object. After initiation, we will uses solo to get those.

-To drag( Simulate touching) from a specified location to a new location.
solo.drag(0, 240, 0, 400, 10);

In here , parameters
a. From position (X coordinate) of initial touch
b. To position (X coordinate) of the drag destination
c. From position (Y coordinate) of initial touch
d. To position (Y coordinate) of the drag destination 
e. Step counter(integer) indicating the number of steps to drag. Step count is the number performing the drag operation in to number of steps. Ex- it we move (0,0) to (240,400) , we can make it in 10 steps or 240 steps. If we make 10 steps, dragging will be (0,0) to (

Thanks..:) 

2013-05-28

How to long press in Robotium?

In this article we are going to see how to click /press long. It is a spatial event like as clicking. Android provide separate event handler for long press. Ex- when we press on screen long time(3s+), the menu comes.

We need to initiate the Solo object. After initiation, we will uses solo to get those.

-To Long click on specific list line of a text view. It returns an ArrayList of the TextView objects (contains the lines). It will get the first ListView that it finds.
solo.clickLongInList(0);

-To Long click on specific list line of a text view and the index. It returns an ArrayList of the TextView objects (contains the lines).
solo.clickLongInList(1,0);

-To Long click on specific list line of a text view , the index and the amount of time (long press time in millisecond integer) . It returns an ArrayList of the TextView objects (contains the lines).
solo.clickLongInList(2, 1,5);

-To Long click on specific coordinate X, Y. This coordinate is the resolution of the screen.Ex-480x800, here X=480(max) and Y=800(max) in portrait mode.
solo.clickLongOnScreen(240, 400);

-To Long click on specific coordinate X, Y and the amount of time (long press time in millisecond integer)
solo.clickLongOnScreen(240,400,5);

-To Long click on a View/Web Element displaying a specific text. It will automatically scroll.
solo.clickLongOnText("TextToClick");

-To Long click on a View/Web Element displaying a specific text and the index for multiple match. It will automatically scroll.
solo.clickLongOnText("Regix", 0);

-To Long click on a View/Web Element displaying a specific text , the index for multiple match and scroll Boolean value . Provide true when if we need to enable scrolling.
solo.clickLongOnText("Regix", 0, true);

-To Long click on a View/Web Element displaying a specific text , the index for multiple match and the amount of time (long press time in millisecond integer)
solo.clickLongOnText("Regix", 0, 5);

-To Long click on specific text and then selects an item(index) from the context menu that appears. It will automatically scroll.
solo.clickLongOnTextAndPress("Regix", 1);

-To Long click on specific view. In here myView is a view object.
solo.clickLongOnView(myView);

-To Long click on specific view and the amount of time (long press time in millisecond integer)
solo.clickLongOnView(myView, 5);

Thanks...:)

How to scroll/ nevigate in Robotium?

In this article we are going to see how to scroll on the screen in robotium. Basically, this is nevigation over items.

We need to initiate the Solo object. After initiation, we will uses solo to get those.

-To scroll down to screen.
solo.scrollDown();
It returns false if not possible(end of screen)

-To scroll down to specific list (AbsListView). In here mylist is a AbsListView item
solo.scrollDownList(myList);
It returns false if not possible(end of screen)

-To scroll down to specific index(zero based) in a ListView
solo.scrollDownList(0);
It returns false if not possible(end of screen)

-To scroll to bottom of the screen
solo.scrollToBottom();      

-To scroll to bottom of the list (AbsListView). In here mylist is a AbsListView item
solo.scrollListToBottom(myList);
It returns false if not possible(end of screen)

-To scroll to bottom to specific ListView index(zero based)
solo.scrollListToBottom(1);      
It returns false if not possible(end of screen)

-To scroll a specified AbsListView and Line (integer)
solo.scrollListToLine(myList, 1);

-To scroll a AbsListView item with specific index and specified line. Both integer
solo.scrollListToLine(1,1);      

-To scroll Horizontally. We can provide two values as parameter, solo.RIGHT or solo.LEFT
solo.scrollToSide(solo.RIGHT);

-To scroll Horizontally to a specific AbsListView item.
solo.scrollViewToSide(myView, solo.LEFT);

Note : We can provide two values as parameter, solo.RIGHT or solo.LEFT

-To scroll to top of the screen
solo.scrollToTop();
      
-To scroll Up. It returns false if not possible(top of screen)
solo.scrollUp();

-To scroll Up to specific AbsListView item
solo.scrollUpList(myList);

-To scroll Up a list view to specific Index(Zero Based)
solo.scrollUpList(1);

-To scroll the list to the top in a specific AbsListView item.
solo.scrollListToTop(myList);
It returns false if not possible(top of screen)

-To scroll the list to the top in a list view index(Zero Based)
solo.scrollListToTop(0);
It returns false if not possible(top of screen)

...Thanks...:)

How to click an item in Robotium?

In this article we are going to see how to click different type of items using Robotium.

We need to initiate the Solo object. After initiation, we will uses solo to get those.

For List items:
- To click a specific list line and returns an Array List of TextView objects. .

solo.clickInList(0);
Parameter is the Line Number to click. Will use the first ListView of it finds.


- To click a specific list line and returns an Array List of TextView objects. .
solo.clickInList(1,0);
Parameter is the Line Number and the List Index to click.

For Buttons : 
-To  click Home Button
solo.clickOnActionBarHomeButton();

-To click the Action Bar Item with specific id( as integer )
solo.clickOnActionBarItem(1);


-To click Button that matches the Id( as integer )
solo.clickOnButton(1);

-To click Button that matches the text
 solo.clickOnButton("Delete");
It will use scrolling automatically

-To click on an image Button with specific index(zero based Integer)
solo.clickOnImageButton(0);

-To click a toggle Button that matches the text
solo.clickOnToggleButton("Enable");

-To click on an Radio Button with specific index(zero based Integer)
solo.clickOnRadioButton(0);

-To click Check Box that matches the Id( as integer )
solo.clickOnCheckBox(0);


For View or Web Element : 
-To click a View /WebElement item that showing a specific text. It will automatically scroll if needed.
solo.clickOnText("ClickHere");


-To click a View /WebElement item that showing a specific text and matching index.
solo.clickOnText("Regix", 0);

-To click a View /WebElement item that showing a specific text, matching and scrolling mode
solo.clickOnText("Regix", 0, true);

Note : 
-The text parameter is handled as Regix matching
-Matching Index will define which one to click on multiple objects found.
-Scrolling true means, it will scroll.

-To click a specific view 
solo.clickOnView(myView);

-To click a specific view without wait(immediately)
solo.clickOnView(myView, true);

-To click a web element with a specified object(using By)
solo.clickOnWebElement(By.id("Id"));

-To click a web element with a specified object(using By) and matching index.
solo.clickOnWebElement(By.id("Id"), 0);

-To click a web element with a specified object(using By) ,matching index and scrolling selection(true/false). If true, scrolling will be performed
solo.clickOnWebElement(By.id("Id"), 0, true);

-To click a specific web element
solo.clickOnWebElement(myWebElement);

There are some other items which can be present for click event. Some are clicked in following ways.

-To click on current EditText item with specific index(zero based Integer)

solo.clickOnEditText(0);

-To click on an image view item with specific index.(zero based Integer)
solo.clickOnImage(0);

-To click on screen position with X coordinate and Y coordinate .
solo.clickOnScreen(240,400);
X an Y coordinate calculated from top upper corner of screen. For example if you have a cell phone of 480x800 resolution. When it is in portrait mode, x value max 480, Y value max 800.

Thanks..:)

2013-05-27

How to delete text in Robotium?

In this article we are going to see how can we clear text from a android item or a web element with robotium framework.
After Initiating solo, we will mainly two type asserts

-To clear text from current edit text item(in here myEditText)
solo.clearEditText(myEditText);        

-To clear text from currently active edit text item's index(zero based)
solo.clearEditText(0);

-To clear text from a web element specified by a locator(i used Xpath, you may use others, see all By options from this post)
solo.clearTextInWebElement(By.xpath("XpathOftheItem"));
       
Thanks...:)

What are the asserts in Robotium(build in)?

In this article we are going to see the build in asserts methods spatially come with robotium framework. These are not predefined Java asserts, these are from solo object specified form mobile.

After Initiating solo, we will mainly two type asserts

1. Memory checking : This asserts the available memory is not low by the system. Actually, it checks whether the current system memory is running low or not.
solo.assertMemoryNotLow();

Actually this is the implementation of this :
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();        ((ActivityManager)activityUtils.getCurrentActivity().getSystemService("activity")).getMemoryInfo(mi);
Assert.assertFalse("Low memory available: " + mi.availMem + " bytes!", mi.lowMemory);

2. Activity Checking : This assert is spatially for checking current activity. It has 4 overloaded methods to get this checking in 4 ways. We assume current activity = NoteEditor

-To check current activity with specified message and name
solo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor");


-To check current activity with specified message ,name and new instance or not.
solo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor", true);

-To check current activity with specified message and Class (extracted from Name)
solo.assertCurrentActivity("Expected NoteEditor activity",NotesList.class);

-To check current activity with specified message ,Class (extracted from Name) new instance or not.
solo.assertCurrentActivity("Expected NoteEditor activity", NotesList.class, true);

Note :  The Boolean value checks whether it is new activity or not where we use this.

Thanks..:) 

2013-05-23

Function Helper in Jmeter

In this article we are going to see function helper of jmeter. As we know, we use jmeter function to get various information for using as data while testing and we use this format {$__functionName(parameter1, parameter 2, ...)} to use them

So, what is Function Helper? It's simple an UI that helps to understand the functions and provide the variable string directly usable in the jmeter scripts. To start Function Helper, we need to
open jmeter  > Click Options > click Function Helper Dialog.


And we will get this UI.
 

The working is simple,
Step1: Select a function from drop down
Step2: Insert value according the description of the paramter
Step 3: Click Generate and we will get formatted string used in jmeter script.
If we need multiple variables, we can add or delete( depends on which function we use)

Thanks..:)