How to use toString method of io.appium.java_client.MobileBy.ByIosNsPredicate class

Best io.appium code snippet using io.appium.java_client.MobileBy.ByIosNsPredicate.toString

SmartAnnotations.java

Source:SmartAnnotations.java Github

copy

Full Screen

...137 private static String getValue(Annotation annotation,138 Strategies strategy) {139 try {140 Method m = annotation.getClass().getMethod(strategy.valueName, DEFAULT_ANNOTATION_METHOD_ARGUMENTS);141 return m.invoke(annotation, new Object[]{}).toString();142 } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {143 throw new RuntimeException(e);144 }145 }146 org.openqa.selenium.By getBy(Annotation annotation) {147 return null;148 }149 }150 public SmartAnnotations(Field field, MobilePlatform platform) {151 this(field, platform, WebDriverInjectors.getInjector().getInstance(CustomFindByAnnotationProviderService.class));152 }153 public SmartAnnotations(Field field, MobilePlatform platform,154 CustomFindByAnnotationProviderService customFindByAnnotationProviderService) {155 super(field);156 this.field = field;157 this.platform = platform;158 this.customFindByAnnotationProviderService = customFindByAnnotationProviderService;159 }160 protected void assertValidAnnotations() {161 FindBys findBys = field.getAnnotation(FindBys.class);162 FindBy myFindBy = field.getAnnotation(FindBy.class);163 // START - [dep1] *** todo [deprecate thucydides] Remove this check once thucydides package name removed164 net.thucydides.core.annotations.findby.FindBy myDepFindBy = field.getAnnotation(net.thucydides.core.annotations.findby.FindBy.class);165 if (myDepFindBy != null && myFindBy != null) {166 throw new IllegalArgumentException(("Do not combine the serenitybdd and thucydides namespace. The thucydides namespace is now deprecated, so please convert."));167 }168 if (findBys != null && myDepFindBy != null) {169 throw new IllegalArgumentException("If you use a '@FindBys' annotation, "170 + "you must not also use a '@FindBy' annotation");171 }172 // END - [dep1] *** [deprecated thucydides]173 if (findBys != null && myFindBy != null) {174 throw new IllegalArgumentException("If you use a '@FindBys' annotation, "175 + "you must not also use a '@FindBy' annotation");176 }177 }178 // @Override179 public org.openqa.selenium.By buildBy() {180 assertValidAnnotations();181 org.openqa.selenium.By by = null;182 // appium additions183 AndroidFindBy androidBy = field.getAnnotation(AndroidFindBy.class);184 if (androidBy != null && ANDROID.toUpperCase().equals(platform.name())) {185 by = getMobileBy(androidBy, getFieldValue(androidBy));186 }187 AndroidFindBys androidBys = field.getAnnotation(AndroidFindBys.class);188 if (androidBys != null && ANDROID.toUpperCase().equals(platform.name())) {189 by = getComplexMobileBy(androidBys.value(), ByChained.class);190 }191 AndroidFindAll androidFindAll = field.getAnnotation(AndroidFindAll.class);192 if (androidFindAll != null && ANDROID.toUpperCase().equals(platform.name())) {193 by = getComplexMobileBy(androidFindAll.value(), ByChained.class);194 }195 iOSXCUITFindBy iOSBy = field.getAnnotation(iOSXCUITFindBy.class);196 if (iOSBy != null && IOS.toUpperCase().equals(platform.name())) {197 by = getMobileBy(iOSBy, getFieldValue(iOSBy));198 }199 iOSXCUITFindBys iOSBys = field.getAnnotation(iOSXCUITFindBys.class);200 if (iOSBys != null && IOS.toUpperCase().equals(platform.name())) {201 by = getComplexMobileBy(iOSBys.value(), ByChained.class);202 }203 iOSXCUITFindAll iOSXCUITFindAll = field.getAnnotation(iOSXCUITFindAll.class);204 if (iOSXCUITFindAll != null && IOS.toUpperCase().equals(platform.name())) {205 by = getComplexMobileBy(iOSXCUITFindAll.value(), ByChained.class);206 }207 //my additions to FindBy208 FindBy myFindBy = field.getAnnotation(FindBy.class);209 if (by == null && myFindBy != null) {210 by = buildByFromFindBy(myFindBy);211 }212 // START - [deo2] *** todo [deprecate thucydides] Remove this code once thucydides package name removed213 //my additions to FindBy214 net.thucydides.core.annotations.findby.FindBy myDepFindBy = field.getAnnotation(net.thucydides.core.annotations.findby.FindBy.class);215 if (by == null && myDepFindBy != null) {216 by = buildByFromFindBy(myDepFindBy);217 }218 //END - [dep2] ***219// FindBys thucydidesBys = field.getAnnotation(FindBys.class);220// if (thucydidesBys != null) {221// by = buildByFromFindBys(thucydidesBys);222// }223//224// // default implementation in case if org.openqa.selenium.support.FindBy was used225// org.openqa.selenium.support.FindBy seleniumBy = field.getAnnotation(org.openqa.selenium.support.FindBy.class);226// if (seleniumBy != null) {227// by = super.buildByFromFindBy(seleniumBy);228// }229//230// org.openqa.selenium.support.FindAll seleniumFindAll = field.getAnnotation(org.openqa.selenium.support.FindAll.class);231// if (seleniumFindAll != null) {232// by = super.buildBysFromFindByOneOf(seleniumFindAll);233// }234//235 if (by == null) {236 by = buildByFromCustomAnnotationProvider(field);237 }238 if (by == null) {239 by = super.buildBy();240 }241 if (by == null) {242 by = buildByFromDefault();243 }244 if (by == null) {245 throw new IllegalArgumentException("Cannot determine how to locate element " + field);246 }247 return by;248 }249 protected org.openqa.selenium.By buildByFromCustomAnnotationProvider( Field field) {250 return customFindByAnnotationProviderService.getCustomFindByAnnotationServices().stream()251 .filter(annotationService ->annotationService.isAnnotatedByCustomFindByAnnotation(field))252 .findFirst().map(annotationService ->annotationService.buildByFromCustomFindByAnnotation(field))253 .orElse(null);254 }255 protected org.openqa.selenium.By buildByFromFindBy(FindBy myFindBy) {256 assertValidFindBy(myFindBy);257 org.openqa.selenium.By by = buildByFromShortFindBy(myFindBy);258 if (by == null) {259 by = buildByFromLongFindBy(myFindBy);260 }261 return by;262 }263 protected org.openqa.selenium.By buildByFromLongFindBy(FindBy myFindBy) {264 How how = myFindBy.how();265 String using = myFindBy.using();266 switch (how) {267 case CLASS_NAME:268 return org.openqa.selenium.By.className(using);269 case CSS:270 return org.openqa.selenium.By.cssSelector(using);271 case ID:272 return org.openqa.selenium.By.id(using);273 case ID_OR_NAME:274 return new ByIdOrName(using);275 case LINK_TEXT:276 return org.openqa.selenium.By.linkText(using);277 case NAME:278 return org.openqa.selenium.By.name(using);279 case PARTIAL_LINK_TEXT:280 return org.openqa.selenium.By.partialLinkText(using);281 case TAG_NAME:282 return org.openqa.selenium.By.tagName(using);283 case XPATH:284 return org.openqa.selenium.By.xpath(using);285 case JQUERY:286 return By.jquery(using);287 case SCLOCATOR:288 return By.sclocator(using);289 case ACCESSIBILITY_ID:290 return MobileBy.AccessibilityId(using);291// case IOS_UI_AUTOMATION:292// return MobileBy.IosUIAutomation(using);293 case ANDROID_UI_AUTOMATOR:294 return MobileBy.AndroidUIAutomator(using);295 case IOS_CLASS_CHAIN:296 return MobileBy.iOSClassChain(using);297 case IOS_NS_PREDICATE_STRING:298 return MobileBy.iOSNsPredicateString(using);299 default:300 // Note that this shouldn't happen (eg, the above matches all301 // possible values for the How enum)302 throw new IllegalArgumentException("Cannot determine how to locate element " + field);303 }304 }305 protected org.openqa.selenium.By buildByFromShortFindBy(FindBy myFindBy) {306 if (isNotEmpty(myFindBy.className())) {307 return org.openqa.selenium.By.className(myFindBy.className());308 }309 if (isNotEmpty(myFindBy.css())) {310 return org.openqa.selenium.By.cssSelector(myFindBy.css());311 }312 if (isNotEmpty(myFindBy.id())) {313 return org.openqa.selenium.By.id(myFindBy.id());314 }315 if (isNotEmpty(myFindBy.linkText())) {316 return org.openqa.selenium.By.linkText(myFindBy.linkText());317 }318 if (isNotEmpty(myFindBy.name())) {319 return org.openqa.selenium.By.name(myFindBy.name());320 }321 if (isNotEmpty(myFindBy.ngModel())) {322 return org.openqa.selenium.By.cssSelector("*[ng-model='" + myFindBy.ngModel() + "']");323 }324 if (isNotEmpty(myFindBy.partialLinkText())) {325 return org.openqa.selenium.By.partialLinkText(myFindBy.partialLinkText());326 }327 if (isNotEmpty(myFindBy.tagName())) {328 return org.openqa.selenium.By.tagName(myFindBy.tagName());329 }330 if (isNotEmpty(myFindBy.xpath())) {331 return org.openqa.selenium.By.xpath(myFindBy.xpath());332 }333 if (isNotEmpty(myFindBy.sclocator())) {334 return By.sclocator(myFindBy.sclocator());335 }336 if (isNotEmpty(myFindBy.jquery())) {337 return By.jquery(myFindBy.jquery());338 }339 if (isNotEmpty(myFindBy.accessibilityId())) {340 return MobileBy.AccessibilityId(myFindBy.accessibilityId());341 }342 if (isNotEmpty(myFindBy.androidUIAutomator())) {343 return MobileBy.AndroidUIAutomator(myFindBy.androidUIAutomator());344 }345// if (isNotEmpty(myFindBy.iOSUIAutomation())) {346// // FIXME: Need to support android with platform switch347// return MobileBy.IosUIAutomation(myFindBy.iOSUIAutomation());348// }349 // Fall through350 return null;351 }352 private org.openqa.selenium.By getMobileBy(Annotation annotation, String valueName) {353 Strategies strategies[] = Strategies.values();354 for (Strategies strategy : strategies) {355 if (strategy.returnValueName().equals(valueName)) {356 return strategy.getBy(annotation);357 }358 }359 throw new IllegalArgumentException("@"360 + annotation.getClass().getSimpleName()361 + ": There is an unknown strategy " + valueName);362 }363 @SuppressWarnings("unchecked")364 private <T extends org.openqa.selenium.By> T getComplexMobileBy(Annotation[] annotations, Class<T> requiredByClass) {365 ;366 org.openqa.selenium.By[] byArray = new org.openqa.selenium.By[annotations.length];367 for (int i = 0; i < annotations.length; i++) {368 byArray[i] = getMobileBy(annotations[i],369 getFieldValue(annotations[i]));370 }371 try {372 Constructor<?> c = requiredByClass.getConstructor(org.openqa.selenium.By[].class);373 Object[] values = new Object[]{byArray};374 return (T) c.newInstance(values);375 } catch (Exception e) {376 throw new RuntimeException(e);377 }378 }379 private static String getFieldValue(Annotation mobileBy) {380 Method[] values = prepareAnnotationMethods(mobileBy.getClass());381 for (Method value : values) {382 try {383 String strategyParameter = value.invoke(mobileBy).toString();384 if (isNotEmpty(strategyParameter) && isStrategyName(value.getName())) {385 return value.getName();386 }387 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {388 throw new RuntimeException(e);389 }390 }391 throw new IllegalArgumentException("@"392 + mobileBy.getClass().getSimpleName() + ": one of "393 + Arrays.toString(Strategies.strategyNames()) + " should be filled");394 }395 private static boolean isStrategyName(String potentialStrategyName) {396 return Arrays.asList(Strategies.strategyNames()).contains(potentialStrategyName);397 }398 private static Method[] prepareAnnotationMethods(399 Class<? extends Annotation> annotation) {400 List<String> targetAnnotationMethodNamesList = getMethodNames(annotation.getDeclaredMethods());401 targetAnnotationMethodNamesList.removeAll(METHODS_TO_BE_EXCLUDED_WHEN_ANNOTATION_IS_READ);402 Method[] result = new Method[targetAnnotationMethodNamesList.size()];403 for (String methodName : targetAnnotationMethodNamesList) {404 try {405 result[targetAnnotationMethodNamesList.indexOf(methodName)] = annotation.getMethod(methodName, DEFAULT_ANNOTATION_METHOD_ARGUMENTS);406 } catch (NoSuchMethodException e) {407 throw new RuntimeException(e);408 } catch (SecurityException e) {409 throw new RuntimeException(e);410 }411 }412 return result;413 }414 private static List<String> getMethodNames(Method[] methods) {415 List<String> names = new ArrayList<String>();416 for (Method m : methods) {417 names.add(m.getName());418 }419 return names;420 }421 private final static List<String> METHODS_TO_BE_EXCLUDED_WHEN_ANNOTATION_IS_READ = new ArrayList<String>() {422 private static final long serialVersionUID = 1L;423 {424 List<String> objectClassMethodNames = getMethodNames(Object.class425 .getDeclaredMethods());426 addAll(objectClassMethodNames);427 List<String> annotationClassMethodNames = getMethodNames(Annotation.class428 .getDeclaredMethods());429 annotationClassMethodNames.removeAll(objectClassMethodNames);430 addAll(annotationClassMethodNames);431 }432 };433 private void assertValidFindBy(FindBy findBy) {434 if (findBy.how() != null) {435 if (findBy.using() == null) {436 throw new IllegalArgumentException(437 "If you set the 'how' property, you must also set 'using'");438 }439 }440 Set<String> finders = new HashSet<String>();441 if (!"".equals(findBy.using())) finders.add("how: " + findBy.using());442 if (!"".equals(findBy.className())) finders.add("class name:" + findBy.className());443 if (!"".equals(findBy.css())) finders.add("css:" + findBy.css());444 if (!"".equals(findBy.id())) finders.add("id: " + findBy.id());445 if (!"".equals(findBy.linkText())) finders.add("link text: " + findBy.linkText());446 if (!"".equals(findBy.name())) finders.add("name: " + findBy.name());447 if (!"".equals(findBy.ngModel())) finders.add("ngModel: " + findBy.ngModel());448 if (!"".equals(findBy.partialLinkText())) finders.add("partial link text: " + findBy.partialLinkText());449 if (!"".equals(findBy.tagName())) finders.add("tag name: " + findBy.tagName());450 if (!"".equals(findBy.xpath())) finders.add("xpath: " + findBy.xpath());451 if (!"".equals(findBy.sclocator())) finders.add("scLocator: " + findBy.sclocator());452 if (!"".equals(findBy.jquery())) finders.add("jquery: " + findBy.jquery());453 if (!"".equals(findBy.accessibilityId())) finders.add("accessibilityId: " + findBy.accessibilityId());454 if (!"".equals(findBy.androidUIAutomator())) finders.add("androidUIAutomator: " + findBy.androidUIAutomator());455 if (!"".equals(findBy.iOSUIAutomation())) finders.add("iOSUIAutomation: " + findBy.iOSUIAutomation());456 // A zero count is okay: it means to look by name or id.457 if (finders.size() > 1) {458 throw new IllegalArgumentException(459 String.format("You must specify at most one location strategy. Number found: %d (%s)",460 finders.size(), finders.toString()));461 }462 }463 // START - [dep3] *** todo [deprecate thucydides] Remove this once thucydides package name is removed464 /**465 * @deprecated use serenitybdd variation466 */467 @Deprecated468 protected org.openqa.selenium.By buildByFromFindBy(net.thucydides.core.annotations.findby.FindBy myDepFindBy) {469 assertValidFindBy(myDepFindBy);470 org.openqa.selenium.By ans = buildByFromShortFindBy(myDepFindBy);471 if (ans == null) {472 ans = buildByFromLongFindBy(myDepFindBy);473 }474 return ans;475 }476 /**477 * @deprecated use serenitybdd variation478 */479 @Deprecated480 protected org.openqa.selenium.By buildByFromLongFindBy(net.thucydides.core.annotations.findby.FindBy myDepFindBy) {481 How how = myDepFindBy.how();482 String using = myDepFindBy.using();483 switch (how) {484 case CLASS_NAME:485 return org.openqa.selenium.By.className(using);486 case CSS:487 return org.openqa.selenium.By.cssSelector(using);488 case ID:489 return org.openqa.selenium.By.id(using);490 case ID_OR_NAME:491 return new ByIdOrName(using);492 case LINK_TEXT:493 return org.openqa.selenium.By.linkText(using);494 case NAME:495 return org.openqa.selenium.By.name(using);496 case PARTIAL_LINK_TEXT:497 return org.openqa.selenium.By.partialLinkText(using);498 case TAG_NAME:499 return org.openqa.selenium.By.tagName(using);500 case XPATH:501 return org.openqa.selenium.By.xpath(using);502 case JQUERY:503 return By.jquery(using);504 case SCLOCATOR:505 return By.sclocator(using);506 default:507 // Note that this shouldn't happen (eg, the above matches all508 // possible values for the How enum)509 throw new IllegalArgumentException("Cannot determine how to locate element " + field);510 }511 }512 /**513 * @deprecated use serenitybdd variation514 */515 @Deprecated516 protected org.openqa.selenium.By buildByFromShortFindBy(net.thucydides.core.annotations.findby.FindBy myDepFindBy) {517 if (isNotEmpty(myDepFindBy.className())) {518 return org.openqa.selenium.By.className(myDepFindBy.className());519 }520 if (isNotEmpty(myDepFindBy.css())) {521 return org.openqa.selenium.By.cssSelector(myDepFindBy.css());522 }523 if (isNotEmpty(myDepFindBy.id())) {524 return org.openqa.selenium.By.id(myDepFindBy.id());525 }526 if (isNotEmpty(myDepFindBy.linkText())) {527 return org.openqa.selenium.By.linkText(myDepFindBy.linkText());528 }529 if (isNotEmpty(myDepFindBy.name())) {530 return org.openqa.selenium.By.name(myDepFindBy.name());531 }532 if (isNotEmpty(myDepFindBy.ngModel())) {533 return org.openqa.selenium.By.cssSelector("*[ng-model='" + myDepFindBy.ngModel() + "']");534 }535 if (isNotEmpty(myDepFindBy.partialLinkText())) {536 return org.openqa.selenium.By.partialLinkText(myDepFindBy.partialLinkText());537 }538 if (isNotEmpty(myDepFindBy.tagName())) {539 return org.openqa.selenium.By.tagName(myDepFindBy.tagName());540 }541 if (isNotEmpty(myDepFindBy.xpath())) {542 return org.openqa.selenium.By.xpath(myDepFindBy.xpath());543 }544 if (isNotEmpty(myDepFindBy.sclocator())) {545 return By.sclocator(myDepFindBy.sclocator());546 }547 if (isNotEmpty(myDepFindBy.jquery())) {548 return By.jquery(myDepFindBy.jquery());549 }550 // Fall through551 return null;552 }553 /**554 * @deprecated use serenitybdd variation555 */556 @Deprecated557 private void assertValidFindBy(net.thucydides.core.annotations.findby.FindBy findDepBy) {558 if (findDepBy.how() != null) {559 if (findDepBy.using() == null) {560 throw new IllegalArgumentException(561 "If you set the 'how' property, you must also set 'using'");562 }563 }564 Set<String> finders = new HashSet<String>();565 if (!"".equals(findDepBy.using())) finders.add("how: " + findDepBy.using());566 if (!"".equals(findDepBy.className())) finders.add("class name:" + findDepBy.className());567 if (!"".equals(findDepBy.css())) finders.add("css:" + findDepBy.css());568 if (!"".equals(findDepBy.id())) finders.add("id: " + findDepBy.id());569 if (!"".equals(findDepBy.linkText())) finders.add("link text: " + findDepBy.linkText());570 if (!"".equals(findDepBy.name())) finders.add("name: " + findDepBy.name());571 if (!"".equals(findDepBy.ngModel())) finders.add("ngModel: " + findDepBy.ngModel());572 if (!"".equals(findDepBy.partialLinkText())) finders.add("partial link text: " + findDepBy.partialLinkText());573 if (!"".equals(findDepBy.tagName())) finders.add("tag name: " + findDepBy.tagName());574 if (!"".equals(findDepBy.xpath())) finders.add("xpath: " + findDepBy.xpath());575 if (!"".equals(findDepBy.sclocator())) finders.add("scLocator: " + findDepBy.sclocator());576 if (!"".equals(findDepBy.jquery())) finders.add("jquery: " + findDepBy.jquery());577 // A zero count is okay: it means to look by name or id.578 if (finders.size() > 1) {579 throw new IllegalArgumentException(580 String.format("You must specify at most one location strategy. Number found: %d (%s)",581 finders.size(), finders.toString()));582 }583 }584 // END - [dep3] ***[deprecate thucydides] Remove this once thucydides package name is removed585}...

Full Screen

Full Screen

MobileBy.java

Source:MobileBy.java Github

copy

Full Screen

...44 }45 @SuppressWarnings("unchecked")46 @Override public List<WebElement> findElements(SearchContext context) {47 return (List<WebElement>) ((FindsByFluentSelector<?>) context)48 .findElements(selector.toString(), getLocatorString());49 }50 @Override public WebElement findElement(SearchContext context) {51 return ((FindsByFluentSelector<?>) context)52 .findElement(selector.toString(), getLocatorString());53 }54 /**55 * Read https://developer.apple.com/library/tvos/documentation/DeveloperTools/56 * Conceptual/InstrumentsUserGuide/UIAutomation.html57 *58 * @param iOSAutomationText is iOS UIAutomation string59 * @return an instance of {@link io.appium.java_client.MobileBy.ByIosUIAutomation}60 */61 public static By IosUIAutomation(final String iOSAutomationText) {62 return new ByIosUIAutomation(iOSAutomationText);63 }64 /**65 * Read http://developer.android.com/intl/ru/tools/testing-support-library/66 * index.html#uia-apis67 * @param uiautomatorText is Android UIAutomator string68 * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}69 */70 public static By AndroidUIAutomator(final String uiautomatorText) {71 return new ByAndroidUIAutomator(uiautomatorText);72 }73 /**74 * About Android accessibility75 * https://developer.android.com/intl/ru/training/accessibility/accessible-app.html76 * About iOS accessibility77 * https://developer.apple.com/library/ios/documentation/UIKit/Reference/78 * UIAccessibilityIdentification_Protocol/index.html79 * @param accessibilityId id is a convenient UI automation accessibility Id.80 * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}81 */82 public static By AccessibilityId(final String accessibilityId) {83 return new ByAccessibilityId(accessibilityId);84 }85 /**86 * This locator strategy is available in XCUITest Driver mode87 * @param iOSClassChainString is a valid class chain locator string.88 * See <a href="https://github.com/facebook/WebDriverAgent/wiki/Queries">89 * the documentation</a> for more details90 * @return an instance of {@link io.appium.java_client.MobileBy.ByIosClassChain}91 */92 public static By iOSClassChain(final String iOSClassChainString) {93 return new ByIosClassChain(iOSClassChainString);94 }95 /**96 * This locator strategy is available in XCUITest Driver mode97 * @param iOSNsPredicateString is an an iOS NsPredicate String98 * @return an instance of {@link io.appium.java_client.MobileBy.ByIosNsPredicate}99 */100 public static By iOSNsPredicateString(final String iOSNsPredicateString) {101 return new ByIosNsPredicate(iOSNsPredicateString);102 }103 public static By windowsAutomation(final String windowsAutomation) {104 return new ByWindowsAutomation(windowsAutomation);105 }106 107 public static class ByIosUIAutomation extends MobileBy implements Serializable {108 public ByIosUIAutomation(String iOSAutomationText) {109 super(MobileSelector.IOS_UI_AUTOMATION, iOSAutomationText);110 }111 /**112 * @throws WebDriverException when current session doesn't support the given selector or when113 * value of the selector is not consistent.114 * @throws IllegalArgumentException when it is impossible to find something on the given115 * {@link SearchContext} instance116 */117 @SuppressWarnings("unchecked")118 @Override119 public List<WebElement> findElements(SearchContext context) throws WebDriverException,120 IllegalArgumentException {121 Class<?> contextClass = context.getClass();122 if (FindsByIosUIAutomation.class.isAssignableFrom(contextClass)) {123 return FindsByIosUIAutomation.class.cast(context)124 .findElementsByIosUIAutomation(getLocatorString());125 }126 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {127 return super.findElements(context);128 }129 throw formIllegalArgumentException(contextClass, FindsByIosUIAutomation.class,130 FindsByFluentSelector.class);131 }132 /**133 * @throws WebDriverException when current session doesn't support the given selector or when134 * value of the selector is not consistent.135 * @throws IllegalArgumentException when it is impossible to find something on the given136 * {@link SearchContext} instance137 */138 @Override public WebElement findElement(SearchContext context) throws WebDriverException,139 IllegalArgumentException {140 Class<?> contextClass = context.getClass();141 if (FindsByIosUIAutomation.class.isAssignableFrom(contextClass)) {142 return ((FindsByIosUIAutomation<?>) context)143 .findElementByIosUIAutomation(getLocatorString());144 }145 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {146 return super.findElement(context);147 }148 throw formIllegalArgumentException(contextClass, FindsByIosUIAutomation.class,149 FindsByFluentSelector.class);150 }151 @Override public String toString() {152 return "By.IosUIAutomation: " + getLocatorString();153 }154 }155 public static class ByAndroidUIAutomator extends MobileBy implements Serializable {156 public ByAndroidUIAutomator(String uiautomatorText) {157 super(MobileSelector.ANDROID_UI_AUTOMATOR, uiautomatorText);158 }159 /**160 * @throws WebDriverException when current session doesn't support the given selector or when161 * value of the selector is not consistent.162 * @throws IllegalArgumentException when it is impossible to find something on the given163 * {@link SearchContext} instance164 */165 @SuppressWarnings("unchecked")166 @Override167 public List<WebElement> findElements(SearchContext context) throws WebDriverException,168 IllegalArgumentException {169 Class<?> contextClass = context.getClass();170 if (FindsByAndroidUIAutomator.class.isAssignableFrom(contextClass)) {171 return FindsByAndroidUIAutomator.class.cast(context)172 .findElementsByAndroidUIAutomator(getLocatorString());173 }174 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {175 return super.findElements(context);176 }177 throw formIllegalArgumentException(contextClass, FindsByAndroidUIAutomator.class,178 FindsByFluentSelector.class);179 }180 /**181 * @throws WebDriverException when current session doesn't support the given selector or when182 * value of the selector is not consistent.183 * @throws IllegalArgumentException when it is impossible to find something on the given184 * {@link SearchContext} instance185 */186 @Override public WebElement findElement(SearchContext context) throws WebDriverException,187 IllegalArgumentException {188 Class<?> contextClass = context.getClass();189 if (FindsByAndroidUIAutomator.class.isAssignableFrom(contextClass)) {190 return FindsByAndroidUIAutomator.class.cast(context)191 .findElementByAndroidUIAutomator(getLocatorString());192 }193 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {194 return super.findElement(context);195 }196 throw formIllegalArgumentException(contextClass, FindsByAndroidUIAutomator.class,197 FindsByFluentSelector.class);198 }199 @Override public String toString() {200 return "By.AndroidUIAutomator: " + getLocatorString();201 }202 }203 public static class ByAccessibilityId extends MobileBy implements Serializable {204 public ByAccessibilityId(String accessibilityId) {205 super(MobileSelector.ACCESSIBILITY, accessibilityId);206 }207 /**208 * @throws WebDriverException when current session doesn't support the given selector or when209 * value of the selector is not consistent.210 * @throws IllegalArgumentException when it is impossible to find something on the given211 * {@link SearchContext} instance212 */213 @SuppressWarnings("unchecked")214 @Override215 public List<WebElement> findElements(SearchContext context) throws WebDriverException,216 IllegalArgumentException {217 Class<?> contextClass = context.getClass();218 if (FindsByAccessibilityId.class.isAssignableFrom(contextClass)) {219 return FindsByAccessibilityId.class.cast(context)220 .findElementsByAccessibilityId(getLocatorString());221 }222 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {223 return super.findElements(context);224 }225 throw formIllegalArgumentException(contextClass, FindsByAccessibilityId.class,226 FindsByFluentSelector.class);227 }228 /**229 * @throws WebDriverException when current session doesn't support the given selector or when230 * value of the selector is not consistent.231 * @throws IllegalArgumentException when it is impossible to find something on the given232 * {@link SearchContext} instance233 */234 @Override public WebElement findElement(SearchContext context) throws WebDriverException,235 IllegalArgumentException {236 Class<?> contextClass = context.getClass();237 if (FindsByAccessibilityId.class.isAssignableFrom(contextClass)) {238 return FindsByAccessibilityId.class.cast(context)239 .findElementByAccessibilityId(getLocatorString());240 }241 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {242 return super.findElement(context);243 }244 throw formIllegalArgumentException(contextClass, FindsByAccessibilityId.class,245 FindsByFluentSelector.class);246 }247 @Override public String toString() {248 return "By.AccessibilityId: " + getLocatorString();249 }250 }251 public static class ByIosClassChain extends MobileBy implements Serializable {252 protected ByIosClassChain(String locatorString) {253 super(MobileSelector.IOS_CLASS_CHAIN, locatorString);254 }255 /**256 * @throws WebDriverException when current session doesn't support the given selector or when257 * value of the selector is not consistent.258 * @throws IllegalArgumentException when it is impossible to find something on the given259 * {@link SearchContext} instance260 */261 @SuppressWarnings("unchecked")262 @Override public List<WebElement> findElements(SearchContext context) {263 Class<?> contextClass = context.getClass();264 if (FindsByIosClassChain.class.isAssignableFrom(contextClass)) {265 return FindsByIosClassChain.class.cast(context)266 .findElementsByIosClassChain(getLocatorString());267 }268 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {269 return super.findElements(context);270 }271 throw formIllegalArgumentException(contextClass, FindsByIosClassChain.class,272 FindsByFluentSelector.class);273 }274 /**275 * @throws WebDriverException when current session doesn't support the given selector or when276 * value of the selector is not consistent.277 * @throws IllegalArgumentException when it is impossible to find something on the given278 * {@link SearchContext} instance279 */280 @Override public WebElement findElement(SearchContext context) {281 Class<?> contextClass = context.getClass();282 if (FindsByIosClassChain.class.isAssignableFrom(contextClass)) {283 return FindsByIosClassChain.class.cast(context)284 .findElementByIosClassChain(getLocatorString());285 }286 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {287 return super.findElement(context);288 }289 throw formIllegalArgumentException(contextClass, FindsByIosClassChain.class,290 FindsByFluentSelector.class);291 }292 @Override public String toString() {293 return "By.IosClassChain: " + getLocatorString();294 }295 }296 public static class ByIosNsPredicate extends MobileBy implements Serializable {297 protected ByIosNsPredicate(String locatorString) {298 super(MobileSelector.IOS_PREDICATE_STRING, locatorString);299 }300 /**301 * @throws WebDriverException when current session doesn't support the given selector or when302 * value of the selector is not consistent.303 * @throws IllegalArgumentException when it is impossible to find something on the given304 * {@link SearchContext} instance305 */306 @SuppressWarnings("unchecked")307 @Override public List<WebElement> findElements(SearchContext context) {308 Class<?> contextClass = context.getClass();309 if (FindsByIosNSPredicate.class.isAssignableFrom(contextClass)) {310 return FindsByIosNSPredicate.class.cast(context)311 .findElementsByIosNsPredicate(getLocatorString());312 }313 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {314 return super.findElements(context);315 }316 throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,317 FindsByFluentSelector.class);318 }319 /**320 * @throws WebDriverException when current session doesn't support the given selector or when321 * value of the selector is not consistent.322 * @throws IllegalArgumentException when it is impossible to find something on the given323 * {@link SearchContext} instance324 */325 @Override public WebElement findElement(SearchContext context) {326 Class<?> contextClass = context.getClass();327 if (FindsByIosNSPredicate.class.isAssignableFrom(contextClass)) {328 return FindsByIosNSPredicate.class.cast(context)329 .findElementByIosNsPredicate(getLocatorString());330 }331 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {332 return super.findElement(context);333 }334 throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,335 FindsByFluentSelector.class);336 }337 @Override public String toString() {338 return "By.IosNsPredicate: " + getLocatorString();339 }340 }341 public static class ByWindowsAutomation extends MobileBy implements Serializable {342 protected ByWindowsAutomation(String locatorString) {343 super(MobileSelector.WINDOWS_UI_AUTOMATION, locatorString);344 }345 /**346 * @throws WebDriverException when current session doesn't support the given selector or when347 * value of the selector is not consistent.348 * @throws IllegalArgumentException when it is impossible to find something on the given349 * {@link SearchContext} instance350 */351 @SuppressWarnings("unchecked")...

Full Screen

Full Screen

ByParserTest.java

Source:ByParserTest.java Github

copy

Full Screen

...45 webDriver.isWebContext(); result = true;46 }};47 By by = ByParser.parseBy("id=id", webDriver);48 Assert.assertTrue(by instanceof By.ById);49 Assert.assertEquals("By.id: id", by.toString());50 by = ByParser.parseBy("link=link", webDriver);51 Assert.assertTrue(by instanceof By.ByLinkText);52 Assert.assertEquals("By.linkText: link", by.toString());53 by = ByParser.parseBy("partial link=link", webDriver);54 Assert.assertTrue(by instanceof By.ByPartialLinkText);55 Assert.assertEquals("By.partialLinkText: link", by.toString());56 by = ByParser.parseBy("tag=button", webDriver);57 Assert.assertTrue(by instanceof By.ByTagName);58 Assert.assertEquals("By.tagName: button", by.toString());59 by = ByParser.parseBy("name=name", webDriver);60 Assert.assertTrue(by instanceof By.ByName);61 Assert.assertEquals("By.name: name", by.toString());62 by = ByParser.parseBy("class=class", webDriver);63 Assert.assertTrue(by instanceof By.ByClassName);64 Assert.assertEquals("By.className: class", by.toString());65 by = ByParser.parseBy("css=css", webDriver);66 Assert.assertTrue(by instanceof ByCss);67 Assert.assertEquals("By.css: css", by.toString());68 by = ByParser.parseBy("xpath=//xpath", webDriver);69 Assert.assertTrue(by instanceof By.ByXPath);70 Assert.assertEquals("By.xpath: //xpath", by.toString());71 by = ByParser.parseBy("identifier=identifier", webDriver);72 Assert.assertTrue(by instanceof ByIdOrName);73 Assert.assertEquals("by id or name \"identifier\"", by.toString());74 by = ByParser.parseBy("alt=alt", webDriver);75 Assert.assertTrue(by instanceof ByAlt);76 Assert.assertEquals("By.alt: alt", by.toString());77 by = ByParser.parseBy("dom=dom", webDriver);78 Assert.assertTrue(by instanceof ByDom);79 Assert.assertEquals("By.dom: dom", by.toString());80 by = ByParser.parseBy("index=1", webDriver);81 Assert.assertTrue(by instanceof ByIndex);82 Assert.assertEquals("By.index: [null][1]", by.toString());83 by = ByParser.parseBy("variable=variable", webDriver);84 Assert.assertTrue(by instanceof ByVariable);85 Assert.assertEquals("By.variable: variable", by.toString());86 by = ByParser.parseBy("//xpath", webDriver);87 Assert.assertTrue(by instanceof By.ByXPath);88 Assert.assertEquals("By.xpath: //xpath", by.toString());89 by = ByParser.parseBy("document.getElementById('login-btn')", webDriver);90 Assert.assertTrue(by instanceof ByDom);91 Assert.assertEquals("By.dom: document.getElementById('login-btn')", by.toString());92 by = ByParser.parseBy("identifier", webDriver);93 Assert.assertTrue(by instanceof ByIdOrName);94 Assert.assertEquals("by id or name \"identifier\"", by.toString());95 }96 @Test97 public void testParseByMobile() {98 new Expectations() {{99 webDriver.isWebContext(); result = false;100 }};101 By by = ByParser.parseBy("accessibility id=accessibility id", webDriver);102 Assert.assertTrue(by instanceof MobileBy.ByAccessibilityId);103 Assert.assertEquals("By.AccessibilityId: accessibility id", by.toString());104 by = ByParser.parseBy("class=class", webDriver);105 Assert.assertTrue(by instanceof MobileBy.ByClassName);106 Assert.assertEquals("By.className: class", by.toString());107 by = ByParser.parseBy("id=id", webDriver);108 Assert.assertTrue(by instanceof MobileBy.ById);109 Assert.assertEquals("By.id: id", by.toString());110 by = ByParser.parseBy("name=name", webDriver);111 Assert.assertTrue(by instanceof MobileBy.ByName);112 Assert.assertEquals("By.name: name", by.toString());113 by = ByParser.parseBy("xpath=//xpath", webDriver);114 Assert.assertTrue(by instanceof MobileBy.ByXPath);115 Assert.assertEquals("By.xpath: //xpath", by.toString());116 by = ByParser.parseBy("android uiautomator=android uiautomator", webDriver);117 Assert.assertTrue(by instanceof MobileBy.ByAndroidUIAutomator);118 Assert.assertEquals("By.AndroidUIAutomator: android uiautomator", by.toString());119 by = ByParser.parseBy("android viewtag=android viewtag", webDriver);120 Assert.assertTrue(by instanceof MobileBy.ByAndroidViewTag);121 Assert.assertEquals("By.AndroidViewTag: android viewtag", by.toString());122 by = ByParser.parseBy("android datamatcher=android datamatcher", webDriver);123 Assert.assertTrue(by instanceof MobileBy.ByAndroidDataMatcher);124 Assert.assertEquals("By.FindsByAndroidDataMatcher: android datamatcher", by.toString());125 by = ByParser.parseBy("ios predicate string=ios predicate string", webDriver);126 Assert.assertTrue(by instanceof MobileBy.ByIosNsPredicate);127 Assert.assertEquals("By.IosNsPredicate: ios predicate string", by.toString());128 by = ByParser.parseBy("ios class chain=ios class chain", webDriver);129 Assert.assertTrue(by instanceof MobileBy.ByIosClassChain);130 Assert.assertEquals("By.IosClassChain: ios class chain", by.toString());131 by = ByParser.parseBy("windows uiautomation=windows uiautomation", webDriver);132 Assert.assertTrue(by instanceof MobileBy.ByWindowsAutomation);133 by = ByParser.parseBy("index=1", webDriver);134 Assert.assertTrue(by instanceof ByIndex);135 Assert.assertEquals("By.index: [null][1]", by.toString());136 by = ByParser.parseBy("variable=variable", webDriver);137 Assert.assertTrue(by instanceof ByVariable);138 Assert.assertEquals("By.variable: variable", by.toString());139 by = ByParser.parseBy("//xpath", webDriver);140 Assert.assertTrue(by instanceof MobileBy.ByXPath);141 Assert.assertEquals("By.xpath: //xpath", by.toString());142 by = ByParser.parseBy("accessibility id", webDriver);143 Assert.assertTrue(by instanceof MobileBy.ByAccessibilityId);144 Assert.assertEquals("By.AccessibilityId: accessibility id", by.toString());145 }146}...

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1By locator = MobileBy.ByIosNsPredicate.toString("type == 'XCUIElementTypeTextField'"); 2By locator = MobileBy.ByIosUIAutomation.toString(".elements()[0]");3By locator = MobileBy.ByAndroidUIAutomator.toString("new UiSelector().text(\"SomeText\")");4By locator = MobileBy.ByAndroidViewTag.toString("SomeText");5By locator = MobileBy.ByAccessibilityId.toString("SomeText");6By locator = MobileBy.ByIosNsPredicate.toString("type == 'XCUIElementTypeTextField'"); 7By locator = MobileBy.ByIosUIAutomation.toString(".elements()[0]");8By locator = MobileBy.ByAndroidUIAutomator.toString("new UiSelector().text(\"SomeText\")");9By locator = MobileBy.ByAndroidViewTag.toString("SomeText");10By locator = MobileBy.ByAccessibilityId.toString("SomeText");11By locator = MobileBy.ByIosNsPredicate.toString("type == 'XCUIElementTypeTextField'"); 12By locator = MobileBy.ByIosUIAutomation.toString(".elements()[0]");13By locator = MobileBy.ByAndroidUIAutomator.toString("new UiSelector().text(\"SomeText\")");

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1By by = MobileBy.ByIosNsPredicate.toString("type == 'XCUIElementTypeButton' && name == 'Back'");2By by = MobileBy.ByIosUIAutomation.toString("UIATarget.localTarget().frontMostApp().mainWindow().buttons()['Back']");3By by = MobileBy.ByIosClassChain.toString("**/XCUIElementTypeButton[`name == 'Back'`]");4driver.findElement(by).click();5By by = MobileBy.ByAccessibilityId.toString("Back");6driver.findElement(by).click();7By by = MobileBy.ByAndroidUIAutomator.toString("new UiSelector().text(\"Back\")");8driver.findElement(by).click();9By by = MobileBy.ByAndroidViewTag.toString("Back");10driver.findElement(by).click();11By by = MobileBy.ByAndroidDataMatcher.toString("new UiSelector().text(\"Back\")");12driver.findElement(by).click();13By by = MobileBy.ByAndroidViewMatcher.toString("new UiSelector().text(\"Back\")");14driver.findElement(by).click();15By by = MobileBy.ByAndroidClass.toString("android.widget.Button");16driver.findElement(by).click();17By by = MobileBy.ByAndroidText.toString("Back");18driver.findElement(by).click();19By by = MobileBy.ByAndroidContentDesc.toString("Back");20driver.findElement(by).click();21By by = MobileBy.ByAndroidResourceID.toString("com.android.calculator2:id

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1MobileElement element = (MobileElement) driver.findElement(MobileBy.ByIosNsPredicate.toString("type == 'XCUIElementTypeButton' AND name == 'OK'"));2element.click();3MobileElement element = (MobileElement) driver.findElement(MobileBy.ByIosUIAutomation.toString(".elements()[0].elements()[1].elements()[0].elements()[0]"));4element.click();5element = driver.find_element_by_ios_uiautomation('.elements()[0].elements()[1].elements()[0].elements()[0]')6element.click()7element = driver.find_element(:ios_uiautomation, '.elements()[0].elements()[1].elements()[0].elements()[0]')

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1By by = MobileBy.ByIosNsPredicate.toString("type == 'XCUIElementTypeButton' AND name == 'Search'");2By by = MobileBy.ByIosNsPredicate.valueOf("name == 'Search'");3By by = MobileBy.ByIosNsPredicate.valueOf("type == 'XCUIElementTypeButton' AND name == 'Search'");4By by = MobileBy.ByIosNsPredicate.valueOf("type == 'XCUIElementTypeButton' AND name == 'Search'");5By by = MobileBy.ByIosNsPredicate.valueOf("type == 'XCUIElementTypeButton' AND name == 'Search'");6By by = MobileBy.ByIosNsPredicate.valueOf("type == 'XCUIElementTypeButton' AND name == 'Search'");7By by = MobileBy.ByIosNsPredicate.valueOf("type == 'XCUIElementTypeButton' AND name == 'Search'");8By by = MobileBy.ByIosNsPredicate.valueOf("type == 'XCUIElementTypeButton' AND name == 'Search'");9By by = MobileBy.ByIosNsPredicate.valueOf("type == 'XCUIElementTypeButton' AND name == 'Search'");

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1ByIosNsPredicate byIosNsPredicate = new ByIosNsPredicate("type == 'XCUIElementTypeButton' AND name == 'Done'");2WebElement element = driver.findElement(byIosNsPredicate);3System.out.println(element);4ByIosUIAutomation byIosUIAutomation = new ByIosUIAutomation(".elements()[0].cells()[0].buttons()[0]");5WebElement element = driver.findElement(byIosUIAutomation);6System.out.println(element);7ByIosClassChain byIosClassChain = new ByIosClassChain("**/XCUIElementTypeButton[`name == \"Done\"`]");8WebElement element = driver.findElement(byIosClassChain);9System.out.println(element);10ByAccessibilityId byAccessibilityId = new ByAccessibilityId("Done");11WebElement element = driver.findElement(byAccessibilityId);12System.out.println(element);13ByAndroidUIAutomator byAndroidUIAutomator = new ByAndroidUIAutomator("new UiSelector().clickable(true)");14WebElement element = driver.findElement(byAndroidUIAutomator);15System.out.println(element);16ByAndroidDataMatcher byAndroidDataMatcher = new ByAndroidDataMatcher("hasEntry(\"name\", \"Done\")");17WebElement element = driver.findElement(byAndroidDataMatcher);18System.out.println(element);19ByAndroidViewTag byAndroidViewTag = new ByAndroidViewTag("Done");20WebElement element = driver.findElement(byAndroidViewTag);21System.out.println(element);22ByAndroidViewMatcher byAndroidViewMatcher = new ByAndroidViewMatcher("withText(\"Done\")");23WebElement element = driver.findElement(byAndroidViewMatcher);24System.out.println(element);25ByAndroidContentDesc byAndroidContentDesc = new ByAndroidContentDesc("Done");

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1MobileBy.ByIosNsPredicate nsPredicate = new MobileBy.ByIosNsPredicate("type == \"XCUIElementTypeStaticText\" AND label == \"PREFERENCES\"");2String xpath = nsPredicate.toString();3System.out.println(xpath);4MobileBy.ByIosUIAutomation uiAutomation = new MobileBy.ByIosUIAutomation(".elements()[0]");5String xpath1 = uiAutomation.toString();6System.out.println(xpath1);7MobileBy.ByAccessibilityId accessibilityId = new MobileBy.ByAccessibilityId("PREFERENCES");8String xpath2 = accessibilityId.toString();9System.out.println(xpath2);10MobileBy.ByAndroidUIAutomator androidUIAutomator = new MobileBy.ByAndroidUIAutomator("new UiSelector().text(\"PREFERENCES\")");11String xpath3 = androidUIAutomator.toString();12System.out.println(xpath3);13MobileBy.ByAndroidDataMatcher androidDataMatcher = new MobileBy.ByAndroidDataMatcher("withText(\"PREFERENCES\")");14String xpath4 = androidDataMatcher.toString();15System.out.println(xpath4);16}17}

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 io.appium automation tests on LambdaTest cloud grid

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

Most used method in MobileBy.ByIosNsPredicate

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful