转载地址:http://blog.csdn.net/gzh0222/article/details/7029981
package com.xgd.activity.test;
import com.jayway.android.robotium.solo.Solo;
import com.xgd.activity.PhoneActivity;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.Smoke;
public class uitest extends ActivityInstrumentationTestCase2< PhoneActivity >{
private Solo solo;
public uitest() {
super("com.xgd.activity",PhoneActivity.class);
// TODO Auto-generated constructor stub
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
//该方法用来初始化solo,绑定对应的Activity。
}
@Smoke
public void testaddphonenum() throws Exception {
solo.enterText(0, "1234");
boolean expected = true;
boolean acture=solo.searchText("1234");
assertEquals("输入不正确",expected,acture);
}
public void testelphonenum() throws Exception{
String appName = solo.getCurrentActivity().getClass().getSimpleName();//获取当前的测试app的名称
System.out.println(appName);
solo.getButton(0).getClass().getSimpleName();
solo.assertCurrentActivity("Expected login activity", appName);
System.out.println(solo.getButton(0).getText());//获取第一个Button的名称
solo.clickOnButton("拨号");
}
@Override
public void tearDown() throws Exception {
try {
//Robotium will finish all the activities that have been opened
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}