| | 148 | |
| | 149 | |
| | 150 | == 是用uiautomator 测试 == |
| | 151 | |
| | 152 | http://developer.android.com/tools/testing/testing_ui.html [[BR]] |
| | 153 | |
| | 154 | 先用自带工具 uiautomatorviewer 看页面元素,再写程序 [[BR]] |
| | 155 | |
| | 156 | 代码如 |
| | 157 | |
| | 158 | {{{ |
| | 159 | |
| | 160 | getUiDevice().pressHome(); |
| | 161 | |
| | 162 | UiObject allAppsButton = new UiObject(new UiSelector() |
| | 163 | .description("Apps")); |
| | 164 | |
| | 165 | allAppsButton.clickAndWaitForNewWindow(); |
| | 166 | |
| | 167 | UiObject appsTab = new UiObject(new UiSelector() |
| | 168 | .text("Apps")); |
| | 169 | |
| | 170 | appsTab.click(); |
| | 171 | |
| | 172 | UiScrollable appViews = new UiScrollable(new UiSelector() |
| | 173 | .scrollable(true)); |
| | 174 | |
| | 175 | appViews.setAsHorizontalList(); |
| | 176 | |
| | 177 | UiObject settingsApp = appViews.getChildByText(new UiSelector() |
| | 178 | .className(android.widget.TextView.class.getName()), |
| | 179 | "Settings"); |
| | 180 | settingsApp.clickAndWaitForNewWindow(); |
| | 181 | |
| | 182 | UiObject settingsValidation = new UiObject(new UiSelector() |
| | 183 | .packageName("com.android.settings")); |
| | 184 | assertTrue("Unable to detect Settings", |
| | 185 | settingsValidation.exists()); |
| | 186 | }}} |
| | 187 | |