How to use getStartsWith method of com.qaprosoft.carina.core.foundation.webdriver.locator.LocatorType class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.webdriver.locator.LocatorType.getStartsWith

Source:ExtendedWebElement.java Github

copy

Full Screen

...1036 }1037 public ExtendedWebElement format(Object... objects) {1038 String locator = by.toString();1039 By by = null;1040 if (locator.startsWith(LocatorType.ID.getStartsWith())) {1041 if (caseInsensitiveConverter != null) {1042 by = caseInsensitiveConverter.convert(by);1043 } else {1044 by = By.id(String.format(StringUtils.remove(locator, LocatorType.ID.getStartsWith()), objects));1045 }1046 }1047 if (locator.startsWith(LocatorType.NAME.getStartsWith())) {1048 if (caseInsensitiveConverter != null) {1049 by = caseInsensitiveConverter.convert(by);1050 } else {1051 by = By.id(String.format(StringUtils.remove(locator, LocatorType.NAME.getStartsWith()), objects));1052 }1053 }1054 if (locator.startsWith(LocatorType.XPATH.getStartsWith())) {1055 if (caseInsensitiveConverter != null) {1056 by = caseInsensitiveConverter.convert(by);1057 } else {1058 by = By.xpath(String.format(StringUtils.remove(locator, LocatorType.XPATH.getStartsWith()), objects));1059 }1060 }1061 if (locator.startsWith(LocatorType.LINKTEXT.getStartsWith())) {1062 if (caseInsensitiveConverter != null) {1063 by = caseInsensitiveConverter.convert(by);1064 } else {1065 by = By.xpath(String.format(StringUtils.remove(locator, LocatorType.LINKTEXT.getStartsWith()), objects));1066 }1067 }1068 if (locator.startsWith("partialLinkText: ")) {1069 by = By.partialLinkText(String.format(StringUtils.remove(locator, "partialLinkText: "), objects));1070 }1071 if (locator.startsWith("css: ")) {1072 by = By.cssSelector(String.format(StringUtils.remove(locator, "css: "), objects));1073 }1074 if (locator.startsWith("tagName: ")) {1075 by = By.tagName(String.format(StringUtils.remove(locator, "tagName: "), objects));1076 }1077 /*1078 * All ClassChain locators start from **. e.g FindBy(xpath = "**'/XCUIElementTypeStaticText[`name CONTAINS[cd] '%s'`]")1079 */1080 if (locator.startsWith("By.IosClassChain: **")) {1081 by = MobileBy.iOSClassChain(String.format(StringUtils.remove(locator, "By.IosClassChain: "), objects));1082 }1083 if (locator.startsWith("By.IosNsPredicate: **")) {1084 by = MobileBy.iOSNsPredicateString(String.format(StringUtils.remove(locator, "By.IosNsPredicate: "), objects));1085 }1086 if (locator.startsWith("By.AccessibilityId: ")) {1087 by = MobileBy.AccessibilityId(String.format(StringUtils.remove(locator, "By.AccessibilityId: "), objects));1088 }1089 if (locator.startsWith("By.Image: ")) {1090 String formattedLocator = String.format(StringUtils.remove(locator, "By.Image: "), objects);1091 Path path = Paths.get(formattedLocator);1092 LOGGER.debug("Formatted locator is : " + formattedLocator);1093 String base64image;1094 try {1095 base64image = new String(Base64.encode(Files.readAllBytes(path)));1096 } catch (IOException e) {1097 throw new RuntimeException(1098 "Error while reading image file after formatting. Formatted locator : " + formattedLocator, e);1099 }1100 LOGGER.debug("Base64 image representation has benn successfully obtained after formatting.");1101 by = MobileBy.image(base64image);1102 }1103 if (locator.startsWith("By.AndroidUIAutomator: ")) {1104 by = MobileBy.AndroidUIAutomator(String.format(StringUtils.remove(locator, "By.AndroidUIAutomator: "), objects));1105 LOGGER.debug("Formatted locator is : " + by.toString());1106 }1107 return new ExtendedWebElement(by, name, this.driver, this.searchContext, objects);1108 }1109 /**1110 * Pause for specified timeout.1111 * 1112 * @param timeout in seconds.1113 */1114 public void pause(long timeout) {1115 CommonUtils.pause(timeout);1116 }1117 public void pause(double timeout) {1118 CommonUtils.pause(timeout);1119 }1120 1121 public interface ActionSteps {1122 void doClick();1123 1124 void doClickByJs();1125 1126 void doClickByActions();1127 1128 void doDoubleClick();1129 void doRightClick();1130 1131 void doHover(Integer xOffset, Integer yOffset);1132 void doType(String text);1133 void doSendKeys(Keys keys);1134 void doAttachFile(String filePath);1135 void doCheck();1136 void doUncheck();1137 1138 boolean doIsChecked();1139 1140 String doGetText();1141 Point doGetLocation();1142 Dimension doGetSize();1143 String doGetAttribute(String name);1144 boolean doSelect(String text);1145 boolean doSelectValues(final String[] values);1146 boolean doSelectByMatcher(final BaseMatcher<String> matcher);1147 boolean doSelectByPartialText(final String partialSelectText);1148 boolean doSelectByIndex(final int index);1149 1150 String doGetSelectedValue();1151 1152 List<String> doGetSelectedValues();1153 }1154 private Object executeAction(ACTION_NAME actionName, ActionSteps actionSteps, Object... inputArgs) {1155 Object result = null;1156 switch (actionName) {1157 case CLICK:1158 actionSteps.doClick();1159 break;1160 case CLICK_BY_JS:1161 actionSteps.doClickByJs();1162 break;1163 case CLICK_BY_ACTIONS:1164 actionSteps.doClickByActions();1165 break;1166 case DOUBLE_CLICK:1167 actionSteps.doDoubleClick();1168 break;1169 case HOVER:1170 actionSteps.doHover((Integer) inputArgs[0], (Integer) inputArgs[1]);1171 break;1172 case RIGHT_CLICK:1173 actionSteps.doRightClick();1174 break;1175 case GET_TEXT:1176 result = actionSteps.doGetText();1177 break;1178 case GET_LOCATION:1179 result = actionSteps.doGetLocation();1180 break;1181 case GET_SIZE:1182 result = actionSteps.doGetSize();1183 break;1184 case GET_ATTRIBUTE:1185 result = actionSteps.doGetAttribute((String) inputArgs[0]);1186 break;1187 case SEND_KEYS:1188 actionSteps.doSendKeys((Keys) inputArgs[0]);1189 break;1190 case TYPE:1191 actionSteps.doType((String) inputArgs[0]);1192 break;1193 case ATTACH_FILE:1194 actionSteps.doAttachFile((String) inputArgs[0]);1195 break;1196 case CHECK:1197 actionSteps.doCheck();1198 break;1199 case UNCHECK:1200 actionSteps.doUncheck();1201 break;1202 case IS_CHECKED:1203 result = actionSteps.doIsChecked();1204 break;1205 case SELECT:1206 result = actionSteps.doSelect((String) inputArgs[0]);1207 break;1208 case SELECT_VALUES:1209 result = actionSteps.doSelectValues((String[]) inputArgs);1210 break;1211 case SELECT_BY_MATCHER:1212 result = actionSteps.doSelectByMatcher((BaseMatcher<String>) inputArgs[0]);1213 break;1214 case SELECT_BY_PARTIAL_TEXT:1215 result = actionSteps.doSelectByPartialText((String) inputArgs[0]);1216 break;1217 case SELECT_BY_INDEX:1218 result = actionSteps.doSelectByIndex((int) inputArgs[0]);1219 break;1220 case GET_SELECTED_VALUE:1221 result = actionSteps.doGetSelectedValue();1222 break;1223 case GET_SELECTED_VALUES:1224 result = actionSteps.doGetSelectedValues();1225 break;1226 default:1227 Assert.fail("Unsupported UI action name" + actionName.toString());1228 break;1229 }1230 return result;1231 }1232 /**1233 * doAction on element.1234 *1235 * @param actionName1236 * ACTION_NAME1237 * @param timeout1238 * long1239 * @param waitCondition1240 * to check element conditions before action1241 * @return1242 * Object1243 */1244 private Object doAction(ACTION_NAME actionName, long timeout, ExpectedCondition<?> waitCondition) {1245 // [VD] do not remove null args otherwise all actions without arguments will be broken!1246 Object nullArgs = null;1247 return doAction(actionName, timeout, waitCondition, nullArgs);1248 }1249 private Object doAction(ACTION_NAME actionName, long timeout, ExpectedCondition<?> waitCondition,1250 Object...inputArgs) {1251 1252 if (waitCondition != null) {1253 //do verification only if waitCondition is not null1254 if (!waitUntil(waitCondition, timeout)) {1255 //TODO: think about raising exception otherwise we do extra call and might wait and hangs especially for mobile/appium1256 LOGGER.error(Messager.ELEMENT_CONDITION_NOT_VERIFIED.getMessage(actionName.getKey(), getNameWithLocator()));1257 }1258 }1259 1260 if (isLocalized) {1261 isLocalized = false; // single verification is enough for this particular element1262 L10N.verify(this);1263 }1264 Object output = null;1265 try {1266 this.element = getElement();1267 output = overrideAction(actionName, inputArgs);1268 } catch (StaleElementReferenceException e) {1269 //TODO: analyze mobile testing for staled elements. Potentially it should be fixed by appium java client already1270 // sometime Appium instead printing valid StaleElementException generate java.lang.ClassCastException:1271 // com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to java.lang.String1272 LOGGER.debug("catched StaleElementReferenceException: ", e);1273 // try to find again using driver context and do action1274 element = this.findElement();1275 output = overrideAction(actionName, inputArgs);1276 }1277 return output;1278 }1279 // single place for all supported UI actions in carina core1280 private Object overrideAction(ACTION_NAME actionName, Object...inputArgs) {1281 Object output = executeAction(actionName, new ActionSteps() {1282 @Override1283 public void doClick() {1284 DriverListener.setMessages(Messager.ELEMENT_CLICKED.getMessage(getName()),1285 Messager.ELEMENT_NOT_CLICKED.getMessage(getNameWithLocator()));1286 element.click();1287 }1288 1289 @Override1290 public void doClickByJs() {1291 DriverListener.setMessages(Messager.ELEMENT_CLICKED.getMessage(getName()),1292 Messager.ELEMENT_NOT_CLICKED.getMessage(getNameWithLocator()));1293 LOGGER.info("Do click by JavascriptExecutor for element: " + getNameWithLocator());1294 JavascriptExecutor executor = (JavascriptExecutor) getDriver();1295 executor.executeScript("arguments[0].click();", element);1296 }1297 1298 @Override1299 public void doClickByActions() {1300 DriverListener.setMessages(Messager.ELEMENT_CLICKED.getMessage(getName()),1301 Messager.ELEMENT_NOT_CLICKED.getMessage(getNameWithLocator()));1302 LOGGER.info("Do click by Actions for element: " + getNameWithLocator());1303 Actions actions = new Actions(getDriver());1304 actions.moveToElement(element).click().perform();1305 } 1306 1307 @Override1308 public void doDoubleClick() {1309 DriverListener.setMessages(Messager.ELEMENT_DOUBLE_CLICKED.getMessage(getName()),1310 Messager.ELEMENT_NOT_DOUBLE_CLICKED.getMessage(getNameWithLocator()));1311 1312 WebDriver drv = getDriver();1313 Actions action = new Actions(drv);1314 action.moveToElement(element).doubleClick(element).build().perform();1315 }1316 1317 @Override1318 public void doHover(Integer xOffset, Integer yOffset) {1319 DriverListener.setMessages(Messager.ELEMENT_HOVERED.getMessage(getName()),1320 Messager.ELEMENT_NOT_HOVERED.getMessage(getNameWithLocator()));1321 1322 WebDriver drv = getDriver();1323 Actions action = new Actions(drv);1324 if (xOffset != null && yOffset!= null) {1325 action.moveToElement(element, xOffset, yOffset).build().perform();1326 } else {1327 action.moveToElement(element).build().perform();1328 }1329 }1330 1331 @Override1332 public void doSendKeys(Keys keys) {1333 DriverListener.setMessages(Messager.KEYS_SEND_TO_ELEMENT.getMessage(keys.toString(), getName()),1334 Messager.KEYS_NOT_SEND_TO_ELEMENT.getMessage(keys.toString(), getNameWithLocator()));1335 element.sendKeys(keys);1336 }1337 @Override1338 public void doType(String text) {1339 final String decryptedText = cryptoTool.decryptByPattern(text, CRYPTO_PATTERN);1340/* if (!element.getText().isEmpty()) {1341 DriverListener.setMessages(Messager.KEYS_CLEARED_IN_ELEMENT.getMessage(getName()),1342 Messager.KEYS_NOT_CLEARED_IN_ELEMENT.getMessage(getNameWithLocator()));1343 element.clear();1344 }1345*/1346 DriverListener.setMessages(Messager.KEYS_CLEARED_IN_ELEMENT.getMessage(getName()),1347 Messager.KEYS_NOT_CLEARED_IN_ELEMENT.getMessage(getNameWithLocator()));1348 element.clear();1349 String textLog = (!decryptedText.equals(text) ? "********" : text);1350 DriverListener.setMessages(Messager.KEYS_SEND_TO_ELEMENT.getMessage(textLog, getName()),1351 Messager.KEYS_NOT_SEND_TO_ELEMENT.getMessage(textLog, getNameWithLocator()));1352 element.sendKeys(decryptedText);1353 }1354 @Override1355 public void doAttachFile(String filePath) {1356 final String decryptedText = cryptoTool.decryptByPattern(filePath, CRYPTO_PATTERN);1357 String textLog = (!decryptedText.equals(filePath) ? "********" : filePath);1358 DriverListener.setMessages(Messager.FILE_ATTACHED.getMessage(textLog, getName()),1359 Messager.FILE_NOT_ATTACHED.getMessage(textLog, getNameWithLocator()));1360 ((JavascriptExecutor) getDriver()).executeScript("arguments[0].style.display = 'block';", element);1361 ((RemoteWebDriver) castDriver(getDriver())).setFileDetector(new LocalFileDetector());1362 element.sendKeys(decryptedText);1363 }1364 @Override1365 public String doGetText() {1366 String text = element.getText();1367 LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Text", text, getName()));1368 return text;1369 }1370 @Override1371 public Point doGetLocation() {1372 Point point = element.getLocation();1373 LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Location", point.toString(), getName()));1374 return point;1375 }1376 @Override1377 public Dimension doGetSize() {1378 Dimension dim = element.getSize();1379 LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Size", dim.toString(), getName()));1380 return dim;1381 }1382 @Override1383 public String doGetAttribute(String name) {1384 String attribute = element.getAttribute(name);1385 LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage(name, attribute, getName()));1386 return attribute;1387 }1388 @Override1389 public void doRightClick() {1390 DriverListener.setMessages(Messager.ELEMENT_RIGHT_CLICKED.getMessage(getName()),1391 Messager.ELEMENT_NOT_RIGHT_CLICKED.getMessage(getNameWithLocator()));1392 1393 WebDriver drv = getDriver();1394 Actions action = new Actions(drv);1395 action.moveToElement(element).contextClick(element).build().perform();1396 }1397 @Override1398 public void doCheck() {1399 DriverListener.setMessages(Messager.CHECKBOX_CHECKED.getMessage(getName()), null);1400 1401 boolean isSelected = element.isSelected();1402 if (element.getAttribute("checked") != null) {1403 isSelected |= element.getAttribute("checked").equalsIgnoreCase("true");1404 }1405 1406 if (!isSelected) {1407 click();1408 }1409 }1410 @Override1411 public void doUncheck() {1412 DriverListener.setMessages(Messager.CHECKBOX_UNCHECKED.getMessage(getName()), null);1413 1414 boolean isSelected = element.isSelected();1415 if (element.getAttribute("checked") != null) {1416 isSelected |= element.getAttribute("checked").equalsIgnoreCase("true");1417 }1418 1419 if (isSelected) {1420 click();1421 }1422 }1423 1424 @Override1425 public boolean doIsChecked() {1426 1427 boolean res = element.isSelected();1428 if (element.getAttribute("checked") != null) {1429 res |= element.getAttribute("checked").equalsIgnoreCase("true");1430 }1431 1432 return res;1433 }1434 1435 @Override1436 public boolean doSelect(String text) {1437 final String decryptedSelectText = cryptoTool.decryptByPattern(text, CRYPTO_PATTERN);1438 1439 String textLog = (!decryptedSelectText.equals(text) ? "********" : text);1440 1441 DriverListener.setMessages(Messager.SELECT_BY_TEXT_PERFORMED.getMessage(textLog, getName()),1442 Messager.SELECT_BY_TEXT_NOT_PERFORMED.getMessage(textLog, getNameWithLocator()));1443 1444 final Select s = new Select(getElement());1445 // [VD] do not use selectByValue as modern controls could have only visible value without value1446 s.selectByVisibleText(decryptedSelectText);1447 return true;1448 }1449 @Override1450 public boolean doSelectValues(String[] values) {1451 boolean result = true;1452 for (String value : values) {1453 if (!select(value)) {1454 result = false;1455 }1456 }1457 return result;1458 }1459 @Override1460 public boolean doSelectByMatcher(BaseMatcher<String> matcher) {1461 1462 DriverListener.setMessages(Messager.SELECT_BY_MATCHER_TEXT_PERFORMED.getMessage(matcher.toString(), getName()),1463 Messager.SELECT_BY_MATCHER_TEXT_NOT_PERFORMED.getMessage(matcher.toString(), getNameWithLocator()));1464 1465 final Select s = new Select(getElement());1466 String fullTextValue = null;1467 for (WebElement option : s.getOptions()) {1468 if (matcher.matches(option.getText())) {1469 fullTextValue = option.getText();1470 break;1471 }1472 }1473 s.selectByVisibleText(fullTextValue);1474 return true;1475 }1476 @Override1477 public boolean doSelectByPartialText(String partialSelectText) {1478 1479 DriverListener.setMessages(1480 Messager.SELECT_BY_TEXT_PERFORMED.getMessage(partialSelectText, getName()),1481 Messager.SELECT_BY_TEXT_NOT_PERFORMED.getMessage(partialSelectText, getNameWithLocator()));1482 1483 final Select s = new Select(getElement());1484 String fullTextValue = null;1485 for (WebElement option : s.getOptions()) {1486 if (option.getText().contains(partialSelectText)) {1487 fullTextValue = option.getText();1488 break;1489 }1490 }1491 s.selectByVisibleText(fullTextValue);1492 return true;1493 }1494 @Override1495 public boolean doSelectByIndex(int index) {1496 DriverListener.setMessages(1497 Messager.SELECT_BY_INDEX_PERFORMED.getMessage(String.valueOf(index), getName()),1498 Messager.SELECT_BY_INDEX_NOT_PERFORMED.getMessage(String.valueOf(index), getNameWithLocator()));1499 1500 1501 final Select s = new Select(getElement());1502 s.selectByIndex(index);1503 return true;1504 }1505 @Override1506 public String doGetSelectedValue() {1507 final Select s = new Select(getElement());1508 return s.getAllSelectedOptions().get(0).getText();1509 }1510 @Override1511 public List<String> doGetSelectedValues() {1512 final Select s = new Select(getElement());1513 List<String> values = new ArrayList<String>();1514 for (WebElement we : s.getAllSelectedOptions()) {1515 values.add(we.getText());1516 }1517 return values;1518 }1519 1520 }, inputArgs);1521 return output;1522 }1523 public WebDriver getDriver() {1524 if (driver == null) {1525 LOGGER.error("There is no any initialized driver for ExtendedWebElement: " + getNameWithLocator());1526 throw new RuntimeException(1527 "Driver isn't initialized. Review stacktrace to analyze why driver is not populated correctly via reflection!");1528 }1529 return driver;1530 }1531 1532 private WebDriver castDriver(WebDriver drv) {1533 if (drv instanceof EventFiringWebDriver) {1534 drv = ((EventFiringWebDriver) drv).getWrappedDriver();1535 }1536 return drv;1537 }1538 1539 //TODO: investigate how can we merge the similar functionality in ExtendedWebElement, DriverHelper and LocalizedAnnotations1540 public By generateByForList(By by, int index) {1541 String locator = by.toString();1542 By resBy = null;1543 if (locator.startsWith(LocatorType.ID.getStartsWith())) {1544 resBy = By.id(StringUtils.remove(locator, LocatorType.ID.getStartsWith()) + "[" + index + "]");1545 }1546 if (locator.startsWith(LocatorType.NAME.getStartsWith())) {1547 resBy = By.name(StringUtils.remove(locator, LocatorType.NAME.getStartsWith()) + "[" + index + "]");1548 }1549 if (locator.startsWith(LocatorType.XPATH.getStartsWith())) {1550 resBy = By.xpath(StringUtils.remove(locator, LocatorType.XPATH.getStartsWith()) + "[" + index + "]");1551 }1552 if (locator.startsWith(LocatorType.LINKTEXT.getStartsWith())) {1553 resBy = By.linkText(StringUtils.remove(locator, LocatorType.LINKTEXT.getStartsWith()) + "[" + index + "]");1554 }1555 if (locator.startsWith("partialLinkText: ")) {1556 resBy = By.partialLinkText(StringUtils.remove(locator, "partialLinkText: ") + "[" + index + "]");1557 }1558 if (locator.startsWith("css: ")) {1559 resBy = By.cssSelector(StringUtils.remove(locator, "css: ") + ":nth-child(" + index + ")");1560 }1561 1562 if (locator.startsWith("By.cssSelector: ")) {1563 resBy = By.cssSelector(StringUtils.remove(locator, "By.cssSelector: ") + ":nth-child(" + index + ")");1564 }1565 if (locator.startsWith("tagName: ")) {1566 resBy = By.tagName(StringUtils.remove(locator, "tagName: ") + "[" + index + "]");1567 }...

Full Screen

Full Screen

Source:CaseInsensitiveConverter.java Github

copy

Full Screen

...37 }38 private By convertToXpath(By by) {39 By byToConvert = by;40 String locator = by.toString();41 if (locator.startsWith(LocatorType.ID.getStartsWith())) {42 byToConvert = platformDependsConverter.idToXpath(byToConvert);43 }44 if (locator.startsWith(LocatorType.NAME.getStartsWith())) {45 byToConvert = platformDependsConverter.nameToXpath(byToConvert);46 }47 if (locator.startsWith(LocatorType.LINKTEXT.getStartsWith())) {48 byToConvert = platformDependsConverter.linkTextToXpath(byToConvert);49 }50 return byToConvert;51 }52 private By convertXPathToCaseInsensitive(By by) {53 By byToConvert = by;54 if (paramsToConvert.isId()) {55 byToConvert = platformDependsConverter.xpathIdCaseInsensitive(byToConvert);56 }57 if (paramsToConvert.isName()) {58 byToConvert = platformDependsConverter.xpathNameCaseInsensitive(byToConvert);59 }60 if (paramsToConvert.isText()) {61 byToConvert = platformDependsConverter.xpathTextCaseInsensitive(byToConvert);62 }63 if (paramsToConvert.isClassAttr()) {64 byToConvert = platformDependsConverter.xpathClassCaseInsensitive(byToConvert);65 }66 return byToConvert;67 }68 private IPlatformDependsConverter getConverterDependsOnPlatform(Platform platform) {69 IPlatformDependsConverter converter;70 switch (platform) {71 case WEB:72 converter = new WebCaseInsensitiveConverter();73 break;74 case MOBILE:75 converter = new MobileCaseInsensitiveConverter();76 break;77 default:78 throw new InvalidArgumentException("Platform " + platform + " is not supported");79 }80 return converter;81 }82 private boolean isConvertibleToXpath(By by) {83 String locator = by.toString();84 return listOfConvertableLocators.stream()85 .anyMatch(locatorType -> locator.startsWith(locatorType.getStartsWith()));86 }87 public void setParamsToConvert(ParamsToConvert paramsToConvert) {88 this.paramsToConvert = paramsToConvert;89 }90}...

