本文整理匯總了Java中android.support.test.uiautomator.UiObject.setText方法的典型用法代碼示例。如果您正苦於以下問題:Java UiObject.setText方法的具體用法?Java UiObject.setText怎麽用?Java UiObject.setText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.test.uiautomator.UiObject
的用法示例。
在下文中一共展示了UiObject.setText方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: test_singleTap2Taps
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void test_singleTap2Taps() throws UiObjectNotFoundException, InterruptedException {
BaseTest activity = mActivityRule.getActivity();
final UIGestureRecognizerDelegate delegate = activity.delegate;
delegate.clear();
UITapGestureRecognizer recognizer = new UITapGestureRecognizer(context);
recognizer.setTag("single-tap");
recognizer.setNumberOfTouchesRequired(1);
recognizer.setNumberOfTapsRequired(2);
recognizer.setActionListener(mActivityRule.getActivity());
delegate.addGestureRecognizer(recognizer);
final UiObject mainView = getMainView();
final UiObject textView = getTextView();
final UiObject title = getTitleView();
title.setText("2 Taps");
textView.setText("None");
onView(ViewMatchers.withId(R.id.activity_main)).perform(ViewActions.doubleClick());
SystemClock.sleep(200);
assertEquals(recognizer.getTag() + ": " + State.Ended, textView.getText());
}
示例3: test_singleTap
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void test_singleTap() throws UiObjectNotFoundException, InterruptedException {
BaseTest activity = mActivityRule.getActivity();
final UIGestureRecognizerDelegate delegate = activity.delegate;
Assert.assertNotNull(delegate);
delegate.clear();
UITapGestureRecognizer recognizer = new UITapGestureRecognizer(context);
recognizer.setTag("single-tap");
recognizer.setNumberOfTouchesRequired(1);
recognizer.setNumberOfTapsRequired(1);
recognizer.setActionListener(mActivityRule.getActivity());
delegate.addGestureRecognizer(recognizer);
final UiObject mainView = getMainView();
final UiObject textView = getTextView();
final UiObject title = getTitleView();
title.setText("1 Tap");
textView.setText("None");
mainView.click();
SystemClock.sleep(200);
assertEquals(recognizer.getTag() + ": " + State.Ended, textView.getText());
}
示例4: test_singleTap2Fingers
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void test_singleTap2Fingers() throws UiObjectNotFoundException, InterruptedException {
final UIGestureRecognizerDelegate delegate = mActivityRule.getActivity().delegate;
Assert.assertNotNull(delegate);
delegate.clear();
UITapGestureRecognizer recognizer = new UITapGestureRecognizer(context);
recognizer.setTag("single-tap");
recognizer.setNumberOfTouchesRequired(2);
recognizer.setNumberOfTapsRequired(1);
recognizer.setActionListener(mActivityRule.getActivity());
delegate.addGestureRecognizer(recognizer);
final UiObject mainView = getMainView();
final UiObject textView = getTextView();
final UiObject title = getTitleView();
title.setText("1 Tap 2 Fingers");
mainView.performTwoPointerGesture(
new Point(200, 300),
new Point(200, 400),
new Point(200, 300),
new Point(200, 400),
1
);
SystemClock.sleep(200);
assertEquals(recognizer.getTag() + ": " + State.Ended, textView.getText());
}
示例5: resetFieldWithText
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* @param text - The text of the field to get
* @param newValue - The new value
*/
private void resetFieldWithText( String text, String newValue ){
if ( text == null || text.length() <= 0 ){
fail("Wrong test");
}
try {
// Display the dialog
UiObject field = mDevice.findObject(
new UiSelector()
.className("android.widget.TextView")
.packageName(PACKAGE_APP_PATH)
.resourceId("android:id/title")
.text(text)
);
field.click();
// Change the value
field = mDevice.findObject(
new UiSelector()
.className("android.widget.EditText")
.packageName(PACKAGE_APP_PATH)
.resourceId("android:id/edit")
);
field.setText(newValue);
// Confirm
UiObject button = mDevice.findObject(
new UiSelector()
.className("android.widget.Button")
.packageName(PACKAGE_APP_PATH)
.resourceId("android:id/button1")
);
button.click();
} catch ( UiObjectNotFoundException uonfe ){
uonfe.printStackTrace();
fail(uonfe.getMessage());
}
}
示例6: testFieldWithName
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* @param index - The idnex of the field in the list (start at 0)
* @param text - The text of the field to get
*/
private void testFieldWithName( int index, String text ){
if ( text == null || text.length() <= 0 || index < 0){
fail("Wrong test");
}
final String DUMMY_TEXT = "Hello world";
try {
// Display the dialog
UiObject field = mDevice.findObject(
new UiSelector()
.className("android.widget.TextView")
.packageName(PACKAGE_APP_PATH)
.resourceId("android:id/title")
.text(text)
);
field.click();
// Change the value
field = mDevice.findObject(
new UiSelector()
.className("android.widget.EditText")
.packageName(PACKAGE_APP_PATH)
.resourceId("android:id/edit")
);
final String BACKUP_TEXT = field.getText();
field.setText(DUMMY_TEXT);
// Confirm
UiObject button = mDevice.findObject(
new UiSelector()
.className("android.widget.Button")
.packageName(PACKAGE_APP_PATH)
.resourceId("android:id/button1")
);
button.click();
w(1000);
// Check the summary
BySelector checkboxSettingsSelector = By.clazz("android.widget.TextView");
List<UiObject2> summaries = mDevice.findObjects(checkboxSettingsSelector);
UiObject2 field2 = summaries.get( index * 4 + 2 );
assertEquals(DUMMY_TEXT, field2.getText());
// Reset the value
resetFieldWithText( DUMMY_TEXT, BACKUP_TEXT );
} catch ( UiObjectNotFoundException uonfe ){
uonfe.printStackTrace();
fail(uonfe.getMessage());
}
}
示例7: testBrowserApp
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void testBrowserApp() throws Exception {
// Home screen apps button
UiObject appButton = uiDevice.findObject(new UiSelector().descriptionContains("Apps"));
assertTrue(appButton.exists());
appButton.clickAndWaitForNewWindow();
// Scrollable view with apps
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
assertTrue(appViews.exists());
appViews.setAsHorizontalList();
// Find browser application
UiObject browserApp = appViews.getChildByText(new UiSelector()
.className("android.widget.TextView"), "Browser");
assertTrue(browserApp.exists());
browserApp.clickAndWaitForNewWindow();
// Browser App set url
UiObject urlForm = uiDevice.findObject(new UiSelector()
.resourceId("com.android.browser:id/url"));
assertTrue(urlForm.exists());
urlForm.click();
urlForm.setText("www.google.com");
uiDevice.pressEnter();
// Wait to load page
SystemClock.sleep(10000);
// Show menu
uiDevice.pressMenu();
// Find text on page
UiObject findButton = uiDevice.findObject(new UiSelector()
.text("Find on page"));
assertTrue(findButton.exists());
findButton.click();
UiObject findView = uiDevice.findObject(new UiSelector()
.resourceId("android:id/edit"));
assertTrue(findView.exists());
findView.click();
findView.setText("Google");
uiDevice.pressEnter();
SystemClock.sleep(2000);
// Dismiss search
UiObject okButtonView = uiDevice.findObject(new UiSelector()
.resourceId("com.android.browser:id/iconcombo"));
assertTrue(okButtonView.exists());
okButtonView.click();
}