Bug 701076 - [tests] Robotium integration into mozilla-central. r=mfinkle,dburns

This commit is contained in:
Joel Maher 2011-12-16 14:27:52 -05:00
Родитель a48bdecde5
Коммит 90498fe0fa
5 изменённых файлов: 544 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,108 @@
#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import com.jayway.android.robotium.solo.Solo;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import android.test.PerformanceTestCase;
import android.util.Log;
import android.widget.Button;
import android.content.Intent;
import java.util.HashMap;
@SuppressWarnings("unused")
public class testAwesomebar extends ActivityInstrumentationTestCase2 {
@SuppressWarnings("unchecked")
public testAwesomebar(Class activityClass) {
super(activityClass);
// TODO Auto-generated constructor stub
}
private static final String TARGET_PACKAGE_ID = "org.mozilla.gecko";
private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME="@ANDROID_PACKAGE_NAME@.App";
private Solo solo;
private Activity activity;
private Driver driver;
private Actions actions;
private static Class<?> launcherActivityClass;
static{
try{
launcherActivityClass = Class.forName(LAUNCH_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e){
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public testAwesomebar() throws ClassNotFoundException {
super(TARGET_PACKAGE_ID, launcherActivityClass);
}
@Override
protected void setUp() throws Exception
{
// Load config file from sdcard (setup by python script)
String configFile = FennecNativeDriver.getFile("/mnt/sdcard/robotium.config");
HashMap config = FennecNativeDriver.convertTextToTable(configFile);
// Create the intent to be used with all the important arguments.
Intent i = new Intent(Intent.ACTION_MAIN);
String argsList = "-no-remote -profile " + (String)config.get("profile");
i.putExtra("args", argsList);
//Start the activity
setActivityIntent(i);
activity = getActivity();
//Set up Robotium.solo and Driver objects
solo = new Solo(getInstrumentation(), getActivity());
driver = new FennecNativeDriver(activity, solo);
actions = new FennecNativeActions(activity, solo, getInstrumentation());
driver.setLogFile((String)config.get("logfile"));
}
public void testAwesomebar() {
// TODO: find a better way to not hardcode this url
String url = "http://mochi.test:8888/tests/robocop/robocop.html";
Element awesomebar = driver.findElement("awesome_bar");
awesomebar.click();
Element urlbar = driver.findElement("awesomebar_text");
actions.sendKeys(url);
driver.is(url, urlbar.getText(), "Awesomebar URL Typed Properly");
//could also use: urlbar.clickSpecialKey(Element.SpecialKey.ENTER)
actions.sendKeys("\n");
//wait for screen to load
actions.waitForGeckoEvent("DOMContentLoaded");
driver.setupScrollHandling();
//Calculate where we should be dragging.
int midX = driver.getGeckoLeft() + driver.getGeckoWidth()/2;
int midY = driver.getGeckoTop() + driver.getGeckoHeight()/2;
int endY = driver.getGeckoTop() + driver.getGeckoHeight()/10;
for(int i = 0; i < 10; i++) {
actions.drag(midX,midX,midY,endY);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//Click the awesomebar again
awesomebar.click();
driver.is(url, urlbar.getText(), "Aweosmebar URL stayed the same");
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
}catch (Throwable e){
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}

Просмотреть файл

@ -0,0 +1,109 @@
#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import com.jayway.android.robotium.solo.Solo;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import android.test.PerformanceTestCase;
import android.util.Log;
import android.widget.Button;
import android.content.Intent;
import java.util.HashMap;
@SuppressWarnings("unused")
public class testBookmark extends ActivityInstrumentationTestCase2 {
@SuppressWarnings("unchecked")
public testBookmark(Class activityClass) {
super(activityClass);
// TODO Auto-generated constructor stub
}
private static final String TARGET_PACKAGE_ID = "org.mozilla.gecko";
private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME="@ANDROID_PACKAGE_NAME@.App";
private Solo solo;
private Activity activity;
private Driver driver;
private Actions actions;
private static Class<?> launcherActivityClass;
static{
try{
launcherActivityClass = Class.forName(LAUNCH_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e){
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public testBookmark() throws ClassNotFoundException {
super(TARGET_PACKAGE_ID, launcherActivityClass);
}
@Override
protected void setUp() throws Exception
{
//Load config file
String configFile = FennecNativeDriver.getFile("/mnt/sdcard/robotium.config");
HashMap config = FennecNativeDriver.convertTextToTable(configFile);
//Create the intent to be used with all the important arguments
Intent i = new Intent(Intent.ACTION_MAIN);
String argsList = "-no-remote -profile " + (String)config.get("profile");
i.putExtra("args", argsList);
//Start the activity
setActivityIntent(i);
activity = getActivity();
//Set up Robotium.solo and Driver objects
solo = new Solo(getInstrumentation(), getActivity());
driver = new FennecNativeDriver(activity, solo);
actions = new FennecNativeActions(activity, solo, getInstrumentation());
driver.setLogFile((String)config.get("logfile"));
}
public void testBookmark(){
// TODO: find a better way to not hardcode this url
String url = "http://mochi.test:8888/tests/robocop/robocop.html";
Element awesomebar = driver.findElement("awesome_bar");
awesomebar.click();
Element urlbar = driver.findElement("awesomebar_text");
actions.sendKeys(url);
driver.is(url, urlbar.getText(), "Awesomebar url typed properly");
//Click the top item in the list.
actions.sendSpecialKey(Actions.SpecialKey.DOWN);
actions.sendSpecialKey(Actions.SpecialKey.ENTER);
actions.waitForGeckoEvent("DOMContentLoaded");
awesomebar.click();
driver.is(url, urlbar.getText(),"Awesomebar URL still on");
//Click the Top item in the history list.
actions.sendSpecialKey(Actions.SpecialKey.RIGHT);
actions.sendSpecialKey(Actions.SpecialKey.RIGHT);
actions.sendSpecialKey(Actions.SpecialKey.DOWN);
actions.sendSpecialKey(Actions.SpecialKey.DOWN);
actions.sendSpecialKey(Actions.SpecialKey.ENTER);
actions.waitForGeckoEvent("DOMContentLoaded");
awesomebar.click();
//Unfortunately, the item isn't constant so can't be tested.
//driver.is(url, urlbar.getText(),"Shouldn't this be the last url in the history?");
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
}catch (Throwable e){
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}

Просмотреть файл

@ -0,0 +1,96 @@
#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import com.jayway.android.robotium.solo.Solo;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import android.test.PerformanceTestCase;
import android.util.Log;
import android.widget.Button;
import android.content.Intent;
import java.util.HashMap;
@SuppressWarnings("unused")
public class testLoad extends ActivityInstrumentationTestCase2 {
@SuppressWarnings("unchecked")
public testLoad(Class activityClass) {
super(activityClass);
// TODO Auto-generated constructor stub
}
private static final String TARGET_PACKAGE_ID = "org.mozilla.gecko";
private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME="@ANDROID_PACKAGE_NAME@.App";
private Solo solo;
private Activity activity;
private Driver driver;
private Actions actions;
private static Class<?> launcherActivityClass;
static{
try{
launcherActivityClass = Class.forName(LAUNCH_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e){
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public testLoad() throws ClassNotFoundException {
super(TARGET_PACKAGE_ID, launcherActivityClass);
}
@Override
protected void setUp() throws Exception
{
//Load config file
String configFile = FennecNativeDriver.getFile("/mnt/sdcard/robotium.config");
HashMap config = FennecNativeDriver.convertTextToTable(configFile);
//Create the intent to be used with all the important arguments
Intent i = new Intent(Intent.ACTION_MAIN);
String argsList = "-no-remote -profile " + (String)config.get("profile");
i.putExtra("args", argsList);
//Start the activity
setActivityIntent(i);
activity = getActivity();
//Set up Robotium.solo and Driver objects
solo = new Solo(getInstrumentation(), getActivity());
driver = new FennecNativeDriver(activity, solo);
actions = new FennecNativeActions(activity, solo, getInstrumentation());
driver.setLogFile((String)config.get("logfile"));
}
public void testLoad(){
// TODO: find a better way to not hardcode this url
String url = "http://mochi.test:8888/tests/robocop/robocop.html";
Element awesomebar = driver.findElement("awesome_bar");
awesomebar.click();
Element urlbar = driver.findElement("awesomebar_text");
actions.sendKeys(url);
driver.is(url, urlbar.getText(),"Awesomebar URL Correct");
//Select top item in the list.
actions.sendSpecialKey(Actions.SpecialKey.DOWN);
actions.sendKeys("\n");
actions.waitForGeckoEvent("DOMContentLoaded");
awesomebar.click();
driver.is(url, urlbar.getText(), "Awesomebar URL is still correct");
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
}catch (Throwable e){
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}

Просмотреть файл

@ -0,0 +1,111 @@
#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import com.jayway.android.robotium.solo.Solo;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import android.test.PerformanceTestCase;
import android.util.Log;
import android.widget.Button;
import android.content.Intent;
import java.util.HashMap;
@SuppressWarnings("unused")
public class testNewTab extends ActivityInstrumentationTestCase2 {
@SuppressWarnings("unchecked")
public testNewTab(Class activityClass) {
super(activityClass);
// TODO Auto-generated constructor stub
}
private static final String TARGET_PACKAGE_ID = "org.mozilla.gecko";
private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME="@ANDROID_PACKAGE_NAME@.App";
private Solo solo;
private Activity activity;
private Actions actions;
private Driver driver;
private static Class<?> launcherActivityClass;
static{
try{
launcherActivityClass = Class.forName(LAUNCH_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e){
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public testNewTab() throws ClassNotFoundException {
super(TARGET_PACKAGE_ID, launcherActivityClass);
}
@Override
protected void setUp() throws Exception
{
// Load config file from sdcard (setup by python script)
String configFile = FennecNativeDriver.getFile("/mnt/sdcard/robotium.config");
HashMap config = FennecNativeDriver.convertTextToTable(configFile);
// Create the intent to be used with all the important arguments.
Intent i = new Intent(Intent.ACTION_MAIN);
String argsList = "-no-remote -profile " + (String)config.get("profile");
i.putExtra("args", argsList);
//Start the activity
setActivityIntent(i);
activity = getActivity();
//Set up Robotium.solo and Driver objects
solo = new Solo(getInstrumentation(), getActivity());
driver = new FennecNativeDriver(activity, solo);
actions = new FennecNativeActions(activity, solo, getInstrumentation());
driver.setLogFile((String)config.get("logfile"));
}
public void testNewTab(){
// TODO: find a better way to not hardcode this url
String url = "http://mochi.test:8888/tests/robocop/robocop.html";
Element tabs = driver.findElement("tabs");
//Add one tab
tabs.click();
Element urlbar = driver.findElement("awesomebar_text");
actions.sendKeys(url);
driver.is(url, urlbar.getText(),"Awesomebar url is fine");
actions.sendSpecialKey(Actions.SpecialKey.ENTER);
actions.waitForGeckoEvent("DOMContentLoaded");
try{Thread.sleep(5000);}catch(Throwable e){};
//See tab count
Element tabCount = driver.findElement("tabs_count");
driver.is("2", tabCount.getText(),"Number of tabs has increased");
//Click tab list
tabs.click();
Element addTab = driver.findElement("add_tab");
//Add another tab
addTab.click();
actions.sendKeys(url);
driver.is(url, urlbar.getText(),"URL is still fine");
actions.sendSpecialKey(Actions.SpecialKey.ENTER);
actions.waitForGeckoEvent("DOMContentLoaded");
//Check tab count another time.
driver.is("3", tabCount.getText(),"Number of tabs has increased");
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
}catch (Throwable e){
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}

Просмотреть файл

@ -0,0 +1,120 @@
#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import com.jayway.android.robotium.solo.Solo;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import android.test.PerformanceTestCase;
import android.util.Log;
import android.widget.Button;
import android.content.Intent;
import java.util.HashMap;
import java.util.List;
@SuppressWarnings("unused")
public class testPan extends ActivityInstrumentationTestCase2 {
@SuppressWarnings("unchecked")
public testPan(Class activityClass) {
super(activityClass);
// TODO Auto-generated constructor stub
}
private static final String TARGET_PACKAGE_ID = "org.mozilla.gecko";
private static final String LAUNCH_ACTIVITY_FULL_CLASSNAME="@ANDROID_PACKAGE_NAME@.App";
private Solo solo;
private Activity activity;
private Driver driver;
private Actions actions;
private static Class<?> launcherActivityClass;
static{
try{
launcherActivityClass = Class.forName(LAUNCH_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e){
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public testPan() throws ClassNotFoundException {
super(TARGET_PACKAGE_ID, launcherActivityClass);
}
@Override
protected void setUp() throws Exception
{
// Load config file from sdcard (setup by python script)
String configFile = FennecNativeDriver.getFile("/mnt/sdcard/robotium.config");
HashMap config = FennecNativeDriver.convertTextToTable(configFile);
// Create the intent to be used with all the important arguments.
Intent i = new Intent(Intent.ACTION_MAIN);
String argsList = "-no-remote -profile " + (String)config.get("profile");
i.putExtra("args", argsList);
//Start the activity
setActivityIntent(i);
activity = getActivity();
//Set up Robotium.solo and Driver objects
solo = new Solo(getInstrumentation(), getActivity());
driver = new FennecNativeDriver(activity, solo);
actions = new FennecNativeActions(activity, solo, getInstrumentation());
driver.setLogFile((String)config.get("logfile"));
}
public void testPan() {
// TODO: find a better way to not hardcode this url
String url = "http://mochi.test:8888/tests/robocop/robocop.html";
Element awesomebar = driver.findElement("awesome_bar");
awesomebar.click();
Element urlbar = driver.findElement("awesomebar_text");
actions.sendKeys(url);
driver.is(url, urlbar.getText(),"Asserting Awesomebar typing works");
actions.sendSpecialKey(Actions.SpecialKey.ENTER);
actions.waitForGeckoEvent("DOMContentLoaded");
driver.setupScrollHandling();
// Setup scrolling coordinates.
int midX = driver.getGeckoLeft() + driver.getGeckoWidth()/2;
int midY = driver.getGeckoTop() + driver.getGeckoHeight()/2;
int endY = driver.getGeckoTop() + driver.getGeckoHeight()/10;
driver.startFrameRecording();
int i = 0;
// Scroll a thousand times or until the end of the page.
do {
actions.drag(midX, midX, midY, endY);
try {
Thread.sleep(200);
}
catch (InterruptedException e) {
e.printStackTrace();
}
i++;
} while( i < 1000 && driver.getScrollHeight() + 2*driver.getHeight() < driver.getPageHeight() );
driver.ok(i < 1000, "Less than 1000", "Should take less than 1000 drags to get to bottom of the page.");
int frames = driver.stopFrameRecording();
driver.dumpLog("__start_report" + Integer.toString(frames) + "__end_report");
Long msecs = System.currentTimeMillis();
driver.dumpLog("__startTimestamp" + msecs.toString() + "__endTimestamp");
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
}catch (Throwable e){
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}