Auto-tools/Projects/Robocop/WritingTests
Setup
Writing a test for Robocop shouldn't be very hard, but there is a limited API as of yet. Copying a test from the examples is the best way to start. The flow of the test will go from starting the application to killing it. Your test should be in the file test[Case].java.in -- see mobile/android/base/tests. It will have three methods in the class test[Case]: setUp(), test[Case](), and tearDown(). setUp gets called at the beginning and starts fennec. The top of the test must have:
#filter substitution package @ANDROID_PACKAGE_NAME@.tests
APIs
The three main interfaces that are used are Actions, Driver and Element. Driver finds elements. Element represents each of the available UI objects in Fennec including the Awesomebar, the 'tabs' button, and different lists and menus. Actions has a list of commonly used non-element specific actions that can be taken on the application, such as clicking, dragging and sending key events.
Actions //This will cause this process to spin until the gecko fires a specific JSON event, such as DOMContentLoaded void waitForGeckoEvent(String geckoEvent); //Clicks the given Key (Actions.SpecialKey.[DOWN|UP|LEFT|RIGHT|ENTER]) void sendSpecialKey(SpecialKey button) //Sends a string of characters to the system. (most have been implemented but not all) void sendKeys(String keysToSend); //Sends a drag action across the screen void drag(int startingX, int endingX, int startingY, int endingY)
Driver //This is used to find elements given their id's name. Element findElement(String name); //This will cause this process to spin until the gecko fires a specific JSON event, such as DOMContentLoaded void waitForGeckoEvent(String geckoEvent); //This is used for getting information on scrolls. NOTE: It must be used for the next three methods to return useful information void setupScrollHandling(); int getPageHeight(); //The total height of the page. int getScrollHeight(); //How far down the screen the client has scrolled. int getHeight(); //The height of the client's view. //The following are used to give information on the graphical location of the Gecko view on the screen. int getGeckoTop(); int getGeckoLeft(); int getGeckoHeight(); int getGeckoWidth();
Element //To click the element. void click() //Returns true if the element is currently displayed boolean isDisplayed(); //Returns the text currently displayed on the element, or direct sub-elements. String getText();
Usable IDs
The following is a list of ids that can be used with Driver.findElement(). Most of the following ids have not been tested, so might have unexpeced results, or require increased APIs for them. To know how a given object is used, in mobile/android/base, grep R.id.[id-name] * (from Objdir/mobile/android/base/R.java#id)
abouthome_content add_tab addons address_bar agent_mode all_pages_list awesome_bar awesome_screen awesomebar_button awesomebar_tabs awesomebar_text background bookmark bookmark_icon bookmark_title bookmark_url bookmarks_list browser_toolbar close container doorhanger_choices doorhanger_container doorhanger_title favicon forward gecko_layout grid history_list info list main_layout notification_image notification_progressbar notification_text notification_title outline plugin_container preferences quit recommended_addon_list reload save_as_pdf screenshot select_list share site_security stop tabs tabs_count title url