简体   繁体   中英

Running different test scripts in same file using Robotium Recorder

I am using Robotium Recorder for android whitebox testing. I have two test codes which runs properly if I place it in two different files. But If I place the same test codes in same file in different function then only the first method (test1) runs and test2 become fails.

package com.samsung.mdl.radio.test;

import com.samsung.mdl.radio.MainActivity;
import com.robotium.solo.*;

import android.test.ActivityInstrumentationTestCase2;

public class AddToMyStationsTest extends
        ActivityInstrumentationTestCase2<MainActivity> {

    private Solo solo;

    public AddToMyStationsTest() {
        super(MainActivity.class);
        // TODO Auto-generated constructor stub
    }


protected void setUp() throws Exception {
    super.setUp();
    solo = new Solo(getInstrumentation());
    getActivity();

}

@Override
public void tearDown() throws Exception {
    solo.finishOpenedActivities();
    super.tearDown();
}


public void test1() throws Exception {
    solo.waitForActivity(com.samsung.mdl.radio.MainActivity.class, 2000);
    assertTrue("com.samsung.mdl.radio.SplashActivity is not found!", solo.waitForActivity(com.samsung.mdl.radio.SplashActivity.class));
    solo.clickOnView(solo.getView(com.samsung.mdl.radio.R.id.dialog_positive_button));
    Timeout.setSmallTimeout(17313);
    solo.sleep(6000);
    // Click on ImageView
    solo.clickOnView(solo.getView(com.samsung.mdl.radio.R.id.options_button));
    // Click on Never Play Song
    solo.clickOnView(solo.getView(com.samsung.mdl.radio.R.id.element_text, 1));
    // Click on Undo
    solo.clickOnView(solo.getView(com.samsung.mdl.radio.R.id.undo_button));

}


public void test2() throws Exception {
    solo.waitForActivity(com.samsung.mdl.radio.MainActivity.class, 2000);
    assertTrue("com.samsung.mdl.radio.SplashActivity is not found!", solo.waitForActivity(com.samsung.mdl.radio.SplashActivity.class));
    solo.clickOnView(solo.getView(com.samsung.mdl.radio.R.id.dialog_positive_button));
    Timeout.setSmallTimeout(17313);
    solo.sleep(6000);
    solo.clickOnView(solo.getView(com.samsung.mdl.radio.R.id.options_button));
    solo.clickOnView(solo.getView(com.samsung.mdl.radio.R.id.element_text, 2));
}
}

So what can I do now. Am I doing anything wrong.? Is it possible ?

You should keep the tearDown() method. From the tearDown() robotium.finishOpenedActivities() is run which will close all the activities before the next test case begins. Also you should keep setUp() with only the three first lines.

The easiest you can do is to keep the first test class (first generated file) and then copy in the testRun() from the other files and just rename them. In that case you will keep the correct setUp() and tearDown() that are needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM