robotium 方法学习实例

package com.calculator.andyguo.test;
import com.jayway.android.robotium.solo.Solo;
import com.calculator.andyguo.Calculator;


import android.test.ActivityInstrumentationTestCase2;


public class CalculatorTest extends ActivityInstrumentationTestCase2<Calculator> {

private Solo solo; //声明一下Solo
public CalculatorTest() { //告诉程序要测试的包和类名
super("com.calculator.andyguo",Calculator.class);
}

public void setUp() throws Exception {//初始化被测程序
solo = new Solo(getInstrumentation(), getActivity());
}


public void testclick() throws Exception{

//solo.clickLongInList( 0, 1, 10000);
//solo.clickOnText("a", 1);
// solo.enterText(1,"text");
// solo.enterText(0,"text");

//solo.clearEditText(0);
// solo.sleep(10000);

// solo.scrollDownList(0);
//solo.scrollUpList(0);

/* System.out.println(solo.getCurrentActivity().getLocalClassName().toString());
System.out.println(solo.getButton(0).getText());

solo.sendKey(solo.DOWN);
solo.sendKey(solo.DOWN);
solo.sendKey(solo.DOWN);
solo.sendKey(solo.DOWN);
solo.sendKey(solo.DOWN);
solo.sendKey(solo.DOWN);

solo.sleep(10000);*/
solo.clickOnButton("取消");//关闭dialog

// solo.sleep(5000);
//System.out.println(solo.waitForDialogToClose((long)10000)); //返回false?

System.out.println(solo.waitForText("k",1, 10000, true));


System.out.println(solo.waitForActivity("Calculator", 10000));

System.out.println("查找结果"+solo.searchText("c",3,true));

System.out.println(solo.getCurrentButtons().get(0).getId());


solo.sleep(10000);
//solo.clickLongOnScreen(100,123, 12330);


}

public void tearDown() throws Exception { //关闭solo
try {
solo.finalize(); //执行清理工作
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();//测试结束,关闭应用程序
super.tearDown();
}
}

你可能感兴趣的:(robot)