How to use isSameIdentifier method of org.cerberus.engine.entity.Identifier class

Best Cerberus-source code snippet using org.cerberus.engine.entity.Identifier.isSameIdentifier

Source:AppiumService.java Github

copy

Full Screen

...145 @Override146 public MessageEvent click(final Session session, final Identifier identifier) {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 }394 @Override395 public MessageEvent clearField(final Session session, final Identifier identifier) {396 try {397 final TouchAction action = new TouchAction(session.getAppiumDriver());398 if (identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {399 final Coordinates coordinates = getCoordinates(identifier);400 click(session, identifier);401 } else {402 click(session, identifier);403 //action.press(ElementOption.element(getElement(session, identifier, false, false))).waitAction(WaitOptions.waitOptions(Duration.ofMillis(8000))).release().perform();404 //MobileElement element = (MobileElement) session.getAppiumDriver().findElementByAccessibilityId("SomeAccessibilityID");405 //element.clear();406 // WebElement elmt = this.getElement(session, identifier, false, false);407 ((MobileElement) this.getElement(session, identifier, false, false)).clear();408 }409 return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLEAR).resolveDescription("ELEMENT", identifier.toString());410 } catch (NoSuchElementException e) {411 if (LOG.isDebugEnabled()) {412 LOG.debug(e.getMessage());...

Full Screen

Full Screen

isSameIdentifier

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.Identifier;2import org.cerberus.engine.entity.MessageEvent;3import org.cerberus.engine.entity.MessageGeneral;4import org.cerberus.engine.entity.MessageGeneralEnum;5import org.cerberus.engine.execution.IExecutionHandlerService;6import org.cerberus.engine.execution.IExecutionService;7import org.cerberus.engine.execution.impl.ExecutionHandlerService;8import org.cerberus.engine.execution.impl.ExecutionService;9import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderService;10import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceFactory;11import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceFactoryImpl;12import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceFactoryImplTest;13import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest;14import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest2;15import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest3;16import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest4;17import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest5;18import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest6;19import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest7;20import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest8;21import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest9;22import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest10;23import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest11;24import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest12;25import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest13;26import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest14;27import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest15;28import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest16;29import org.cerberus.engine.execution.impl.resultreaderservice.ResultReaderServiceTest17;30import org.cerberus.engine.execution

Full Screen

Full Screen

isSameIdentifier

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.*;2import org.cerberus.engine.entity.impl.*;3import org.cerberus.engine.execution.*;4import org.cerberus.engine.execution.impl.*;5import org.cerberus.engine.groovy.*;6import org.cerberus.engine.groovy.impl.*;7import org.cerberus.engine.groovy.impl.GroovyCompiler;8import org.cerberus.engine.groovy.impl.GroovyExecutor;9import org.cerberus.engine.groovy.impl.GroovyInterpreter;10import org.cerberus.engine.groovy.impl.GroovyLoader;11import org.cerberus.engine.groovy.impl.GroovyParser;12import org.cerberus.engine.groovy.impl.GroovyPreCompiler;13import org.cerberus.engine.groovy.impl.GroovyPreInterpreter;14import org.cerberus.engine.groovy.impl.GroovyPreLoader;15import org.cerberus.engine.groovy.impl.GroovyPreParser;16import org.cerberus.engine.groovy.impl.GroovyPreValidator;17import org.cerberus.engine.groovy.impl.GroovyValidator;18import org.cerberus.engine.groovy.impl.GroovyVariable;19import org.cerberus.engine.groovy.impl.GroovyVariableFactory;20import org.cerberus.engine.groovy.impl.GroovyVariableFactoryImpl;21import org.cerberus.engine.groovy.impl.GroovyVariableImpl;22import org

Full Screen

Full Screen

isSameIdentifier

Using AI Code Generation

copy

Full Screen

1Identifier myIdentifier = new Identifier();2myIdentifier.setIdentifier("myIdentifier");3Identifier myIdentifier2 = new Identifier();4myIdentifier2.setIdentifier("myIdentifier2");5Identifier myIdentifier3 = new Identifier();6myIdentifier3.setIdentifier("myIdentifier");7myIdentifier.isSameIdentifier(myIdentifier2);8myIdentifier.isSameIdentifier(myIdentifier3);9myIdentifier2.isSameIdentifier(myIdentifier3);10myIdentifier.isSameIdentifier(null);11myIdentifier.isSameIdentifier(null);12myIdentifier.isSameIdentifier(null);13myIdentifier.isSameIdentifier(new Identifier());14myIdentifier.isSameIdentifier(new Identifier());15myIdentifier.isSameIdentifier(new Identifier());16myIdentifier.isSameIdentifier(null);17myIdentifier.isSameIdentifier(null);18myIdentifier.isSameIdentifier(null);19myIdentifier.isSameIdentifier("");20myIdentifier.isSameIdentifier("");21myIdentifier.isSameIdentifier("");22myIdentifier.isSameIdentifier(null);23myIdentifier.isSameIdentifier(null);24myIdentifier.isSameIdentifier(null);25myIdentifier.isSameIdentifier(" ");26myIdentifier.isSameIdentifier(" ");

Full Screen

Full Screen

isSameIdentifier

Using AI Code Generation

copy

Full Screen

1Identifier id = new Identifier("id", "name");2Identifier id2 = new Identifier("id", "name");3Identifier id3 = new Identifier("id", "name2");4Identifier id4 = new Identifier("id", "name3");5Identifier id5 = new Identifier("id", "name4");6Identifier id6 = new Identifier("id", "name5");7Identifier id7 = new Identifier("id", "name6");8Identifier id8 = new Identifier("id", "name7");9Identifier id9 = new Identifier("id", "name8");10Identifier id10 = new Identifier("id", "name9");11Identifier id11 = new Identifier("id", "name10");12Identifier id12 = new Identifier("id", "name11");13Identifier id13 = new Identifier("id", "name12");14Identifier id14 = new Identifier("id", "name13");15Identifier id15 = new Identifier("id", "name14");16Identifier id16 = new Identifier("id", "name15");17Identifier id17 = new Identifier("id", "name16");18Identifier id18 = new Identifier("id", "name17");

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful