本文整理匯總了Java中android.support.test.uiautomator.UiObject.click方法的典型用法代碼示例。如果您正苦於以下問題:Java UiObject.click方法的具體用法?Java UiObject.click怎麽用?Java UiObject.click使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.test.uiautomator.UiObject
的用法示例。
在下文中一共展示了UiObject.click方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: allowPermissionsIfNeeded
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
public static void allowPermissionsIfNeeded(String permissionNeeded) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasNeededPermission(permissionNeeded)) {
sleep(PERMISSIONS_DIALOG_DELAY);
UiDevice device = UiDevice.getInstance(getInstrumentation());
UiObject allowPermissions = device.findObject(new UiSelector()
.clickable(true)
.checkable(false)
.index(GRANT_BUTTON_INDEX));
if (allowPermissions.exists()) {
allowPermissions.click();
}
}
} catch (UiObjectNotFoundException e) {
System.out.println("There is no permissions dialog to interact with");
}
}
示例2: shareTest
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void shareTest() throws InterruptedException, UiObjectNotFoundException {
UiObject shareBtn = TestHelper.mDevice.findObject(new UiSelector()
.resourceId("org.mozilla.focus.debug:id/share")
.enabled(true));
/* Go to a webpage */
TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
TestHelper.inlineAutocompleteEditText.clearTextField();
TestHelper.inlineAutocompleteEditText.setText("mozilla");
TestHelper.hint.waitForExists(waitingTime);
TestHelper.pressEnterKey();
assertTrue(TestHelper.webView.waitForExists(waitingTime));
/* Select share */
TestHelper.menuButton.perform(click());
shareBtn.waitForExists(waitingTime);
shareBtn.click();
// For simulators, where apps are not installed, it'll take to message app
TestHelper.shareMenuHeader.waitForExists(waitingTime);
assertTrue(TestHelper.shareMenuHeader.exists());
assertTrue(TestHelper.shareAppList.exists());
TestHelper.pressBackKey();
}
示例3: testChangeText_sameActivity
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void testChangeText_sameActivity() {
UiObject skipButton = mDevice.findObject(new UiSelector()
.text("SKIP").className("android.widget.TextView"));
// Simulate a user-click on the OK button, if found.
try {
if (skipButton.exists() && skipButton.isEnabled()) {
skipButton.click();
}
} catch (UiObjectNotFoundException e) {
e.printStackTrace();
}
}
示例4: testUiAutomatorAPI
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Ignore
@Test
public void testUiAutomatorAPI() throws UiObjectNotFoundException, InterruptedException {
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiSelector editTextSelector = new UiSelector().className("android.widget.EditText").text("this is a test").focusable(true);
UiObject editTextWidget = device.findObject(editTextSelector);
editTextWidget.setText("this is new text");
Thread.sleep(2000);
UiSelector buttonSelector = new UiSelector().className("android.widget.Button").text("CLICK ME").clickable(true);
UiObject buttonWidget = device.findObject(buttonSelector);
buttonWidget.click();
Thread.sleep(2000);
}
示例5: testA
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* 測試CollapsingToolbarLayout
* 被測Demo下載地址:https://github.com/alidili/DesignSupportDemo
*
* @throws UiObjectNotFoundException
*/
public void testA() throws UiObjectNotFoundException {
// 獲取設備對象
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
UiDevice uiDevice = UiDevice.getInstance(instrumentation);
// 獲取上下文
Context context = instrumentation.getContext();
// 啟動測試App
Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.yang.designsupportdemo");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
// 打開CollapsingToolbarLayout
String resourceId = "com.yang.designsupportdemo:id/CollapsingToolbarLayout";
UiObject collapsingToolbarLayout = uiDevice.findObject(new UiSelector().resourceId(resourceId));
collapsingToolbarLayout.click();
for (int i = 0; i < 5; i++) {
// 向上移動
uiDevice.swipe(uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight(),
uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight() / 2, 10);
// 向下移動
uiDevice.swipe(uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight() / 2,
uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight(), 10);
}
// 點擊應用返回按鈕
UiObject back = uiDevice.findObject(new UiSelector().description("Navigate up"));
back.click();
// 點擊設備返回按鈕
uiDevice.pressBack();
}
示例6: testB
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* 滑動界麵,打開About phone選項
* 測試環境為標準Android 7.1.1版本,不同設備控件查找方式會有不同
*
* @throws UiObjectNotFoundException
*/
public void testB() throws UiObjectNotFoundException {
// 獲取設備對象
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
UiDevice uiDevice = UiDevice.getInstance(instrumentation);
// 獲取上下文
Context context = instrumentation.getContext();
// 點擊Settings按鈕
UiObject uiObject = uiDevice.findObject(new UiSelector().description("Settings"));
uiObject.click();
// 滑動列表到最後,點擊About phone選項
UiScrollable settings = new UiScrollable(new UiSelector().className("android.support.v7.widget.RecyclerView"));
UiObject about = settings.getChildByText(new UiSelector().className("android.widget.LinearLayout"), "About phone");
about.click();
// 點擊設備返回按鈕
uiDevice.pressBack();
uiDevice.pressBack();
}
示例7: mainActivity_changeGridSize
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void mainActivity_changeGridSize() throws Exception {
UiScrollable recycleView = new UiScrollable(new UiSelector().resourceId("com.fantasyfang.googletrendapp:id/trendRecycleView")
.className(RecyclerView.class));//recycleView.click();
UiObject item = recycleView.getChild(new UiSelector().resourceId("com.fantasyfang.googletrendapp:id/googleTrendView"));
item.click();
String gridDescription = InstrumentationRegistry.getInstrumentation().getTargetContext().getString(R.string.choose_grid);
UiObject grid = mDevice.findObject(new UiSelector().descriptionContains(gridDescription));
grid.click();
UiObject gridList = mDevice.findObject(new UiSelector().text("2*2"));
gridList.click();
mDevice.waitForIdle();
takeScreenShot("Change_grid_to_2_2.jpg");
mDevice.pressHome();
takeScreenShot("Home.jpg");
}
示例8: takeScreenshotsOfOpenWithAndShare
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
private void takeScreenshotsOfOpenWithAndShare() throws Exception {
/* Open_With View */
UiObject openWithBtn = device.findObject(new UiSelector()
.resourceId("org.mozilla.focus.debug:id/open_select_browser")
.enabled(true));
assertTrue(openWithBtn.waitForExists(waitingTime));
openWithBtn.click();
UiObject shareList = device.findObject(new UiSelector()
.resourceId("org.mozilla.focus.debug:id/apps")
.enabled(true));
assertTrue(shareList.waitForExists(waitingTime));
Screengrab.screenshot("OpenWith_Dialog");
/* Share View */
UiObject shareBtn = device.findObject(new UiSelector()
.resourceId("org.mozilla.focus.debug:id/share")
.enabled(true));
device.pressBack();
TestHelper.menuButton.perform(click());
assertTrue(shareBtn.waitForExists(waitingTime));
shareBtn.click();
TestHelper.shareAppList.waitForExists(waitingTime);
Screengrab.screenshot("Share_Dialog");
device.pressBack();
}
示例9: checkScreenShotsPermission
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
public static void checkScreenShotsPermission() {
Context appContext = InstrumentationRegistry.getTargetContext();
Brickator.print("app package is: " + appContext.getApplicationContext().getPackageName());
int permission = ContextCompat.checkSelfPermission(appContext, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission == PackageManager.PERMISSION_DENIED) {
Brickator.getInstance().goToStateSimple(PermissionState.class);
UiObject allowButton = PermissionState.getAllowButton();
try {
allowButton.click();
} catch (UiObjectNotFoundException e) {
throw new UnknownError("Allow button for storage permission don't exists");
}
}
permission = ContextCompat.checkSelfPermission(appContext, Manifest.permission.WRITE_EXTERNAL_STORAGE);
assertEquals(PackageManager.PERMISSION_GRANTED, permission);
SystemClock.sleep(100);
}
示例10: FrenchLocaleTest
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void FrenchLocaleTest() throws InterruptedException, UiObjectNotFoundException {
UiObject frenchMenuItem = TestHelper.mDevice.findObject(new UiSelector()
.className("android.widget.TextView")
.text("Valeur par défaut du système"));
UiObject englishMenuItem = TestHelper.mDevice.findObject(new UiSelector()
.className("android.widget.TextView")
.text("English (United States)"));
UiObject englishLocaleinFr = TestHelper.mDevice.findObject(new UiSelector()
.className("android.widget.CheckedTextView")
.text("English (United States)"));
/* Go to Settings */
TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
openSettings();
LanguageSelection.waitForExists(waitingTime);
/* system locale is in French, check it is now set to system locale */
frenchHeading.waitForExists(waitingTime);
Assert.assertTrue(frenchHeading.exists());
Assert.assertTrue(frenchMenuItem.exists());
LanguageSelection.click();
Assert.assertTrue(sysDefaultLocale.isChecked());
/* change locale to English in the setting, verify the locale is changed */
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
appViews.scrollIntoView(englishLocaleinFr);
Assert.assertTrue(englishLocaleinFr.isClickable());
englishLocaleinFr.click();
englishHeading.waitForExists(waitingTime);
Assert.assertTrue(englishHeading.exists());
Assert.assertTrue(englishMenuItem.exists());
}
示例11: test027CheckSearchHistory
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void test027CheckSearchHistory() throws UiObjectNotFoundException {
TestUtils.screenshotCap("appStoreHome");
UiObject2 hotOne = device.findObject(By.res("woyou.market:id/linear_hot_view")).findObject(By.res("woyou.market:id/tv_name"));
String targetAppName = hotOne.getText();
UiObject2 searchObj = device.findObject(By.res("woyou.market:id/tv_search").text("搜索"));
searchObj.click();
TestUtils.screenshotCap("afterClickSearchBtn");
TestUtils.sleep(SHORT_SLEEP);
UiObject2 searchObj1 = device.findObject(By.res("woyou.market:id/et_search").text("搜索").focused(true));
searchObj1.click();
searchObj1.setText(targetAppName);
TestUtils.screenshotCap("enterSearchContent");
UiScrollable appList = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
UiObject appInfo = appList.getChildByInstance(new UiSelector().resourceId("woyou.market:id/app_view"),0);
UiObject appNameObj = appInfo.getChild(new UiSelector().resourceId("woyou.market:id/tv_name"));
String appName = appNameObj.getText();
appInfo.click();
TestUtils.screenshotCap("enterTheFirstSearchResult");
device.pressBack();
TestUtils.sleep(SHORT_SLEEP);
UiObject2 clearButton = device.findObject(By.res("woyou.market:id/iv_delete"));
clearButton.click();
TestUtils.screenshotCap("clearSearchBar");
TestUtils.sleep(SHORT_SLEEP);
String historyObjName = device.findObject(By.res("woyou.market:id/history_key")).findObject(By.clazz("android.widget.TextView")).getText();
Assert.assertEquals("期望的名字是"+appName+",而實際是"+historyObjName,appName,historyObjName);
}
示例12: selectSettingsFor
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
private boolean selectSettingsFor(String name) {
try {
UiScrollable appsSettingsList = new UiScrollable(SettingsHelper.SCROLL_VIEW);
UiObject obj = appsSettingsList.getChildByText(SettingsHelper.LIST_VIEW_ITEM, name);
obj.click();
} catch (UiObjectNotFoundException e) {
return false;
}
return true;
}
示例13: allowPermissionsIfNeeded
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
protected void allowPermissionsIfNeeded() {
if (Build.VERSION.SDK_INT >= 23) {
UiObject allowPermissions = mDevice.findObject(
new UiSelector().className("android.widget.Button")
.resourceId("com.android.packageinstaller:id/permission_allow_button"));
if (allowPermissions.exists()) {
try {
allowPermissions.click();
} catch (UiObjectNotFoundException e) {
Log.e(this.getClass().getName(), "There is no permissions dialog to interact with ", e);
}
}
}
}
示例14: allowPermissionsIfNeeded
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
protected void allowPermissionsIfNeeded() {
if (Build.VERSION.SDK_INT >= 23) {
UiObject allowPermissions = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).findObject(
new UiSelector().className("android.widget.Button")
.resourceId("com.android.packageinstaller:id/permission_allow_button"));
if (allowPermissions.exists()) {
try {
allowPermissions.click();
} catch (UiObjectNotFoundException e) {
Log.e(this.getClass().getName(), "There is no permissions dialog to interact with ", e);
}
}
}
}
示例15: BadURLcheckTest
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void BadURLcheckTest() throws InterruptedException, UiObjectNotFoundException {
UiObject cancelOpenAppBtn = TestHelper.mDevice.findObject(new UiSelector()
.resourceId("android:id/button2"));
UiObject openAppalert = TestHelper.mDevice.findObject(new UiSelector()
.text("Open link in another app"));
/* provide an invalid URL */
TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
TestHelper.inlineAutocompleteEditText.clearTextField();
TestHelper.inlineAutocompleteEditText.setText("htps://www.mozilla.org");
TestHelper.hint.waitForExists(waitingTime);
TestHelper.pressEnterKey();
TestHelper.tryAgainBtn.waitForExists(waitingTime);
/* Check for error message */
assertTrue(TestHelper.notFoundMsg.exists());
assertTrue(TestHelper.notFounddetailedMsg.exists());
assertTrue(TestHelper.tryAgainBtn.exists());
/* provide market URL that is handled by Google Play app */
TestHelper.floatingEraseButton.perform(click());
TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
TestHelper.inlineAutocompleteEditText.clearTextField();
TestHelper.inlineAutocompleteEditText.setText("market://details?id=org.mozilla.firefox&referrer=" +
"utm_source%3Dmozilla%26utm_medium%3DReferral%26utm_campaign%3Dmozilla-org");
TestHelper.pressEnterKey();
// Wait for the dialog
cancelOpenAppBtn.waitForExists(waitingTime);
assertTrue(openAppalert.exists());
assertTrue(cancelOpenAppBtn.exists());
cancelOpenAppBtn.click();
TestHelper.floatingEraseButton.perform(click());
TestHelper.erasedMsg.waitForExists(waitingTime);
}