use of com.android.uiautomator.core.UiScrollable in project Quality-Tools-for-Android by stephanenicolas.
the class UIAutomatorSampleTest method startAppOnEmulator.
private void startAppOnEmulator(String appName) throws UiObjectNotFoundException {
// Simulate a short press on the HOME button.
getUiDevice().pressHome();
new UiObject(new UiSelector().description("Apps"));
// We?re now in the home screen. Next, we want to simulate
// a user bringing up the All Apps screen.
// If you use the uiautomatorviewer tool to capture a snapshot
// of the Home screen, notice that the All Apps button?s
// content-description property has the value ?Apps?. We can
// use this property to create a UiSelector to find the button.
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
// Simulate a click to bring up the All Apps screen.
allAppsButton.clickAndWaitForNewWindow();
// In the All Apps screen, the Settings app is located in
// the Apps tab. To simulate the user bringing up the Apps tab,
// we create a UiSelector to find a tab with the text
// label ?Apps?.
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
// Simulate a click to enter the Apps tab.
appsTab.click();
// Next, in the apps tabs, we can simulate a user swiping until
// they come to the Settings app icon. Since the container view
// is scrollable, we can use a UiScrollable object.
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
// Set the swiping mode to horizontal (the default is vertical)
appViews.setAsHorizontalList();
appViews.setMaxSearchSwipes(MAX_SEARCH_SWIPES_IN_APP_MENU);
// Create a UiSelector to find the Settings app and simulate
// a user click to launch the app.
UiObject settingsApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), appName);
settingsApp.waitForExists(TIMEOUT_DURING_APP_SEARCH);
settingsApp.clickAndWaitForNewWindow();
}
use of com.android.uiautomator.core.UiScrollable in project android-player-samples by BrightcoveOS.
the class OnceUxUiAutomatorBase method tearDown.
/**
* In the tearDown, using UiAutomator API, it goes back to home, reopens the
* applications menu, sifts through and finds the settings app, and then force
* closes the Sample App. Then, it opens up the recent apps screen, and swipes
* away the Sample App from that screen. By doing so we entirely remove it
* from the device's cached memory. This allows us to have a totally clean
* environment when beginning a new test.
*/
@Override
protected void tearDown() throws Exception {
// We now want to leave the app and close it entirely. The first step is to go to the all apps menu and navigate through it.
getUiDevice().pressHome();
Log.v(TAG, "Pressing the Home button.");
TimeUnit.SECONDS.sleep(1);
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();
Log.v(TAG, "Pressing the All Apps button.");
// Next, we have to navigate through the apps menu.
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
appsTab.click();
Log.v(TAG, "Pressing the Apps tab.");
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
appViews.setAsHorizontalList();
// Next, we open the settings app, and open the particular section that specifies settings for Apps.
UiObject settingsApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "Settings");
settingsApp.click();
Log.v(TAG, "Pressing the Settings app.");
UiObject settingsAppsTab = new UiObject(new UiSelector().text("Apps"));
settingsAppsTab.click();
Log.v(TAG, "Pressing the Apps tab in the Settings App.");
// Next, we must choose the "Basic ONCE UX Sample App".
UiObject basicOnceUxSampleAppSettings = new UiObject(new UiSelector().text("Basic ONCE UX Sample App"));
basicOnceUxSampleAppSettings.click();
Log.v(TAG, "Pressing the Basic ONCE UX Sample App in the Apps Settings field.");
// And we Force stop the sample app, pressing OK when the clarification prompt appears, and leave settings.
UiObject forceStopButton = new UiObject(new UiSelector().text("Force stop"));
forceStopButton.clickAndWaitForNewWindow();
UiObject okButton = new UiObject(new UiSelector().text("OK").className(android.widget.Button.class));
okButton.click();
getUiDevice().pressHome();
Log.v(TAG, "Pressing the Home button.");
// The following could serve as an alternative to the first method, or can be used in conjunction
// with it. It only works for android devices that have a recent apps button.
// First, we open the recent apps screen.
getUiDevice().pressHome();
Log.v(TAG, "Pressing the Home button.");
getUiDevice().pressRecentApps();
Log.v(TAG, "Pressing the Recent Apps button.");
// Then we register the UiObject and swipe it down in order to remove it from the recent activity screen, and return to home.
UiObject basicOnceUxSampleAppRecentActivity = new UiObject(new UiSelector().description("Basic ONCE UX Sample App"));
basicOnceUxSampleAppRecentActivity.swipeDown(20);
Log.v(TAG, "Swiping away the Basic Once Ux Sample App activity Ui Object.");
getUiDevice().pressHome();
Log.v(TAG, "Pressing the Home button.");
}
use of com.android.uiautomator.core.UiScrollable in project android-player-samples by BrightcoveOS.
the class OnceUxUiAutomatorBase method setUp.
// Universal setUp and tearDown methods.
/**
* Test represents a setUp method for the other tests. Using the UiAutomator API, it
* goes to the home menu, opens up applications, sifts through and opens up the Basic
* OnceUx Sample App. It opens the application with the name that matches "Basic ONCE
* UX Sample App."
*/
protected void setUp() throws Exception {
// Simulate a short press on the HOME button and navigate to apps screen.
getUiDevice().pressHome();
Log.v(TAG, "Pressing the home button.");
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();
Log.v(TAG, "Pressing the All Apps button.");
// Next is the task of navigating to the sample app in the apps menu and scrolling through until it is found.
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
appsTab.click();
Log.v(TAG, "Pressing the Apps tab.");
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
appViews.setAsHorizontalList();
// If it exists, we want to press on the app's icon, launching it.
basicOnceUxSampleApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "Basic ONCE UX Sample App");
if (basicOnceUxSampleApp != null) {
basicOnceUxSampleApp.clickAndWaitForNewWindow();
Log.v(TAG, "Pressing the Basic Once Ux Sample App.");
}
}
use of com.android.uiautomator.core.UiScrollable in project android-player-samples by BrightcoveOS.
the class UiAutomatorTest method testDemo.
// Public methods.
public void testDemo() throws UiObjectNotFoundException {
// Simulate a short press on the HOME button.
getUiDevice().pressHome();
// We’re now in the home screen. Next, we want to simulate
// a user bringing up the All Apps screen.
// If you use the uiautomatorviewer tool to capture a snapshot
// of the Home screen, notice that the All Apps button’s
// content-description property has the value “Apps”. We can
// use this property to create a UiSelector to find the button.
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
// Simulate a click to bring up the All Apps screen.
allAppsButton.clickAndWaitForNewWindow();
// In the All Apps screen, the Settings app is located in
// the Apps tab. To simulate the user bringing up the Apps tab,
// we create a UiSelector to find a tab with the text
// label “Apps”.
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
// Simulate a click to enter the Apps tab.
appsTab.click();
// Next, in the apps tabs, we can simulate a user swiping until
// they come to the Settings app icon. Since the container view
// is scrollable, we can use a UiScrollable object.
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
// Set the swiping mode to horizontal (the default is vertical)
appViews.setAsHorizontalList();
// Create a UiSelector to find the Settings app and simulate
// a user click to launch the app.
UiObject calendarApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "Calendar");
// Validate that the calendar app exists.
assertTrue("Unable to detect Calendar app.", calendarApp != null);
calendarApp.clickAndWaitForNewWindow();
}
Aggregations