Android自动化测试之Robotium<二>:用例分析(2)

发表于:2012-08-28来源:Csdn作者:wirelessqa点击数: 标签:Android
assertTrue(solo.waitForText(Item 9 clicked!)); solo.clickOnButton(OK); assertTrue(solo.waitForText(Botton OK in dialog with list is pressed!)); } public void testSetScreen() { solo.setActivityOrientat

  assertTrue(solo.waitForText("Item 9 clicked!"));

  solo.clickOnButton("OK");

  assertTrue(solo.waitForText("Botton OK in dialog with list is pressed!"));

  }

  public void testSetScreen() {

  solo.setActivityOrientation( Solo.LANDSCAPE);

  solo.setActivityOrientation(Solo.PORTRAIT);

  solo.sleep(2000);

  }

  public void testGetStringById(){

  solo.clickOnButton("ScrollView");

  assertTrue(solo.getString(R.string.scroll_text).toString().contains("道可道"));

  }

  public void testRequestFocus(){

  //好像没有直接获得焦点的方法,所以。。慢慢移动吧

  }

  public void testSlide(){

  //gallery的操作方法没有

  //左右滑动用 solo.scrollToSide(Solo.LEFT);

  }

  public void testGetChildCount(){

  Log.i(TAG, String.valueOf(solo.getViews().size())); //所有的VIEW数量

  Log.i(TAG, String.valueOf(solo.getViews(solo.getView(R.id.mainroot)).size()));//LinearLayout下的VIEW数量

  Log.i(TAG, String.valueOf(solo.getViews(solo.getView(R.id.my_gallery)).size()));//GALLERY下的VIEW数量

  }

  }

  GridView

  [java] view plaincopypackage org.onceler.robotium.test;

  import org.athrun.android.app.GridViewActivity;

  import org.athrun.android.app.ListViewActivity;

  import android.test.ActivityInstrumentationTestCase2;

  import com.jayway.android.robotium.solo.Solo;

  public class GridViewActivityTest extends ActivityInstrumentationTestCase2{

  private Solo solo;

  private static final String TAG = "robotium_test";

  public GridViewActivityTest() {

  super("org.athrun.android.app", GridViewActivity.class);

  }

  public void setUp() throws Exception {

  solo = new Solo(getInstrumentation(), getActivity());

  }

  @Override

  public void tearDown() throws Exception {

  //Robotium will finish all the activities that have been opened

  solo.finishOpenedActivities();

  }

  public void testGetChildByIndex(){

  // solo.clickOnText("Item.0");

  solo.clickOnImage(0);

  assertTrue(solo.waitForText("Item 0 is clicked!"));

  solo.assertCurrentActivity("current activity is not ListViewActivity", ListViewActivity.class);

  }

  public void testGetChildByIndexMixed(){

  solo.clickOnText("Item.19");

  assertTrue(solo.waitForText("Item 19 is clicked!"));

  solo.sleep(1000);

  //接下来没有办法直接获得哪一行的TEXT,ATHRUN就可以

  //所以只能通过INDEX来查找

  solo.getText(40); //这个有问题,被测应用的问题

  //移动到第20行可以像下面这样OH MY GOD,好慢

  // for(int i = 0;i<21;i++){

  // solo.sendKey(Solo.DOWN);

  // }

  }

  }

原文转自:http://www.ltesting.net