Full Screen

Full Screen

Source:AbstractPlatformDependsConverter.java Github

copy

Full Screen

...9 // Can be used for any type of locator except xpath10 protected static final String ATTRIBUTE_SINGLE_PATTERN = "^.*$";11 protected By caseInsensitiveXpathByAttribute(By by, String attributeRegex) {12 String locator = by.toString();13 String cleanXPath = StringUtils.remove(locator, LocatorType.XPATH.getStartsWith());14 String attributePattern =15 "(?<!(translate\\())((" + attributeRegex + ")\\s*(\\,|\\=)\\s*((['\"])((?:(?!\\6|\\\\).|\\\\.)*)\\6))";16 Matcher matcher = Pattern.compile(attributePattern)17 .matcher(cleanXPath);18 StringBuilder sb = new StringBuilder();19 while (matcher.find()) {20 String replacement = createTranslateWithParameters(matcher.group(3), matcher.group(7),21 matcher.group(6), matcher.group(4));22 matcher.appendReplacement(sb, replacement);23 }24 matcher.appendTail(sb);25 return By.xpath(sb.toString());26 }27 protected String createXpathFromAnotherTypeOfLocator(String context, String tag, String attribute,28 String quote, String value) {29 return context + "//" + tag + "[" + attribute + "=" + quote + value + quote + "]";30 }31 protected String createTranslateWithParameters(String attribute, String value, String quote, String delimiter) {32 return ("translate(" + attribute + ", " + quote + value.toUpperCase() + quote + ", " + quote33 + value.toLowerCase() + quote + ")" + delimiter34 + "translate(" + quote + value + quote + ", " + quote + value.toUpperCase()35 + quote + ", " + quote + value.toLowerCase() + quote36 + ")")37 // Used to escape special symbol $ to be visible in result xpath38 .replaceAll("\\$", "\\\\\\$")39 // Because after translating it will be upper-case40 .replaceAll("%S", "%s");41 }42 protected By locatorToXpath(By by, LocatorType locatorType, UnaryOperator<String> replacementFunc) {43 String cleanXPath = StringUtils.remove(by.toString(), locatorType.getStartsWith());44 Matcher matcher = Pattern.compile(ATTRIBUTE_SINGLE_PATTERN)45 .matcher(cleanXPath);46 StringBuilder sb = new StringBuilder();47 while (matcher.find()) {48 String replacement = replacementFunc.apply(matcher.group());49 matcher.appendReplacement(sb, replacement);50 }51 matcher.appendTail(sb);52 return By.xpath(sb.toString());53 }54}...

