本文整理匯總了Java中android.support.test.uiautomator.UiObject類的典型用法代碼示例。如果您正苦於以下問題:Java UiObject類的具體用法?Java UiObject怎麽用?Java UiObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UiObject類屬於android.support.test.uiautomator包,在下文中一共展示了UiObject類的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: openAppTest
import android.support.test.uiautomator.UiObject; //導入依賴的package包/類
@Test
public void openAppTest() throws Exception {
UiDevice mDevice = UiDevice.getInstance(getInstrumentation());
mDevice.pressHome();
// Bring up the default launcher by searching for a UI component
// that matches the content description for the launcher button.
UiObject allAppsButton = mDevice
.findObject(new UiSelector().description("Apps"));
// Perform a click on the button to load the launcher.
allAppsButton.clickAndWaitForNewWindow();
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.wbrawner.simplemarkdown", appContext.getPackageName());
UiScrollable appView = new UiScrollable(new UiSelector().scrollable(true));
UiSelector simpleMarkdownSelector = new UiSelector().text("Simple Markdown");
appView.scrollIntoView(simpleMarkdownSelector);
mDevice.findObject(simpleMarkdownSelector).clickAndWaitForNewWindow();
}
示例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: 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();
}
示例5: viewExistsContains
import android.support.test.uiautomator.UiObject; //導入依賴的package包/類
public static boolean viewExistsContains(UiDevice device, String... textToMatch) throws UiObjectNotFoundException
{
if (textToMatch == null || textToMatch.length < 1)
{
return false;
}
UiObject view;
boolean contains = false;
for (int i = 0; i < textToMatch.length; i++)
{
view = device.findObject(new UiSelector().textContains(textToMatch[i]));
contains = view.exists();
if (contains) return true;
}
return false;
}
示例6: allowLocationPermissionWhenAsked
import android.support.test.uiautomator.UiObject; //導入依賴的package包/類
/**
* Allows location permission if the runtime permission dialog is shown.
*/
public static void allowLocationPermissionWhenAsked()
{
try
{
if (!PermissionUtils.isLocationGranted(InstrumentationRegistry.getTargetContext()))
{
TestHelper.sleep(PERMISSIONS_DIALOG_DELAY);
final UiDevice device = UiDevice.getInstance(getInstrumentation());
final UiObject allowPermissions = device.findObject(new UiSelector()
.clickable(true)
.checkable(false)
.index(GRANT_BUTTON_INDEX));
if (allowPermissions.exists())
{
allowPermissions.click();
}
}
}
catch (final UiObjectNotFoundException e)
{
Log.e(PermissionTestHelper.class.getSimpleName(), "There is no permissions dialog to interact with.");
}
}
示例7: 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);
}
示例8: openStandaloneModeDialog
import android.support.test.uiautomator.UiObject; //導入依賴的package包/類
/**
* Opens the standalone mode dialog
*/
private void openStandaloneModeDialog(){
try {
// Display the pop-up
UiObject menu = mDevice.findObject(
new UiSelector().className("android.widget.ImageView")
//.description("Plus d'options") // FIXME Raw french string
.description("Autres options") // WARNING FIXME French string used, use instead system R values
);
menu.click();
UiObject menuItem = mDevice.findObject(
new UiSelector().className("android.widget.TextView").text(InstrumentationRegistry.getTargetContext().getString(R.string.action_standalone))
);
menuItem.click();
} catch ( UiObjectNotFoundException uinfe ){
uinfe.printStackTrace();
fail(uinfe.getMessage());
}
}
示例9: 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();
}
示例10: 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();
}
示例11: test009SearchByTitle
import android.support.test.uiautomator.UiObject; //導入依賴的package包/類
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test009SearchByTitle() 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("afterClickSearchBar");
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("inputSearchContent");
UiScrollable appList = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
UiObject appInfo = appList.getChildByInstance(new UiSelector().className("android.widget.FrameLayout"),0);
UiObject appNameObj = appInfo.getChild(new UiSelector().resourceId("woyou.market:id/tv_name"));
Assert.assertEquals(targetAppName,appNameObj.getText());
}
示例12: test026FoldupAppDetail
import android.support.test.uiautomator.UiObject; //導入依賴的package包/類
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test026FoldupAppDetail() throws UiObjectNotFoundException {
TestUtils.screenshotCap("appStoreHome");
UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
TestUtils.screenshotCap("hotAllInterface");
UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
UiObject fullAppObj = hotAllScroll.getChild(new UiSelector().className("android.widget.FrameLayout"));
fullAppObj.clickAndWaitForNewWindow(LONG_WAIT);
TestUtils.screenshotCap("enterAppDetail");
UiObject2 foldupButton = device.findObject(By.res("woyou.market:id/iv_arrow"));
foldupButton.clickAndWait(Until.newWindow(),LONG_WAIT);
TestUtils.screenshotCap("foldUpAppDetail");
UiScrollable hotAllScroll1 = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
Assert.assertNotNull(hotAllScroll1);
}
示例13: test009SearchByTitle
import android.support.test.uiautomator.UiObject; //導入依賴的package包/類
@Test
public void test009SearchByTitle() 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("afterClickSearchBar");
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("inputSearchContent");
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"));
Assert.assertEquals("搜索結果列表第一個應用不是"+targetAppName,targetAppName,appNameObj.getText());
}
示例14: test026FoldupAppDetail
import android.support.test.uiautomator.UiObject; //導入依賴的package包/類
@Test
public void test026FoldupAppDetail() throws UiObjectNotFoundException {
TestUtils.screenshotCap("appStoreHome");
UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
TestUtils.screenshotCap("hotAllInterface");
UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
UiObject fullAppObj = hotAllScroll.getChild(new UiSelector().resourceId("woyou.market:id/app_view"));
fullAppObj.clickAndWaitForNewWindow(LONG_WAIT);
TestUtils.screenshotCap("enterAppDetail");
UiObject2 foldupButton = device.findObject(By.res("woyou.market:id/iv_arrow"));
foldupButton.clickAndWait(Until.newWindow(),LONG_WAIT);
TestUtils.screenshotCap("foldUpAppDetail");
UiScrollable hotAllScroll1 = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
Assert.assertNotNull(hotAllScroll1);
}
示例15: 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");
}