As a technical tester without any deeper understanding of java I have a question regarding robotium and the ActivityInstrumentationTestCase2. I have manged to create a test case using eclipse and robotium. It works and I can execute it as a junit test as well as from the command line on a real device.
I now want to move this robotium/solo testcase into our existing test framework where each class/tescase is extended by "abstractchecker". Below is an example of one of our web test cases
package ipoMonitor.checkers;
import ipoMonitor.CheckInfo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import java.sql.Connection;
import static org.junit.Assert.assertTrue;
public class EmConsoleChecker extends AbstractChecker {
public EmConsoleChecker(CheckInfo curCheck, Connection con, WebDriver driver) {
super(curCheck, con, driver);
}
@Override
public void runCheck() {
curCheck.subCheckName = "Homepage";
driver.get(curCheck.baseUrl);
assertTrue(driver.findElement(By.cssSelector("BODY")).getText()
.matches("^[\\s\\S]*Login[\\s\\S]*$"));
WriteLog(curCheck, con, " OK");
}
}
Is it somehow possible to keep this standard and have a robotium test class running as a method instead of a class? If so how would the code look like?
My robotium testcase that was originally recorded with extsolo looks like this
public class Test extends ActivityInstrumentationTestCase2<Activity> {
final String[] proj = {"*"};
private static final String LAUNCHER_ACTIVITY_CLASSNAME = "com.somecompany.androidsmsapp.MainActivity";
private static Class<?> launchActivityClass;
static {
try {
launchActivityClass = Class.forName(LAUNCHER_ACTIVITY_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
private Solo solo;
@SuppressWarnings("unchecked")
public Test() {
super((Class<Activity>) launchActivityClass);
}
@Override
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
super.tearDown();
}
public void testRecorded() throws Exception {
try {
Log.i("assert", "---------------NEW RUN-------------------");
Log.i("assert", "Starting SendSMS");
solo.waitForActivity("MainActivity");
// Loads of solo commands executed here
.....
.....
} catch (AssertionFailedError e) {
throw e;
} catch (Exception e) {
throw e;
}
}
}
I have noticed that when you create a robotium test case in eclipse, there are libraries and classpath containers added automatically. Does anyone have a working example that they can share or a link to one? I have searched the net for a looooooooong time without finding any solution to this. Any help is appreciated.
Best Regards, Mattias