QA SoftVision Team/Mobile/Writing tests
< QA SoftVision Team | Mobile
Jump to navigation
Jump to search
Getting Started
- You can find information about setting up the enviroment for running the tests here
- Please make sure to look over this page for some general information about Robocop tests.
- Robocop is a Java API based on the Robotium API used for automation testing on the Android OS
- The existing test cases can be found in the sorce directory under the folder mobile/android/base/tests
- The class that will cover the text will have to be named the same as the test file
- The test file name should be test[Feature_to_be_tested].java.in
- The test must be included in the same package as all other Robocop tests
Basic structure of the test
package org.mozilla.fennec_root.tests; // Robotium test package
import org.mozilla.fennec_root.*; // import the package in order to be able to reuse classes if needed
/*
Insert info about the test here - a basic description of what the test does
*/
public class test[Feature_to_be_tested] extends BaseTest {
@Override
// This method is needed in the BaseTest class
protected int getTestType() {
return TEST_MOCHITEST; // Test type should remain Mochitest
}
/*
* This is the class constructor
* This method will contatin the test that will be ran
*/
public void testLoad() {
}
}
- This is a basic structure of a Robocop test
- Each test class must have three methods:
- protected void setUp() // Starts Fennec and sets up commonly used member variables. This is usually very similar for every test class
- public void test[YourFeature]() // Your test code goes here. Use the Robocop API to access Fennec elements, click, send keys, and assert conditions
- public void tearDown() // Clean up
- If your tests extends BaseTest then you will not need to add the methods setUp() and tearDown() as they are already defined in BaseTest
- If you need to do extra clean-up, like removing entries you added in a database for e.g., the tearDown() method can be overwrittern but make sure to call super.tearDown() as needed in the method. The same is applicable for setUp().
Basic code sequences to do different actions
Load page
- Using an URL
String url = "<insert_link_here>"; loadURL(url);
- Using the robocop tests blank page
String url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
loadUrl(url);
Check Title
Element awesomebar = mDriver.findElement(getActivity(), "awesome_bar_title"); // search the awesomebar title mAsserter.isnot(awesomebar, null, "Got the awesomebar"); // log "Got the awesomebar" in the logs assertMatches(awesomebar.getText(), "<insert_title_here", "page title match"); // do a match between expected and actual title
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
//Open the More menu for devices with old style menues
if (mSolo.waitForText("^More$")) {
mSolo.clickOnText("^More$");
}
Open Menu item
mSolo.waitForText("^Settings$");
mSolo.clickOnText("^Settings$");
Set up listeners to catch the page load
Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
Wait for the new tab and page to load
tabEventExpecter.blockForEvent(); contentEventExpecter.blockForEvent();