---
title: "Android 自动化测试—robotium（五）Spinner控件"
author: "284772894"
date: "2014-12-25T09:31:49Z"
tags: []
categories: ["研发管理"]
slug: "android-robotium-spinner"
draft: false
lastmod: "2014-12-25T09:31:48Z"
id: 2167199
url: "https://284772894.iteye.com/blog/2167199"
---

spinne控件：

![](http://dl2.iteye.com/upload/attachment/0104/4542/b819e7d4-182f-3bc7-a158-e9b7a8f2b152.png)  
 

 

默认显示：【选择的是:北京】

操作步骤：

1.点击【城市】下拉框

2.选择【上海】

验证：TextView 显示：【选择的是:上海】

 

01. public void testUI() throws Exception {
02. this.Spinner();
03. }
04. public void Spinner(){
05. solo.clickOnButton("Spinner");
06. boolean actual = solo.isSpinnerTextSelected(0,"北京");
07. solo.pressSpinnerItem(0, 1);
08. boolean actual1 = solo.searchText("选择的是:上海");
09. assertEquals("This is not found",true, actual1);
10. }

 

isSpinnerTextSelected 拥有两个参数

public boolean isSpinnerTextSelected(int index, String text)

index:定位选择的Spinner,第一个为0

text:所选择的Spinner存在的文本

这个API返回的是一个布尔值，当满足条件时返回true

 

pressSpinnerItem 拥有两个参数

public void pressSpinnerItem(int spinnerIndex, int itemIndex)

spinnerIndex:定位要使用的Spinner,第一个为0

intemIndex:定位所要按下的下拉项，如图：北京=0 上海=1 天津=2 ....

 

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

本文出自 “[小毛子](http://xiaomaozi.blog.51cto.com/)” 博客，请务必保留此出处[http://xiaomaozi.blog.51cto.com/925779/917287](http://xiaomaozi.blog.51cto.com/925779/917287)