/** * start io.appium.uiautomator2.server and launch the application main activity * * @throws InterruptedException */ @BeforeClass public static void beforeStartServer() throws InterruptedException, IOException, SessionRemovedException, JSONException { if (serverInstrumentation == null) { assertNotNull(getUiDevice()); ctx = InstrumentationRegistry.getInstrumentation().getContext(); serverInstrumentation = ServerInstrumentation.getInstance(ctx, ServerConfig.getServerPort()); Logger.info("[AppiumUiAutomator2Server]", " Starting Server "); serverInstrumentation.startServer(); TestHelper.waitForNetty(); createSession(); Configurator.getInstance().setWaitForSelectorTimeout(50000); Configurator.getInstance().setWaitForIdleTimeout(50000); } }
public static void updateSetting(int timeout) { try { Configurator.getInstance().setWaitForIdleTimeout(timeout); Logger.debug("Set waitForIdleTimeout to: " + timeout); } catch (Exception e) { Logger.error("Error setting waitForIdleTimeout " + e.getMessage()); } }
public String getResourceId() throws UiObjectNotFoundException { String resourceId = ""; if (!API.API_18) { Logger.error("Device does not support API >= 18!"); return resourceId; } try { /* * Unfortunately UiObject does not implement a getResourceId method. * There is currently no way to determine the resource-id of a given * element represented by UiObject. Until this support is added to * UiAutomater, we try to match the implementation pattern that is * already used by UiObject for getting attributes using reflection. * The returned string matches exactly what is displayed in the * UiAutomater inspector. */ AccessibilityNodeInfo node = (AccessibilityNodeInfo) invoke(method(element.getClass(), "findAccessibilityNodeInfo", long.class), element, Configurator.getInstance().getWaitForSelectorTimeout()); if (node == null) { throw new UiObjectNotFoundException(element.getSelector().toString()); } resourceId = node.getViewIdResourceName(); } catch (final Exception e) { Logger.error("Exception: " + e + " (" + e.getMessage() + ")"); } return resourceId; }
@Before public void launchAUT() throws InterruptedException, JSONException { Intent intent = new Intent().setClassName(testAppPkg, testAppPkg + ".ApiDemos").addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); ctx.stopService(intent); ctx.startActivity(intent); Logger.info("[AppiumUiAutomator2Server]", " waiting for app to launch "); TestHelper.waitForAppToLaunch(testAppPkg, 15 * SECOND); waitForElement(By.accessibilityId("Accessibility"), 10 * SECOND); getUiDevice().waitForIdle(); Logger.info("Configurator.getInstance().getWaitForSelectorTimeout:" + Configurator.getInstance().getWaitForSelectorTimeout()); element = findElement(By.accessibilityId("Accessibility")); assertTrue(By.accessibilityId("Accessibility") + " not found", isElementPresent(element)); }
@BeforeClass public static void beforeClass() throws Exception { Log.v(TAG, new Exception().getStackTrace()[0].getMethodName() + "()"); // Get command line parameters getArguments(); // Create screenshot folder File path = Environment.getExternalStorageDirectory(); Config.sOutputDir = new File(String.format("%s/AppCrawler/%s", path.getAbsolutePath(), Config.sTargetPackage)); deleteRecursive(Config.sOutputDir); if (!Config.sOutputDir.exists()) { if (!Config.sOutputDir.mkdirs()) { Log.d(TAG, "Failed to create screenshot folder: " + Config.sOutputDir.getPath()); } } // Init File log Config.sFileLog = Config.sOutputDir + "/" + Config.TAG + ".log"; FileLog.i(TAG_MAIN, "Version: " + Config.VERSION); // Init Performance log Config.sPerformanceLog = Config.sOutputDir + "/Performance.csv"; PerformanceMonitor.init(); // Set timeout longer so we can see the ANR dialog? Configurator conf = Configurator.getInstance(); conf.setActionAcknowledgmentTimeout(200L); // Generally, this timeout should not be modified, default 3000 conf.setScrollAcknowledgmentTimeout(100L); // Generally, this timeout should not be modified, default 200 conf.setWaitForIdleTimeout(0L); conf.setWaitForSelectorTimeout(0L); //conf.setKeyInjectionDelay(0L); logConfiguration(); // Register UiWatchers: ANR, CRASH, .... UiHelper.registerAnrAndCrashWatchers(); // Good practice to start from the home screen (launcher) UiHelper.launchHome(); }
public static void logConfiguration() { Configurator conf = Configurator.getInstance(); String log = String.format("ActionAcknowledgmentTimeout:%d," + " KeyInjectionDelay:%d, " + "ScrollAcknowledgmentTimeout:%d," + " WaitForIdleTimeout:%d," + " WaitForSelectorTimeout:%d", conf.getActionAcknowledgmentTimeout(), conf.getKeyInjectionDelay(), conf.getScrollAcknowledgmentTimeout(), conf.getWaitForIdleTimeout(), conf.getWaitForSelectorTimeout()); FileLog.i(TAG_MAIN, log); FileLog.i(TAG_MAIN, "TargetPackage: " + Config.sTargetPackage + ", Debug: " + Config.sDebug + ", MaxSteps: " + Config.sMaxSteps + ", MaxDepth: " + Config.sMaxDepth + ", MaxRuntime: " + Config.sMaxRuntime + ", MaxScreenshot: " + Config.sMaxScreenshot + ", MaxScreenLoop: " + Config.sMaxScreenLoop + ", ScreenSignatueLength: " + Config.sScreenSignatueLength + ", RandomText: " + Config.sRandomText + ", CaptureSteps: " + Config.sCaptureSteps + ", LaunchTimeout: " + Config.sLaunchTimeout + ", WaitIdleTimeout: " + Config.sWaitIdleTimeout); }
public ConfiguratorInfo() { Configurator config = Configurator.getInstance(); this._actionAcknowledgmentTimeout = config.getActionAcknowledgmentTimeout(); this._keyInjectionDelay = config.getKeyInjectionDelay(); this._scrollAcknowledgmentTimeout = config.getScrollAcknowledgmentTimeout(); this._waitForIdleTimeout = config.getWaitForIdleTimeout(); this._waitForSelectorTimeout = config.getWaitForSelectorTimeout(); }
public static void setConfigurator(ConfiguratorInfo info) { Configurator config = Configurator.getInstance(); config.setActionAcknowledgmentTimeout(info.getActionAcknowledgmentTimeout()); config.setKeyInjectionDelay(info.getKeyInjectionDelay()); config.setScrollAcknowledgmentTimeout(info.getScrollAcknowledgmentTimeout()); config.setWaitForIdleTimeout(info.getWaitForIdleTimeout()); config.setWaitForSelectorTimeout(info.getWaitForSelectorTimeout()); }
public boolean moveThumbForward() throws UiObjectNotFoundException { AccessibilityNodeInfo ani = findAccessibilityNodeInfo(Configurator.getInstance().getWaitForSelectorTimeout()); if (ani == null) { throw new UiObjectNotFoundException(getSelector().toString()); } return ani.performAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD); }
public boolean moveThumbBackward() throws UiObjectNotFoundException { AccessibilityNodeInfo ani = findAccessibilityNodeInfo(Configurator.getInstance().getWaitForSelectorTimeout()); if (ani == null) { throw new UiObjectNotFoundException(getSelector().toString()); } return ani.performAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD); }
public boolean setThumbValue(int value) throws UiObjectNotFoundException { AccessibilityNodeInfo ani = findAccessibilityNodeInfo(Configurator.getInstance().getWaitForSelectorTimeout()); if (ani == null) { throw new UiObjectNotFoundException(getSelector().toString()); } Bundle args = new Bundle(); args.putInt("value", value); return ani.performAction(ACT_SET_PROGRESS, args); }
public void setText(String text) throws UiObjectNotFoundException { Configurator config = Configurator.getInstance(); config.setKeyInjectionDelay(20); element.setText(text); config.setKeyInjectionDelay(0); }