Full Screen

Full Screen

getStartsWith

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import com.qaprosoft.carina.core.foundation.webdriver.locator.LocatorType;9public class StartsWith {10public static void main(String[] args) {11 System.setProperty("webdriver.chrome.driver", "C:\\Users\\kavitha\\Downloads\\chromedriver_win32\\chromedriver.exe");12 WebDriver driver = new ChromeDriver();13 WebDriverWait wait = new WebDriverWait(driver, 10);14 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(LocatorType.getStartsWith("q"))));15 WebElement searchBox = driver.findElement(By.xpath(LocatorType.getStartsWith("q")));16 searchBox.sendKeys("Carina");17 WebElement searchButton = driver.findElement(By.xpath(LocatorType.getStartsWith("btnK")));18 searchButton.click();19 driver.close();20}21}22LocatorType.getEndsWith() method23public static String getEndsWith(String locator)24package com.qaprosoft.carina.demo;25import org.openqa.selenium.By;26import org.openqa.selenium.WebDriver;27import org.openqa.selenium.WebElement;28import org.openqa.selenium.chrome.ChromeDriver;29import org.openqa.selenium.support.ui.ExpectedConditions;30import org.openqa.selenium.support.ui.WebDriverWait;31import com.qaprosoft.carina.core.foundation.webdriver.locator.LocatorType;32public class EndsWith {33public static void main(String[] args) {34 System.setProperty("webdriver.chrome.driver", "C:\\Users\\kavitha\\Downloads\\chromedriver_win32\\chromedriver.exe");35 WebDriver driver = new ChromeDriver();36 WebDriverWait wait = new WebDriverWait(driver, 10);37 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(LocatorType.getEndsWith("q"))));

