Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

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-20

How to find a webelement or webelements in Robotium?

In this article we will see the functions used for getting a web element from a web application using Robotium while doing testing.

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

For Single web element : 

Solo object have a function named  solo.getWebElement(), where we use two parameter to get element. First parameter is for element finder(By object) and 2nd one is the index(nth found), So
-The function returns a web element
-We need to specify By object( the object finder)
-We need to specify index. (Zero based integer index and in here 0 means found 1)

-To select a web element by its class name(Actually it is the type name defines what type of web element that is, like button, text box etc)
solo.getWebElement(By.className("Textbox"),0);

-To select a web element by its css selector
solo.getWebElement(By.cssSelector("CSSAsString"),0);

-To select a web element by its ID
solo.getWebElement(By.id("idAsString"), 0);

-To select a web element by its  Name
solo.getWebElement(By.name("NameAsString"), 0);

 -To select a web element by itsTag Name
solo.getWebElement(By.tagName("tagNameAsString"), 0);

-To select a web element by its text content
solo.getWebElement(By.textContent("contentAsString"), 0);

-To select a web element by its Xpath
solo.getWebElement(By.xpath("xpathAsString"), 0);

For Multiple web element : 

There are two function,

1. solo.getCurrentWebElements(By.[--by xpath or above items--])
This is just multiple version of previous single web element finding

2. solo.getCurrentWebElements(); 

For both cases they provide an array list of WebElements displayed in the active WebView.

Thanks..:)

How to press menu items in Robotium?

In this article we are going to see how to check different items from menu. Basically, the items that comes when we press menu button.

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

-To click an items with a text present in the menu.
solo.clickOnMenuItem("ItemName");


-To click an items with a text present in the menu or the sub-menu. If it is true in second parameter, it will check all sub-menu items.
solo.clickOnMenuItem("ItemName", false);


Note: This text will be used as regular expression(it will match with all items of the menu)

-To click a menu item based on it's index(0 Based, integer).
solo.pressMenuItem(0);


-To click a menu item based on it's index(0 Based, integer). In here, we need to mention the number of items present in each row(in integer).
solo.pressMenuItem(0, 3);


Note : In here, Index are sequentially made. Ex- if there are 2 rows and 4 items in each column, index 0=1st row, 1st item and 5=2nd row 2nd item

-To click a Drop Down Menu item based on it's deop down menu index and item index( both are 0 Based integer). First parameter is the index of drop down menu, 2nd one is the item index.
solo.pressSpinnerItem(2, 0);
-I here, Negative number in 2nd parameter(as item index) will move clicking to Up, positive number will be to Down.


..Thanks...:)

How to take a screenshot in robotium?

In this article we are going to see how to take a screenshot in an Android device while performing Unit Testing using robotium framework.

After Initiating solo, we need to use the object of solo.

-To take screenshot with default naming
 solo.takeScreenshot();

-To take screenshot with our given name
solo.takeScreenshot("NameOfTheFile");

-To take screenshot with our given name along with given quality
solo.takeScreenshot("NameOfTheFile",5);

Note :
-Default naming makes the name with current date and time.
-The given quality is measured by compression rate(in integer) 0-100 of the screen shot. 0=lowest size, 100= max quality.
-By default, it saves the screenshot in "/sdcard/Robotium-Screenshots/", So if you are using emulator, do not forget keep an SD card.
-As, it will store, it will need write permission in AndroidManifest.xml
 
(android.permission.WRITE_EXTERNAL_STORAGE)
for latest revision, if we forget to permit this,

Thanks..:)