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

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

Source:AppiumService.java Github

copy

Full Screen

...91 action.press(this.getElement(session, identifier, false, false)).release().perform();92 session.getAppiumDriver().getKeyboard().pressKey(property);93 }94 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TYPE);95 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));96 if (!StringUtil.isNull(property)) {97 message.setDescription(message.getDescription().replace("%DATA%", ParameterParserUtil.securePassword(property, propertyName)));98 } else {99 message.setDescription(message.getDescription().replace("%DATA%", "No property"));100 }101 return message;102 } catch (NoSuchElementException exception) {103 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE_NO_SUCH_ELEMENT);104 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));105 LOG.debug(exception.toString());106 return message;107 } catch (WebDriverException exception) {108 LOG.fatal(exception.toString());109 return parseWebDriverException(exception);110 }111 }112 @Override113 public MessageEvent click(final Session session, final Identifier identifier) {114 try {115 final TouchAction action = new TouchAction(session.getAppiumDriver());116 if (identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {117 final Coordinates coordinates = getCoordinates(identifier);118 action.tap(coordinates.getX(), coordinates.getY()).perform();119 } else {120 action.tap(getElement(session, identifier, false, false)).perform();121 }122 return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICK).resolveDescription("ELEMENT", identifier.toString());123 } catch (NoSuchElementException e) {124 if (LOG.isDebugEnabled()) {125 LOG.debug(e.getMessage());126 }127 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK_NO_SUCH_ELEMENT).resolveDescription("ELEMENT", identifier.toString());128 } catch (WebDriverException e) {129 LOG.warn(e.getMessage());130 return parseWebDriverException(e);131 }132 }133 /**134 * @author vertigo17135 * @param exception the exception need to be parsed by Cerberus136 * @return A new Event Message with selenium related description137 */138 private MessageEvent parseWebDriverException(WebDriverException exception) {139 MessageEvent mes;140 LOG.fatal(exception.toString());141 mes = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY);142 mes.setDescription(mes.getDescription().replace("%ERROR%", exception.getMessage().split("\n")[0]));143 return mes;144 }145 /**146 * Get the {@link Coordinates} represented by the given {@link Identifier}147 *148 * @param identifier the {@link Identifier} to parse to get the149 * {@link Coordinates}150 * @return the {@link Coordinates} represented by the given151 * {@link Identifier}152 * @throws NoSuchElementException if no {@link Coordinates} can be found153 * inside the given {@link Identifier}154 */155 private Coordinates getCoordinates(final Identifier identifier) {156 if (identifier == null || !identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {157 throw new NoSuchElementException("Unable to get coordinates from a non coordinates identifier");158 }159 final Matcher coordinates = Identifier.Identifiers.COORDINATE_VALUE_PATTERN.matcher(identifier.getLocator());160 if (!coordinates.find()) {161 throw new NoSuchElementException("Bad coordinates format");162 }163 try {164 return new Coordinates(165 Integer.valueOf(coordinates.group("xCoordinate")),166 Integer.valueOf(coordinates.group("yCoordinate"))167 );168 } catch (NumberFormatException e) {169 throw new NoSuchElementException("Bad coordinates format", e);170 }171 }172 private By getBy(Identifier identifier) {173 LOG.debug("Finding selenium Element : " + identifier.getLocator() + " by : " + identifier.getIdentifier());174 if (identifier.getIdentifier().equalsIgnoreCase("id")) {175 return By.id(identifier.getLocator());176 } else if (identifier.getIdentifier().equalsIgnoreCase("name")) {177 return By.name(identifier.getLocator());178 } else if (identifier.getIdentifier().equalsIgnoreCase("class")) {179 return By.className(identifier.getLocator());180 } else if (identifier.getIdentifier().equalsIgnoreCase("css")) {181 return By.cssSelector(identifier.getLocator());182 } else if (identifier.getIdentifier().equalsIgnoreCase("xpath")) {183 return By.xpath(identifier.getLocator());184 } else if (identifier.getIdentifier().equalsIgnoreCase("link")) {185 return By.linkText(identifier.getLocator());186 } else if (identifier.getIdentifier().equalsIgnoreCase("data-cerberus")) {187 return By.xpath("//*[@data-cerberus='" + identifier.getLocator() + "']");188 } else {189 throw new NoSuchElementException(identifier.getIdentifier());190 }191 }192 private WebElement getElement(Session session, Identifier identifier, boolean visible, boolean clickable) {193 AppiumDriver driver = session.getAppiumDriver();194 By locator = this.getBy(identifier);195 LOG.debug("Waiting for Element : " + identifier.getIdentifier() + "=" + identifier.getLocator());196 try {197 WebDriverWait wait = new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(session.getCerberus_appium_wait_element()));198 if (visible) {199 if (clickable) {200 wait.until(ExpectedConditions.elementToBeClickable(locator));201 } else {202 wait.until(ExpectedConditions.visibilityOfElementLocated(locator));203 }204 } else {205 wait.until(ExpectedConditions.presenceOfElementLocated(locator));206 }207 } catch (TimeoutException exception) {208 LOG.fatal("Exception waiting for element :" + exception.toString());209 throw new NoSuchElementException(identifier.getIdentifier() + "=" + identifier.getLocator());210 }211 LOG.debug("Finding Element : " + identifier.getIdentifier() + "=" + identifier.getLocator());212 return driver.findElement(locator);213 }214 /**215 *216 * @param session217 * @param action218 * @return219 * @throws IllegalArgumentException220 */221 @Override222 public Direction getDirectionForSwipe(Session session, SwipeAction action) throws IllegalArgumentException {223 Dimension window = session.getAppiumDriver().manage().window().getSize();224 SwipeAction.Direction direction;225 switch (action.getActionType()) {...

Full Screen

Full Screen

getLocator

Using AI Code Generation

copy

Full Screen

1public void getLocator(String locator) {2 String[] locatorArray = locator.split("=");3 String locatorType = locatorArray[0];4 String locatorValue = locatorArray[1];5 System.out.println(locatorType);6 System.out.println(locatorValue);7}8at org.cerberus.engine.entity.Identifier.getLocator(Identifier.java:35)9at org.cerberus.engine.entity.Identifier.main(Identifier.java:26)10Java(TM) SE Runtime Environment (build 1.8.0_171-b11)11Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)12IntelliJ IDEA 2019.2.2 (Ultimate Edition)

Full Screen

Full Screen

getLocator

Using AI Code Generation

copy

Full Screen

1Identifier identifier = new Identifier();2identifier.setIdentifier("login");3identifier.setIdentifierType("name");4Identifier identifier = new Identifier();5identifier.setIdentifier("login");6identifier.setIdentifierType("name");7WebElement element = identifier.getIdentifier(driver);8Identifier identifier = new Identifier();9identifier.setIdentifier("login");10identifier.setIdentifierType("name");11WebElement element = identifier.getIdentifier(driver, "login");12Identifier identifier = new Identifier();13identifier.setIdentifier("login");14identifier.setIdentifierType("name");15WebElement element = identifier.getIdentifier(driver, "login", "name");16Identifier identifier = new Identifier();17identifier.setIdentifier("login");18identifier.setIdentifierType("name");19WebElement element = identifier.getIdentifier(driver, "login", "name", 10);20Identifier identifier = new Identifier();21identifier.setIdentifier("login");22identifier.setIdentifierType("name");23WebElement element = identifier.getIdentifier(driver, "login", "name", 10, 100);24Identifier identifier = new Identifier();25identifier.setIdentifier("login");26identifier.setIdentifierType("name");27WebElement element = identifier.getIdentifier(driver, "login", "name", 10, 100, "login");28Identifier identifier = new Identifier();29identifier.setIdentifier("login");30identifier.setIdentifierType("name");31WebElement element = identifier.getIdentifier(driver, "login", "name", 10, 100, "login", "login");32Identifier identifier = new Identifier();33identifier.setIdentifier("login");34identifier.setIdentifierType("name");35WebElement element = identifier.getIdentifier(driver, "login", "name", 10,

Full Screen

Full Screen

getLocator

Using AI Code Generation

copy

Full Screen

1String locator = getLocator("myElement");2WebElement element = driver.findElement(By.xpath(locator));3WebElement element = driver.findElement(By.xpath(getLocator("myElement")));4WebElement element = driver.findElement(getLocator("myElement"));5WebElement element = driver.findElement(getLocator("myElement", "myPage"));6WebElement element = driver.findElement(getLocator("myElement", "myPage", "myApplication"));7WebElement element = driver.findElement(getLocator("myElement", "myPage", "myApplication", "myCountry"));8WebElement element = driver.findElement(getLocator("myElement", "myPage", "myApplication", "myCountry", "myEnvironment"));9WebElement element = driver.findElement(getLocator("myElement", "myPage", "myApplication", "myCountry", "myEnvironment", "myBrowser"));10WebElement element = driver.findElement(getLocator("myElement", "myPage", "myApplication", "myCountry", "myEnvironment", "myBrowser", "myPlatform"));11WebElement element = driver.findElement(getLocator("myElement", "myPage", "myApplication", "myCountry", "myEnvironment", "myBrowser", "myPlatform", "myTag"));12WebElement element = driver.findElement(getLocator("myElement", "myPage", "myApplication", "myCountry", "myEnvironment", "myBrowser", "myPlatform", "myTag", "myScreenSize"));13WebElement element = driver.findElement(getLocator("myElement", "myPage", "myApplication", "myCountry", "myEnvironment", "myBrowser", "myPlatform", "myTag", "myScreenSize", "myVersion"));14WebElement element = driver.findElement(getLocator("myElement", "myPage", "myApplication", "myCountry", "myEnvironment", "myBrowser", "myPlatform", "myTag", "

Full Screen

Full Screen

getLocator

Using AI Code Generation

copy

Full Screen

1public String getLocator(Identifier identifier) {2 String locator = null;3 switch (identifier.getType()) {4 locator = "id:" + identifier.getValue();5 break;6 locator = "name:" + identifier.getValue();7 break;8 locator = "css:" + identifier.getValue();9 break;10 locator = "xpath:" + identifier.getValue();11 break;12 locator = "linkText:" + identifier.getValue();13 break;14 locator = "partialLinkText:" + identifier.getValue();15 break;16 locator = "tagName:" + identifier.getValue();17 break;18 locator = "className:" + identifier.getValue();19 break;20 }21 return locator;22}23public String getIdentifier(Identifier identifier) {24 String identifierValue = null;25 switch (identifier.getType()) {26 identifierValue = "id=" + identifier.getValue();27 break;28 identifierValue = "name=" + identifier.getValue();29 break;30 identifierValue = "css=" + identifier.getValue();31 break;32 identifierValue = "xpath=" + identifier.getValue();33 break;34 identifierValue = "linkText=" + identifier.getValue();35 break;36 identifierValue = "partialLinkText=" + identifier.getValue();37 break;38 identifierValue = "tagName=" + identifier.getValue();39 break;40 identifierValue = "className=" + identifier.getValue();41 break;42 }43 return identifierValue;44}45public String getIdentifier(Identifier identifier) {

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