Full Screen

Full Screen

getStartsWith

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo.gui.pages;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.support.FindBy;4import org.openqa.selenium.support.ui.ExpectedConditions;5import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;6import com.qaprosoft.carina.core.gui.AbstractPage;7public class HomePage extends AbstractPage {8 private ExtendedWebElement signIn;9 public HomePage(WebDriver driver) {10 super(driver);11 }12 public LoginPage openLoginPage() {13 signIn.click();14 return new LoginPage(driver);15 }16 public boolean isPageOpened() {17 && getDriver().getTitle().equals("My Store");18 }19 public boolean isLoginLinkPresent() {20 return signIn.isPresent();21 }22 public boolean isPageOpened(int timeoutInSec) {23 && wait.until(ExpectedConditions.titleIs("My Store"));24 }25}26package com.qaprosoft.carina.demo.gui.pages;27import org.openqa.selenium.WebDriver;28import org.openqa.selenium.support.FindBy;29import org.openqa.selenium.support.ui.ExpectedConditions;30import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;31import com.qaprosoft.carina.core.gui.AbstractPage;32public class HomePage extends AbstractPage {33 private ExtendedWebElement signIn;34 public HomePage(WebDriver driver) {35 super(driver);36 }37 public LoginPage openLoginPage() {38 signIn.click();39 return new LoginPage(driver);40 }41 public boolean isPageOpened() {42 && getDriver().getTitle().equals("My Store");43 }44 public boolean isLoginLinkPresent() {45 return signIn.isPresent();46 }

Full Screen

Full Screen

getStartsWith

Using AI Code Generation

copy

Full Screen

1import org.testng.Assert;2import org.testng.annotations.Test;3import com.qaprosoft.carina.core.foundation.webdriver.locator.LocatorType;4public class LocatorTypeTest {5 public void testStartsWith() {6 Assert.assertTrue(LocatorType.getStartsWith("xpath").equals("xpath"));7 Assert.assertTrue(LocatorType.getStartsWith("id").equals("id"));8 Assert.assertTrue(LocatorType.getStartsWith("css").equals("css"));9 Assert.assertTrue(LocatorType.getStartsWith("name").equals("name"));10 Assert.assertTrue(LocatorType.getStartsWith("tag").equals("tag"));11 Assert.assertTrue(LocatorType.getStartsWith("class").equals("class"));12 Assert.assertTrue(LocatorType.getStartsWith("link").equals("link"));13 Assert.assertTrue(LocatorType.getStartsWith("partial").equals("partial"));14 Assert.assertTrue(LocatorType.getStartsWith("sizzle").equals("sizzle"));15 Assert.assertTrue(LocatorType.getStartsWith("jquery").equals("jquery"));16 Assert.assertTrue(LocatorType.getStartsWith("dom").equals("dom"));17 Assert.assertTrue(LocatorType.getStartsWith("angular").equals("angular"));18 Assert.assertTrue(LocatorType.getStartsWith("ui").equals("ui"));19 Assert.assertTrue(LocatorType.getStartsWith("ui=css").equals("ui=css"));20 Assert.assertTrue(LocatorType.getStartsWith("ui=jquery").equals("ui=jquery"));21 Assert.assertTrue(LocatorType.getStartsWith("ui=angular").equals("ui=angular"));22 Assert.assertTrue(LocatorType.getStartsWith("ui=jquery=css").equals("ui=jquery=css"));23 Assert.assertTrue(LocatorType.getStartsWith("ui=jquery=angular").equals("ui=jquery=angular"));24 Assert.assertTrue(LocatorType.getStartsWith("ui=angular=css").equals("ui=angular=css"));25 Assert.assertTrue(LocatorType.getStartsWith("ui=angular=jquery").equals("ui=angular=jquery"));26 Assert.assertTrue(LocatorType.getStartsWith("ui=jquery=angular=css").equals("ui=jquery=angular=css"));27 Assert.assertTrue(LocatorType.getStartsWith("ui=angular=jquery=css").equals("ui=angular=jquery=css"));28 Assert.assertTrue(LocatorType.getStartsWith("ui=angular=css=jquery").equals("ui=angular=css=jquery"));29 Assert.assertTrue(LocatorType.getStartsWith("ui=css=angular=jquery").equals("ui=css=angular=jquery"));

Full Screen

Full Screen

getStartsWith

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.locator.LocatorType;2LocatorType locatorType = LocatorType.getStartsWith("id");3System.out.println("Locator Type: " + locatorType);4import com.qaprosoft.carina.core.foundation.webdriver.locator.LocatorType;5LocatorType locatorType = LocatorType.getEndsWith("id");6System.out.println("Locator Type: " + locatorType);7import com.qaprosoft.carina.core.foundation.webdriver.locator.LocatorType;8LocatorType locatorType = LocatorType.getContains("id");9System.out.println("Locator Type: " + locatorType);10import com.qaprosoft.carina.core.foundation.webdriver.locator.LocatorType;11LocatorType locatorType = LocatorType.getEquals("id");12System.out.println("Locator Type: " + locatorType);13import com.qaprosoft.carina.core.foundation.webdriver.locator.LocatorType;14LocatorType locatorType = LocatorType.getEndsWith("id");15System.out.println("Locator Type: " + locatorType);16import com.qaprosoft.carina.core.foundation.webdriver.locator.LocatorType;17LocatorType locatorType = LocatorType.getEquals("id");18System.out.println("Locator Type: " + locatorType);19import com.qaprosoft.carina.core.foundation.webdriver.locator.L

Full Screen

Full Screen

getStartsWith

Using AI Code Generation

copy

Full Screen

1public class 1 {2 public static void main(String[] args) {3 String prefix = LocatorType.getStartsWith(locator);4 System.out.println(prefix);5 }6}7public class 2 {8 public static void main(String[] args) {9 String prefix = LocatorType.getStartsWith(locator);10 System.out.println(prefix);11 }12}13public class 3 {14 public static void main(String[] args) {15 String prefix = LocatorType.getStartsWith(locator);16 System.out.println(prefix);17 }18}19public class 4 {20 public static void main(String[] args) {21 String prefix = LocatorType.getStartsWith(locator);22 System.out.println(prefix);23 }24}25public class 5 {26 public static void main(String[] args) {27 String prefix = LocatorType.getStartsWith(locator);28 System.out.println(prefix);29 }30}31public class 6 {32 public static void main(String[] args) {33 String prefix = LocatorType.getStartsWith(locator);34 System.out.println(prefix);35 }36}37public class 7 {38 public static void main(String[] args) {

Full Screen

Full Screen

getStartsWith

Using AI Code Generation

copy

Full Screen

1public void getStartsWith() {2 LocatorType locatorType = LocatorType.XPATH;3 System.out.println("The locator is: " + locator);4}5public void getContains() {6 LocatorType locatorType = LocatorType.XPATH;7 System.out.println("The locator is: " + locator);8}9public void getEndsWith() {10 LocatorType locatorType = LocatorType.XPATH;11 System.out.println("The locator is: " + locator);12}13public void getStartsWith() {14 LocatorType locatorType = LocatorType.XPATH;15 System.out.println("The locator is: " + locator);16}17public void getContains() {18 LocatorType locatorType = LocatorType.XPATH;19 System.out.println("The locator is: " + locator);20}21public void getEndsWith() {22 LocatorType locatorType = LocatorType.XPATH;23 System.out.println("The locator is: " + locator);24}25public void getStartsWith() {26 LocatorType locatorType = LocatorType.XPATH;

Full Screen

Full Screen

getStartsWith

Using AI Code Generation

copy

Full Screen

1public void test() {2 LocatorType locatorType = LocatorType.getStartsWith("xpath");3 Assert.assertEquals(locatorType, LocatorType.XPATH);4}5public void test() {6 LocatorType locatorType = LocatorType.getStartsWith("id");7 Assert.assertEquals(locatorType, LocatorType.ID);8}9public void test() {10 LocatorType locatorType = LocatorType.getStartsWith("name");11 Assert.assertEquals(locatorType, LocatorType.NAME);12}13public void test() {14 LocatorType locatorType = LocatorType.getStartsWith("class");15 Assert.assertEquals(locatorType, LocatorType.CLASS);16}17public void test() {18 LocatorType locatorType = LocatorType.getStartsWith("css");19 Assert.assertEquals(locatorType, LocatorType.CSS);20}

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 Carina automation tests on LambdaTest cloud grid

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

Most used method in LocatorType

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful