Question

The app I'm testing displays an info screen the first time it's launched after installation with a "Continue" button to dismiss. I'd like to compose tests that will run for either the first launch (i.e., when runs as JUnit from APK) or subsequent launches (i.e., as straight JUnit). I'm trying to use the simplest conditional I could think of, such as...

if (solo.waitForText("Continue", 20000)) {
solo.clickOnButton("Continue");
}

next step....

The tests will pass if the "Continue" button is there (from APK test run) but fails (according to ADK at the clickOnButton) when the button is not there (straight JUnit run). What am I doing wrong?

2/21/14

Maybe I should start over.

The app I'm testing displays an info screen the first time it's launched after installation with a "Continue" button to dismiss. This screen is not displayed in subsequent launches of the app. I'd like to compose tests that will run for either the first launch (i.e., when runs as JUnit from APK) or subsequent launches (i.e., as straight JUnit). I started this test by recording the action using Testdroid, which opens the test like this:

    public void testRecorded() throws Exception {
    try {
        solo.waitForActivity("splash");
        solo.waitForActivity("Login");

        assertTrue(
            "Wait for text (id: com.<app identified>.R.id.continue_txt) failed.",
            solo.waitForTextById(
                    "com.<app identified>.R.id.continue_txt", 20000));
        solo.clickOnText((TextView) solo
            .findViewById("com.<app identified>.R.id.continue_txt"));

This works as long as the app is reinstalled before the test is run (run from APK) but, obviously, fails on subsequent launches (run as straight JUnit) because the screen never shows up. I tried to enclose the waitForTextById and clickOnText statements in an "if" conditional and it didn't work, so I tried to simplify to

if (solo.waitForText("Continue", 20000)) {
solo.clickOnButton("Continue");}

and then tried

if (solo.searchText("Continue")) {
solo.clickOnButton("Continue");}

Neither of these worked, either. According to Eclipse, the test fails when it's can't click on the button (because the button isn't there). My knowledge of Java is rudimentary at best. What am I not understanding here?

Was it helpful?

Solution 2

I finally figured out what the problem was. Once I put the whole assertTrue statement within the if conditional instead of just the solo.waitForTextById, it started to work as I wanted. This problem was due to my limited experience with Java.

Thanks everyone who read this for you help.

OTHER TIPS

Try this:

if (solo.searchText("Continue")) {
solo.clickOnButton("Continue");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top