How to use getY method of org.cerberus.service.appium.impl.Coordinates class

Best Cerberus-source code snippet using org.cerberus.service.appium.impl.Coordinates.getY

Source:AppiumService.java Github

copy

Full Screen

...147 try {148 final TouchAction action = new TouchAction(session.getAppiumDriver());149 if (identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {150 final Coordinates coordinates = getCoordinates(identifier);151 action.tap(PointOption.point(coordinates.getX(), coordinates.getY())).perform();152 } else {153 action.tap(ElementOption.element(getElement(session, identifier, false, false))).perform();154 }155 return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICK).resolveDescription("ELEMENT", identifier.toString());156 } catch (NoSuchElementException e) {157 if (LOG.isDebugEnabled()) {158 LOG.debug(e.getMessage());159 }160 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK_NO_SUCH_ELEMENT).resolveDescription("ELEMENT", identifier.toString());161 } catch (WebDriverException e) {162 LOG.warn(e.getMessage());163 return parseWebDriverException(e);164 }165 }166 /**167 * @author vertigo17168 * @param exception the exception need to be parsed by Cerberus169 * @return A new Event Message with selenium related description170 */171 private MessageEvent parseWebDriverException(WebDriverException exception) {172 MessageEvent mes;173 LOG.error(exception.toString(), exception);174 mes = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY);175 mes.setDescription(mes.getDescription().replace("%ERROR%", exception.getMessage().split("\n")[0]));176 return mes;177 }178 /**179 * Get the {@link Coordinates} represented by the given {@link Identifier}180 *181 * @param identifier the {@link Identifier} to parse to get the182 * {@link Coordinates}183 * @return the {@link Coordinates} represented by the given184 * {@link Identifier}185 * @throws NoSuchElementException if no {@link Coordinates} can be found186 * inside the given {@link Identifier}187 */188 private Coordinates getCoordinates(final Identifier identifier) {189 if (identifier == null || !identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {190 throw new NoSuchElementException("Unable to get coordinates from a non coordinates identifier");191 }192 final Matcher coordinates = Identifier.Identifiers.COORDINATE_VALUE_PATTERN.matcher(identifier.getLocator());193 if (!coordinates.find()) {194 throw new NoSuchElementException("Bad coordinates format");195 }196 try {197 return new Coordinates(198 Integer.valueOf(coordinates.group("xCoordinate")),199 Integer.valueOf(coordinates.group("yCoordinate"))200 );201 } catch (NumberFormatException e) {202 throw new NoSuchElementException("Bad coordinates format", e);203 }204 }205 private By getBy(Identifier identifier) {206 LOG.debug("Finding selenium Element : " + identifier.getLocator() + " by : " + identifier.getIdentifier());207 if (identifier.getIdentifier().equalsIgnoreCase("id")) {208 return By.id(identifier.getLocator());209 } else if (identifier.getIdentifier().equalsIgnoreCase("name")) {210 return By.name(identifier.getLocator());211 } else if (identifier.getIdentifier().equalsIgnoreCase("class")) {212 return By.className(identifier.getLocator());213 } else if (identifier.getIdentifier().equalsIgnoreCase("css")) {214 return By.cssSelector(identifier.getLocator());215 } else if (identifier.getIdentifier().equalsIgnoreCase("xpath")) {216 return By.xpath(identifier.getLocator());217 } else if (identifier.getIdentifier().equalsIgnoreCase("link")) {218 return By.linkText(identifier.getLocator());219 } else if (identifier.getIdentifier().equalsIgnoreCase("data-cerberus")) {220 return By.xpath("//*[@data-cerberus='" + identifier.getLocator() + "']");221 } else if (identifier.getIdentifier().equalsIgnoreCase("accesibility-id")) {222 return MobileBy.AccessibilityId(identifier.getLocator());223 } else {224 throw new NoSuchElementException(identifier.getIdentifier());225 }226 }227 private WebElement getElement(Session session, Identifier identifier, boolean visible, boolean clickable) {228 AppiumDriver driver = session.getAppiumDriver();229 By locator = this.getBy(identifier);230 LOG.debug("Waiting for Element : " + identifier.getIdentifier() + "=" + identifier.getLocator());231 try {232 WebDriverWait wait = new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(session.getCerberus_appium_wait_element()));233 if (visible) {234 if (clickable) {235 wait.until(ExpectedConditions.elementToBeClickable(locator));236 } else {237 wait.until(ExpectedConditions.visibilityOfElementLocated(locator));238 }239 } else {240 wait.until(ExpectedConditions.presenceOfElementLocated(locator));241 }242 } catch (TimeoutException exception) {243 LOG.fatal("Exception waiting for element :" + exception.toString());244 throw new NoSuchElementException(identifier.getIdentifier() + "=" + identifier.getLocator());245 }246 LOG.debug("Finding Element : " + identifier.getIdentifier() + "=" + identifier.getLocator());247 return driver.findElement(locator);248 }249 /**250 *251 * @param session252 * @param action253 * @return254 * @throws IllegalArgumentException255 */256 @Override257 public Direction getDirectionForSwipe(Session session, SwipeAction action) throws IllegalArgumentException {258 Dimension window = session.getAppiumDriver().manage().window().getSize();259 SwipeAction.Direction direction;260 switch (action.getActionType()) {261 case UP:262 direction = SwipeAction.Direction.fromLine(263 new Line2D.Double(264 window.getWidth() / 2,265 2 * window.getHeight() / 3,266 0,267 -window.getHeight() / 3268 )269 );270 break;271 case DOWN:272 direction = SwipeAction.Direction.fromLine(273 new Line2D.Double(274 window.getWidth() / 2,275 window.getHeight() / 3,276 0,277 window.getHeight() / 3278 )279 );280 break;281 case LEFT:282 direction = SwipeAction.Direction.fromLine(283 new Line2D.Double(284 2 * window.getWidth() / 3,285 window.getHeight() / 2,286 -window.getWidth() / 3,287 0288 )289 );290 break;291 case RIGHT:292 direction = SwipeAction.Direction.fromLine(293 new Line2D.Double(294 window.getWidth() / 3,295 window.getHeight() / 2,296 window.getWidth() / 3,297 0298 )299 );300 break;301 case CUSTOM:302 direction = action.getCustomDirection();303 break;304 default:305 throw new IllegalArgumentException("Unknown direction");306 }307 return direction;308 }309 @Override310 public MessageEvent scrollTo(Session session, Identifier element, String numberScrollDownMax) throws IllegalArgumentException {311 AppiumDriver driver = session.getAppiumDriver();312 MessageEvent message;313 try {314 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SCROLLTO);315 int numberOfScrollDown = 8;316 try {317 numberOfScrollDown = Integer.parseInt(numberScrollDownMax);318 } catch (NumberFormatException e) {319 // do nothing320 }321 // check text322 if (element.getIdentifier().equals("text")) {323 scrollDown(driver, By.xpath("//*[contains(@text,'" + element.getLocator() + "')]"), numberOfScrollDown);324 } else {325 scrollDown(driver, this.getBy(element), numberOfScrollDown);326 }327 message.setDescription(message.getDescription().replace("%VALUE%", element.toString()));328 return message;329 } catch (Exception e) {330 LOG.error("An error occured during scroll to (element:" + element + ",numberScrollDownMax:" + numberScrollDownMax + ")", e);331 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC);332 message.setDescription(message.getDescription().replace("%DETAIL%", e.getMessage()));333 return message;334 }335 }336 /**337 * Scroll down and stop when element is present338 *339 * @param driver340 * @param element341 * @return342 */343 private boolean scrollDown(AppiumDriver driver, By element, int numberOfScrollDown) {344 int pressX = driver.manage().window().getSize().width / 2;345 int bottomY = driver.manage().window().getSize().height * 4 / 5;346 int topY = driver.manage().window().getSize().height / 8;347 int i = 0;348 do {349 boolean isPresent = driver.findElements(element).size() > 0;350 if (isPresent) {351 Object elmtObj = driver.findElements(element).get(0);352 if (elmtObj != null && ((MobileElement) elmtObj).isDisplayed()) {353 return true;354 }355 } else {356 scroll(driver, pressX, bottomY, pressX, topY);357 }358 i++;359 } while (i <= numberOfScrollDown);360 return false;361 }362 private void scroll(AppiumDriver driver, int fromX, int fromY, int toX, int toY) {363 TouchAction touchAction = new TouchAction(driver);364 touchAction.longPress(PointOption.point(fromX, fromY)).moveTo(PointOption.point(toX, toY)).release().perform();365 }366 public abstract String executeCommandString(Session session, String cmd, String args) throws IllegalArgumentException, JSONException;367 public String getElementPosition(Session session, Identifier identifier) {368 AppiumDriver driver = session.getAppiumDriver();369 MobileElement element = (MobileElement) driver.findElement(this.getBy(identifier));370 Point location = element.getLocation();371 return location.getX() + ";" + location.getY();372 }373 @Override374 public MessageEvent longPress(final Session session, final Identifier identifier, final Integer timeDuration) {375 try {376 final TouchAction action = new TouchAction(session.getAppiumDriver());377 if (identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {378 final Coordinates coordinates = getCoordinates(identifier);379 action.press(PointOption.point(coordinates.getX(), coordinates.getY())).waitAction(WaitOptions.waitOptions(Duration.ofMillis(timeDuration))).release().perform();380 } else {381 action.press(ElementOption.element(getElement(session, identifier, false, false))).waitAction(WaitOptions.waitOptions(Duration.ofMillis(timeDuration))).release().perform();382 }383 return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_LONG_CLICK).resolveDescription("ELEMENT", identifier.toString());384 } catch (NoSuchElementException e) {385 if (LOG.isDebugEnabled()) {386 LOG.debug(e.getMessage());387 }388 return new MessageEvent(MessageEventEnum.ACTION_FAILED_LONG_CLICK_NO_SUCH_ELEMENT).resolveDescription("ELEMENT", identifier.toString());389 } catch (WebDriverException e) {390 LOG.warn(e.getMessage());391 return parseWebDriverException(e);392 }393 }...

Full Screen

Full Screen

getY

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Point;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.interactions.internal.Coordinates;4import org.openqa.selenium.interactions.internal.Locatable;5import org.openqa.selenium.remote.RemoteWebDriver;6import org.openqa.selenium.remote.RemoteWebElement;7Coordinates coordinate = ((Locatable)element).getCoordinates();8int y = coordinate.onPage().getY();9System.out.println("y value of the element is "+y);10import org.openqa.selenium.WebElement;11import org.openqa.selenium.remote.RemoteWebDriver;12import org.openqa.selenium.remote.RemoteWebElement;13import org.cerberus.service.appium.impl.Element;14Element element1 = new Element((RemoteWebElement) element);15Coordinates coordinate = element1.getCoordinates();16int y = coordinate.onPage().getY();17System.out.println("y value of the element is "+y);18import org.openqa.selenium.WebElement;19import org.openqa.selenium.remote.RemoteWebDriver;20import org.openqa.selenium.remote.RemoteWebElement;21import org.cerberus.service.appium.impl.Element;22Element element1 = new Element((RemoteWebElement) element);23Coordinates coordinate = element1.getCoordinates();24int y = coordinate.inViewPort().getY();25System.out.println("y value of the element is "+y);26import org.openqa.selenium.WebElement;27import org.openqa.selenium.remote.RemoteWebDriver;28import org.openqa.selenium.remote.RemoteWebElement;29import org.cerberus.service.appium.impl.Element;30Element element1 = new Element((RemoteWebElement) element);31Coordinates coordinate = element1.getCoordinates();32int y = coordinate.onScreen().getY();33System.out.println("y value of the element is "+y);34import org.openqa.selenium.WebElement;35import org.openqa.selenium.remote.RemoteWebDriver;36import org.openqa.selenium.remote.RemoteWebElement;37import org.cerberus.service.appium.impl.Element;

Full Screen

Full Screen

getY

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.appium.impl.Coordinates;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.remote.RemoteWebElement;5import org.openqa.selenium.support.ui.ExpectedConditions;6import org.openqa.selenium.support.ui.WebDriverWait;7import org.openqa.selenium.By;8import org.openqa.selenium.Dimension;9import org.openqa.selenium.JavascriptExecutor;10import org.openqa.selenium.Point;11import org.openqa.selenium.interactions.to

Full Screen

Full Screen

getY

Using AI Code Generation

copy

Full Screen

1WebElement element = driver.findElement(By.id("id"));2int y = element.getCoordinates().onPage().getY();3System.out.println("y coordinate of the element is: " + y);4WebElement element = driver.findElement(By.id("id"));5int x = element.getCoordinates().onPage().getX();6System.out.println("x coordinate of the element is: " + x);7WebElement element = driver.findElement(By.id("id"));8Point location = element.getCoordinates().onPage().getLocation();9System.out.println("Location of the element is: " + location);10WebElement element = driver.findElement(By.id("id"));11Point locationInDom = element.getCoordinates().onPage().getLocationInDom();12System.out.println("Location of the element in DOM is: " + locationInDom);13WebElement element = driver.findElement(By.id("id"));14Point locationInView = element.getCoordinates().onPage().getLocationInView();15System.out.println("Location of the element in view is: " + locationInView);16WebElement element = driver.findElement(By.id("id"));17Object auxiliary = element.getCoordinates().onPage().getAuxiliary();18System.out.println("Auxiliary of the element is: " + auxiliary);19WebElement element = driver.findElement(By.id("id"));20Object origin = element.getCoordinates().onPage().getOrigin();21System.out.println("Origin of the element is: " + origin);

Full Screen

Full Screen

getY

Using AI Code Generation

copy

Full Screen

1 public int getY() {2 return this.getCoordinates().onPage().getY();3 }4 public Coordinates getCoordinates() {5 if (this.coordinates == null) {6 this.coordinates = new Coordinates(this);7 }8 return this.coordinates;9 }10 public int getX() {11 return this.getCoordinates().onPage().getX();12 }13 public Coordinates getCoordinates() {14 if (this.coordinates == null) {15 this.coordinates = new Coordinates(this);16 }17 return this.coordinates;18 }19 public Point getCenter() {20 return this.getCoordinates().onPage().getCenter();21 }22 public Coordinates getCoordinates() {23 if (this.coordinates == null) {24 this.coordinates = new Coordinates(this);25 }26 return this.coordinates;27 }28 public Coordinates getCoordinates() {29 if (this.coordinates == null) {30 this.coordinates = new Coordinates(this);31 }32 return this.coordinates;33 }34 public Coordinates getCoordinates() {35 if (this.coordinates == null) {36 this.coordinates = new Coordinates(this);37 }38 return this.coordinates;39 }40 public Coordinates getCoordinates() {41 if (this.coordinates == null) {42 this.coordinates = new Coordinates(this);43 }44 return this.coordinates;45 }

Full Screen

Full Screen

getY

Using AI Code Generation

copy

Full Screen

1AppiumDriver driver = appiumService.getDriver();2Coordinates coordinates = ((Locatable) element).getCoordinates();3int y = coordinates.getY();4System.out.println("Y coordinate of the element is: " + y);5AppiumDriver driver = appiumService.getDriver();6Coordinates coordinates = ((Locatable) element).getCoordinates();7int x = coordinates.getX();8System.out.println("X coordinate of the element is: " + x);9AppiumDriver driver = appiumService.getDriver();10Coordinates coordinates = ((Locatable) element).getCoordinates();11Point location = coordinates.getLocation();12System.out.println("Location of the element is: " + location);13AppiumDriver driver = appiumService.getDriver();14Coordinates coordinates = ((Locatable) element).getCoordinates();15Point locationInDom = coordinates.getLocationInDom();16System.out.println("Location of the element in DOM is: " + locationInDom);

Full Screen

Full Screen

getY

Using AI Code Generation

copy

Full Screen

1public class getY {2 public static void main(String[] args) {3 Coordinates coordinates = new Coordinates();4 int y = coordinates.getY();5 System.out.println("Y coordinate of the element: " + y);6 }7}8org.cerberus.service.appium.impl.Coordinates.getX()9org.cerberus.service.appium.impl.Coordinates.onScreen()10org.cerberus.service.appium.impl.Coordinates.getCenter()11org.cerberus.service.appium.impl.Coordinates.getAuxiliary()12org.cerberus.service.appium.impl.Coordinates.getOrigin()13org.cerberus.service.appium.impl.Coordinates.inViewPort()14org.cerberus.service.appium.impl.Coordinates.inDom()15org.cerberus.service.appium.impl.Coordinates.getReference()16org.cerberus.service.appium.impl.Coordinates.getPointer()17org.cerberus.service.appium.impl.Coordinates.getAbsolute()18org.cerberus.service.appium.impl.Coordinates.getRelative()19org.cerberus.service.appium.impl.Coordinates.getAbsoluteLeft()20org.cerberus.service.appium.impl.Coordinates.getAbsoluteTop()21org.cerberus.service.appium.impl.Coordinates.getAuxiliaryLeft()22org.cerberus.service.appium.impl.Coordinates.getAuxiliaryTop()23org.cerberus.service.appium.impl.Coordinates.getAuxiliaryWidth()24org.cerberus.service.appium.impl.Coordinates.getAuxiliaryHeight()25org.cerberus.service.appium.impl.Coordinates.getReferenceLeft()26org.cerberus.service.appium.impl.Coordinates.getReferenceTop()

Full Screen

Full Screen

getY

Using AI Code Generation

copy

Full Screen

1package org.cerberus.service.appium.impl;2import io.appium.java_client.MobileElement;3import io.appium.java_client.TouchAction;4import io.appium.java_client.android.AndroidDriver;5import io.appium.java_client.ios.IOSDriver;6import io.appium.java_client.ios.IOSElement;7import org.cerberus.service.appium.IAppiumService;8import org.openqa.selenium.Dimension;9import org.openqa.selenium.Point;10import org.openqa.selenium.WebElement;11import java.util.List;12public class AppiumService implements IAppiumService {13 private static final String TAG = "AppiumService";14 public void swipeUp(AndroidDriver driver, int duration) {15 Dimension size = driver.manage().window().getSize();16 int x = size.width / 2;17 int y = size.height / 2;18 int x1 = x;19 int y1 = (int) (y * 0.20);20 int x2 = x;21 int y2 = (int) (y * 0.90);22 swipe(x1, y1, x2, y2, duration);23 }24 public void swipeUp(IOSDriver driver, int duration) {25 Dimension size = driver.manage().window().getSize();26 int x = size.width / 2;27 int y = size.height / 2;28 int x1 = x;29 int y1 = (int) (y * 0.20);30 int x2 = x;31 int y2 = (int) (y * 0.90);32 swipe(x1, y1, x2, y2, duration);33 }34 public void swipeDown(AndroidDriver driver, int duration) {35 Dimension size = driver.manage().window().getSize();36 int x = size.width / 2;37 int y = size.height / 2;38 int x1 = x;39 int y1 = (int) (y * 0.90);40 int x2 = x;41 int y2 = (int) (y * 0.20);42 swipe(x1, y1, x2, y2, duration);43 }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Coordinates

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful