Android automated testing - robotium (5) Spinner control

spinne controls:



 

 

Default display: [Selected is: Beijing]

Steps:

1. Click the [City] drop-down box

2. Select【Shanghai】

Verification: TextView Display: [Selected is: Shanghai]

 

  1. publicvoid testUI() throws Exception {  
  2.        this.Spinner(); 
  3.  
  4. publicvoid Spinner(){  
  5.     solo.clickOnButton("Spinner"); 
  6.     boolean actual = solo.isSpinnerTextSelected(0,"北京"); 
  7.  
  8.     solo.pressSpinnerItem(01); 
  9.     boolean  actual1 = solo.searchText( "Selected is: Shanghai" ); 
  10.     assertEquals("This is not found",true, actual1); 

 

isSpinnerTextSelected has two parameters

public boolean isSpinnerTextSelected(int index, String text)

index: locate the selected Spinner, the first one is 0

text: the text that exists for the selected Spinner

What this API returns is a boolean value that returns true when the condition is met

 

pressSpinnerItem has two parameters

public void pressSpinnerItem(int spinnerIndex, int itemIndex)

spinnerIndex: locate the Spinner to be used, the first one is 0

intemIndex: locate the drop-down item to be pressed, as shown in the figure: Beijing=0 Shanghai=1 Tianjin=2 ....

 

Spinner implementation: http://luwenjie.blog.51cto.com/925779/917238

This article is from the " Xiao Maozi " blog, please be sure to keep this source http://xiaomaozi.blog.51cto.com/925779/917287

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326395672&siteId=291194637