public static void captureLog(AppiumDriver driver, String testName) throws Exception { DateFormat df = new SimpleDateFormat("dd_MM_yyyy_HH-mm-ss"); Date today = Calendar.getInstance().getTime(); String reportDate = df.format(today); String logPath = "C:\\automation_capture\\"; log.info(driver.getSessionId() + ": Saving device log..."); List<LogEntry> logEntries = driver.manage().logs().get("logcat").filter(Level.ALL); File logFile = new File(logPath + reportDate + "_" + testName + ".txt"); PrintWriter log_file_writer = new PrintWriter(logFile); log_file_writer.println(logEntries ); log_file_writer.flush(); log.info(driver.getSessionId() + ": Saving device log - Done."); } }
protected void hideKeyboard() { try { driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.hideKeyboard(); } catch (Exception e) { logger.debug("Hiding soft keyboard failed"); logger.debug(e.toString()); } driver.manage().timeouts().implicitlyWait(defaultWaitTime, TimeUnit.SECONDS); }
public void swipeLeft() { AppiumDriver appiumDriver = (AppiumDriver) driver; appiumDriver.context("NATIVE_APP"); Dimension size = appiumDriver.manage().window().getSize(); int startx = (int) (size.width * 0.8); int endx = (int) (size.width * 0.20); int starty = size.height / 2; appiumDriver.swipe(startx, starty, endx, starty, 1000); }
public void swipeRight() { AppiumDriver appiumDriver = (AppiumDriver) driver; appiumDriver.context("NATIVE_APP"); Dimension size = appiumDriver.manage().window().getSize(); int endx= (int) (size.width * 0.8); int startx = (int) (size.width * 0.20); int starty = size.height / 2; appiumDriver.swipe(startx, starty, endx, starty, 1000); }
public static Dimension getScreenSize() { log.info(MyLogger.getMethodName()); Dimension dimensions = driver.manage().window().getSize(); return dimensions; }
protected void swipeDown(float topPad, float bottomPad) { Dimension size = driver.manage().window().getSize(); logger.debug("Window size is " + size); swipeDown(new Point(0, 0), size, 1000, topPad, bottomPad); }
protected void swipeUp(float topPad, float bottomPad) { Dimension size = driver.manage().window().getSize(); logger.debug("Window size is " + size); swipeUp(new Point(0, 0), size, 1000, topPad, bottomPad); }
protected void swipeLeft(float leftPad, float rightPad) { Dimension size = driver.manage().window().getSize(); logger.debug("Window size " + size); swipeLeft(new Point(0,0), size, 1000, leftPad, rightPad); }
private T swipeTo (final SwipeDirection direction, final SwipeStartPosition start, final int distancePercent) { return SwipeUtils.swipeTo (direction, start, distancePercent, this.setting, this.driver.manage () .window () .getSize (), null, null, this.actions); } }
protected void swipeRight(float leftPad, float rightPad) { Dimension size = driver.manage().window().getSize(); swipeRight(new Point(0,0), size, 1000, leftPad, rightPad); }
/** * Swipe screen to direction * * @param direction swipe direction * @param time how fast screen should be swiped * @throws SwipeException if there is an error while swiping */ public static void swipe(DirectionStrategy direction, int time) throws SwipeException { Dimension size = PageFactory.getMobileDriver().manage().window().getSize(); swipe(new Point(0, 0), size, direction, time); }
private T swipeTo (final SwipeDirection direction, final SwipeStartPosition start, final int distancePercent) { return SwipeUtils.swipeTo (direction, start, distancePercent, this.setting, this.driver.manage () .window () .getSize (), this.element.getSize (), this.element.getLocation (), this.touch); } }
/** * ====================================================================================== * TAPS ON SCREEN - MIDDLE OR AT RELATIVE COORDINATES * ====================================================================================== */ // Taps on the center of the screen. public void tapMiddle() throws Exception { Dimension size = driver.manage().window().getSize(); Point middle = new Point(size.getWidth() / 2, size.getHeight() / 2); tapAtCoordinates((int) middle.x, (int) middle.y); }
public void tapAndHoldOnScreen(double x_offset, double y_offset, int duration) throws Exception { duration = duration * 1000; Dimension size = driver.manage().window().getSize(); Point middle = new Point(size.getWidth(), size.getHeight()); Point middleWithOffset = new Point(middle.x * x_offset, middle.y * y_offset); log("Coordinates with offset are: " + middleWithOffset.x + ", " + middleWithOffset.y); if (automationName.equalsIgnoreCase("selendroid")) { selendroidTapAtCoordinate((int) middleWithOffset.x, (int) middleWithOffset.y, duration); } else { driver.tap(1, (int) middleWithOffset.x, (int) middleWithOffset.y, duration); } }
private void setImplicitWait () { try { this.driver.manage () .timeouts () .implicitlyWait (this.setting.getPlayback () .getDefaultWait (), TimeUnit.SECONDS); } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); } catch (final Exception e) { fail (DeviceDriverDefaultWaitError.class, "Error occured while setting device driver default wait.", e); } }
public void tapAtRelativeCoordinates(double x_offset, double y_offset, int taps, double frequency) throws Exception { Dimension size = driver.manage().window().getSize(); Point middle = new Point(size.getWidth(), size.getHeight()); Point middleWithOffset = new Point(middle.x * x_offset, middle.y * y_offset); log("Tapping at coordinates: " + middleWithOffset.toString() + " when size of the screen is: " + size.toString()); for (int i = 0; i < taps; i++) { if (automationName.equalsIgnoreCase("selendroid")) { selendroidTapAtCoordinate((int) middleWithOffset.x, (int) middleWithOffset.y, 1); } else { driver.tap(1, (int) middleWithOffset.x, (int) middleWithOffset.y, 1); } sleep(frequency); } }
@Before public void setUp() throws IOException { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("platformName", "Mac"); caps.setCapability("deviceName", "Mac"); caps.setCapability("app", "Activity Monitor"); driver = new AppiumDriver(new URL("http://localhost:4723/wd/hub"), caps); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); }
public void swipe(double startX, double startY, double endX, double endY) throws Exception { TouchActions actions = new TouchActions(driver); Dimension size = driver.manage().window().getSize(); Point screen = new Point(size.getWidth(), size.getHeight()); Point swipe_start = new Point(screen.x * startX, screen.y * startY); Point swipe_end = new Point(screen.x * endX, screen.y * endY); if (PlatformType.IOS.equals(PlatformType.IOS)) { iOSSwipe((int) swipe_start.x, (int) swipe_start.y, (int) swipe_end.x, (int) swipe_end.y); } else { androidSwipe((int) swipe_start.x, (int) swipe_start.y, (int) swipe_end.x, (int) swipe_end.y); } }
public void turnPageLeft() throws InterruptedException { acceptBadVideoAlert(); Dimension size = driver.manage().window().getSize(); int startX = (int) (size.width * START_OFFSET); int endX = (int) (size.width * END_OFFSET); int startY = size.height / 4; driver.swipe(startX, startY, endX, startY, SWIPE_DURATION); acceptBadVideoAlert(); }