/** * @author wasiqb * @since Oct 28, 2018 * @param command * @param args */ public void executeCommand (final String command, final Map <String, Object> args) { this.driver.executeScript (command, args); }
public static String getBatterInfo(){ Object batterInfo = Driver.driver.executeScript("mobile:batteryInfo"); log.info("Battery Info : " + batterInfo); return batterInfo.toString(); } }
@PublicAtsApi public String executeScriptAndReturn( String method, Object... args ) { return (String) this.appiumDriver.executeScript(method, args); }
public static void startPerfRecordiOS(){ log.info(MyLogger.getMethodName()); Map<String, Object> args = new HashMap<>(); args.put("pid", "current"); args.put("profileName", "Time Profiler"); args.put("timeout", 6000*1000); driver.executeScript("mobile: startPerfRecord", args); }
public static void stopPerfRecordiOS(){ log.info(MyLogger.getMethodName()); Map<String, Object> args = new HashMap<>(); args.put("profileName", "Time Profiler"); File traceZip = new File(ConfigUtil.getRootDir() + File.separator +"trace.zip"); String b64Zip = (String)driver.executeScript("mobile: stopPerfRecord", args); byte[] bytesZip = Base64.getMimeDecoder().decode(b64Zip); try{ FileOutputStream stream = new FileOutputStream(traceZip); stream.write(bytesZip); stream.close(); }catch (Exception e){ log.error("Fail to capture performance data for iOS"); } }
@Test public void testBackdoor() { ImmutableMap<String, Object> scriptArgs = ImmutableMap.of( "target", "application", "methods", Arrays.asList(ImmutableMap.of( "name", "raiseToast", "args", Arrays.asList(ImmutableMap.of( "value", "Hello from the test script!", "type", "String" )) )) ); driver.executeScript("mobile: backdoor", scriptArgs); try { Thread.sleep(2000); } catch (Exception ign) {} // pause to allow visual verification }
@Test public void testFlashElement() { WebElement el = wait.until(ExpectedConditions.presenceOfElementLocated(loginScreen)); HashMap<String, Object> scriptArgs = new HashMap<>(); scriptArgs.put("element", ((RemoteWebElement)el).getId()); scriptArgs.put("durationMillis", 50); // how long should each flash take? scriptArgs.put("repeatCount", 20); // how many times should we flash? driver.executeScript("mobile: flashElement", scriptArgs); }
public void testShadowElementsWithJS(AppiumDriver driver) { WebDriverWait wait = new WebDriverWait(driver, 10); driver.get(URL); // find the web component WebElement switchComponent = wait.until(ExpectedConditions.presenceOfElementLocated( SWITCH_COMPONENT)); // pierce shadow dom to get checked status of inner control, and assert on it boolean checked = (boolean) driver.executeScript(INPUT_CHECKED, switchComponent); Assert.assertEquals(false, checked); // change the state from off to on by clicking inner input // (clicking the parent component will not work) driver.executeScript(CLICK_INPUT, switchComponent); // check that state of inner control has changed appropriately checked = (boolean) driver.executeScript(INPUT_CHECKED, switchComponent); Assert.assertEquals(true, checked); } }
public void testShadowElementsAsNative (AppiumDriver driver) { WebDriverWait wait = new WebDriverWait(driver, 10); driver.get(URL); // find the web component WebElement switchComponent = wait.until(ExpectedConditions.presenceOfElementLocated( SWITCH_COMPONENT)); // use it to find the inner control WebElement nativeCheckbox = (WebElement) driver.executeScript(SHADOWED_INPUT, switchComponent); // use the standard API to determine whether the control is checked Assert.assertEquals(nativeCheckbox.isSelected(), false); // use the standard API to change the checked status switchComponent.click(); // and finally verify the new checked state after the click Assert.assertEquals(nativeCheckbox.isSelected(), true); }