Best io.appium code snippet using io.appium.java_client.MobileBy.ByIosClassChain
MobileBy.java
Source:MobileBy.java
1/*2 * Licensed under the Apache License, Version 2.0 (the "License");3 * you may not use this file except in compliance with the License.4 * See the NOTICE file distributed with this work for additional5 * information regarding copyright ownership.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.appium.java_client;17import org.apache.commons.lang3.StringUtils;18import org.openqa.selenium.By;19import org.openqa.selenium.SearchContext;20import org.openqa.selenium.WebDriverException;21import org.openqa.selenium.WebElement;22import java.io.Serializable;23import java.util.List;24@SuppressWarnings("serial")25public abstract class MobileBy extends By {26 private static final String ERROR_TEXT = "The class %s of the given context "27 + "doesn't implement %s nor %s. Sorry. It is impossible to find something.";28 private final String locatorString;29 private final MobileSelector selector;30 private static IllegalArgumentException formIllegalArgumentException(Class<?> givenClass,31 Class<?> class1, Class<?> class2) {32 return new IllegalArgumentException(String.format(ERROR_TEXT, givenClass.getCanonicalName(),33 class1.getCanonicalName(), class2.getCanonicalName()));34 }35 protected MobileBy(MobileSelector selector, String locatorString) {36 if (StringUtils.isBlank(locatorString)) {37 throw new IllegalArgumentException("Must supply a not empty locator value.");38 }39 this.locatorString = locatorString;40 this.selector = selector;41 }42 protected String getLocatorString() {43 return locatorString;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")352 @Override public List<WebElement> findElements(SearchContext context) {353 Class<?> contextClass = context.getClass();354 if (FindsByWindowsAutomation.class.isAssignableFrom(contextClass)) {355 return FindsByWindowsAutomation.class.cast(context)356 .findElementsByWindowsUIAutomation(getLocatorString());357 }358 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {359 return super.findElements(context);360 }361 throw formIllegalArgumentException(contextClass, FindsByWindowsAutomation.class,362 FindsByFluentSelector.class);363 }364 /**365 * @throws WebDriverException when current session doesn't support the given selector or when366 * value of the selector is not consistent.367 * @throws IllegalArgumentException when it is impossible to find something on the given368 * {@link SearchContext} instance369 */370 @Override public WebElement findElement(SearchContext context) {371 Class<?> contextClass = context.getClass();372 if (FindsByWindowsAutomation.class.isAssignableFrom(contextClass)) {373 return FindsByWindowsAutomation.class.cast(context)374 .findElementByWindowsUIAutomation(getLocatorString());375 }376 if (FindsByFluentSelector.class.isAssignableFrom(context.getClass())) {377 return super.findElement(context);378 }379 throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,380 FindsByWindowsAutomation.class);381 }382 }383}...
By.java
Source:By.java
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package com.testpros.fast;18import io.appium.java_client.MobileSelector;19/**20 * Mechanism used to locate elements within a document. In order to create your own locating21 * mechanisms, it is possible to subclass this class and override the protected methods as required,22 * though it is expected that all subclasses rely on the basic finding mechanisms provided23 * through static methods of this class:24 *25 * <code>26 * public WebElement findElement(WebDriver driver) {27 * WebElement element = driver.findElement(By.id(getSelector()));28 * if (element == null)29 * element = driver.findElement(By.name(getSelector());30 * return element;31 * }32 * </code>33 */34//public class By extends io.appium.java_client.MobileBy {35//public abstract class By extends org.openqa.selenium.By {36public class By {37 org.openqa.selenium.By by;38 public By(org.openqa.selenium.By by) {39 this.by = by;40 }41 public org.openqa.selenium.By getBy() {42 return by;43 }44 45 /**46 * @param id The value of the "id" attribute to search for.47 * @return A By which locates elements by the value of the "id" attribute.48 */49 public static By id(String id) {50 return new By(org.openqa.selenium.By.id(id));51 }52 /**53 * @param linkText The exact text to match against.54 * @return A By which locates A elements by the exact text it displays.55 */56 public static By linkText(String linkText) {57 return new By(org.openqa.selenium.By.linkText(linkText));58 }59 /**60 * @param partialLinkText The partial text to match against61 * @return a By which locates elements that contain the given link text.62 */63 public static By partialLinkText(String partialLinkText) {64 return new By(org.openqa.selenium.By.partialLinkText(partialLinkText));65 }66 /**67 * @param name The value of the "name" attribute to search for.68 * @return A By which locates elements by the value of the "name" attribute.69 */70 public static By name(String name) {71 return new By(org.openqa.selenium.By.name(name));72 }73 /**74 * @param tagName The element's tag name.75 * @return A By which locates elements by their tag name.76 */77 public static By tagName(String tagName) {78 return new By(org.openqa.selenium.By.tagName(tagName));79 }80 /**81 * @param xpathExpression The XPath to use.82 * @return A By which locates elements via XPath.83 */84 public static By xpath(String xpathExpression) {85 return new By(org.openqa.selenium.By.xpath(xpathExpression));86 }87 /**88 * Find elements based on the value of the "class" attribute. If an element has multiple classes, then89 * this will match against each of them. For example, if the value is "one two onone", then the90 * class names "one" and "two" will match.91 *92 * @param className The value of the "class" attribute to search for.93 * @return A By which locates elements by the value of the "class" attribute.94 */95 public static By className(String className) {96 return new By(org.openqa.selenium.By.className(className));97 }98 /**99 * Find elements via the driver's underlying W3C Selector engine. If the browser does not100 * implement the Selector API, a best effort is made to emulate the API. In this case, we strive101 * for at least CSS2 support, but offer no guarantees.102 *103 * @param cssSelector CSS expression.104 * @return A By which locates elements by CSS.105 */106 public static By cssSelector(String cssSelector) {107 return new By(org.openqa.selenium.By.cssSelector(cssSelector));108 }109 /**110 * Read http://developer.android.com/intl/ru/tools/testing-support-library/111 * index.html#uia-apis112 *113 * @param uiautomatorText is Android UIAutomator string114 * @return an instance of {@link By.ByAndroidUIAutomator}115 */116 public static By AndroidUIAutomator(final String uiautomatorText) {117 return new By(io.appium.java_client.MobileBy.AndroidUIAutomator(uiautomatorText));118 }119 /**120 * About Android accessibility121 * https://developer.android.com/intl/ru/training/accessibility/accessible-app.html122 * About iOS accessibility123 * https://developer.apple.com/library/ios/documentation/UIKit/Reference/124 * UIAccessibilityIdentification_Protocol/index.html125 *126 * @param accessibilityId id is a convenient UI automation accessibility Id.127 * @return an instance of {@link By.ByAndroidUIAutomator}128 */129 public static By AccessibilityId(final String accessibilityId) {130 return new By(io.appium.java_client.MobileBy.AccessibilityId(accessibilityId));131 }132 /**133 * This locator strategy is available in XCUITest Driver mode.134 *135 * @param iOSClassChainString is a valid class chain locator string.136 * See <a href="https://github.com/facebook/WebDriverAgent/wiki/Queries">137 * the documentation</a> for more details138 * @return an instance of {@link By.ByIosClassChain}139 */140 public static By iOSClassChain(final String iOSClassChainString) {141 return new By(io.appium.java_client.MobileBy.iOSClassChain(iOSClassChainString));142 }143 /**144 * This locator strategy is only available in Espresso Driver mode.145 *146 * @param dataMatcherString is a valid class chain locator string.147 * See <a href="https://github.com/appium/appium-espresso-driver/pull/386">148 * the documentation</a> for more details149 * @return an instance of {@link By.ByAndroidDataMatcher}150 */151 public static By androidDataMatcher(final String dataMatcherString) {152 return new By(io.appium.java_client.MobileBy.androidDataMatcher(dataMatcherString));153 }154 /**155 * This locator strategy is available in XCUITest Driver mode.156 *157 * @param iOSNsPredicateString is an an iOS NsPredicate String158 * @return an instance of {@link By.ByIosNsPredicate}159 */160 public static By iOSNsPredicateString(final String iOSNsPredicateString) {161 return new By(io.appium.java_client.MobileBy.iOSNsPredicateString(iOSNsPredicateString));162 }163 public static By windowsAutomation(final String windowsAutomation) {164 return new By(io.appium.java_client.MobileBy.windowsAutomation(windowsAutomation));165 }166 /**167 * This locator strategy is available in Espresso Driver mode.168 *169 * @param tag is an view tag string170 * @return an instance of {@link ByAndroidViewTag}171 * @since Appium 1.8.2 beta172 */173 public static By AndroidViewTag(final String tag) {174 return new By(io.appium.java_client.MobileBy.AndroidViewTag(tag));175 }176 /**177 * This locator strategy is available only if OpenCV libraries and178 * NodeJS bindings are installed on the server machine.179 *180 * @param b64Template base64-encoded template image string. Supported image formats are the same181 * as for OpenCV library.182 * @return an instance of {@link ByImage}183 * @see <a href="https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md">184 * The documentation on Image Comparison Features</a>185 * @see <a href="https://github.com/appium/appium-base-driver/blob/master/lib/basedriver/device-settings.js">186 * The settings available for lookup fine-tuning</a>187 * @since Appium 1.8.2188 */189 public static By image(final String b64Template) {190 return new By(io.appium.java_client.MobileBy.image(b64Template));191 }192 /**193 * This type of locator requires the use of the 'customFindModules' capability and a194 * separately-installed element finding plugin.195 *196 * @param selector selector to pass to the custom element finding plugin197 * @return an instance of {@link ByCustom}198 * @since Appium 1.9.2199 */200 public static By custom(final String selector) {201 return new By(io.appium.java_client.MobileBy.custom(selector));202 }203}...
WhosHomeNotifyMeWhenPage.java
Source:WhosHomeNotifyMeWhenPage.java
1package com.cs.arris.Pages;2import java.util.List;3import org.apache.commons.lang3.time.StopWatch;4import org.openqa.selenium.support.PageFactory;5import com.cs.arris.Base.ParentClass;6import com.cs.arris.Interface.Page;7import com.cs.arris.Utilities.Direction;8import com.cs.arris.Utilities.TestUtils;9import io.appium.java_client.MobileBy;10import io.appium.java_client.MobileBy.ByIosClassChain;11import io.appium.java_client.MobileElement;12import io.appium.java_client.pagefactory.AndroidBy;13import io.appium.java_client.pagefactory.AndroidFindAll;14import io.appium.java_client.pagefactory.AndroidFindBy;15import io.appium.java_client.pagefactory.AppiumFieldDecorator;16import io.appium.java_client.pagefactory.iOSXCUITFindBy;17public class WhosHomeNotifyMeWhenPage extends ParentClass implements Page {18 public TestUtils utils = new TestUtils();19 20 @iOSXCUITFindBy(xpath = "//XCUIElementTypeButton[@name=\"WH_Notify_Screen_NavigationBar_Button_Help\"]")21 public MobileElement helpButton;22 @iOSXCUITFindBy(xpath = "//XCUIElementTypeStaticText[@name=\"WH_Notify_Screen_NavigationBar_Title\"]")23 public MobileElement notifyMeTitle;24 25 @iOSXCUITFindBy(xpath = "//XCUIElementTypeButton[@name=\"WH_Notify_Screen_NavigationBar_Button_Back\"]")26 public MobileElement backButton;27 @iOSXCUITFindBy(xpath = "//XCUIElementTypeStaticText[@name=\"WH_Notify_Screen_Label_Message\"]")28 public MobileElement notifyMeMessage;29 @iOSXCUITFindBy(xpath = "//XCUIElementTypeStaticText[@name=\"WH_Notify_Screen_Label_Tap\"]")30 public MobileElement tapLabel;31 32 @iOSXCUITFindBy(xpath = "//XCUIElementTypeButton[@name=\"WH_Notify_Screen_Button_Add\"]")33 public MobileElement addMembers;34 35 public WhosHomeNotifyMeWhenPage() {36 PageFactory.initElements(new AppiumFieldDecorator(super.getDriver()), this);37 }38 public boolean clickBackButton() {39 if (backButton.isDisplayed()) {40 click(backButton);41 utils.log().info("Clicked on back Button");42 return true;43 } else {44 utils.log().info("Back Button is not displayed");45 return false;46 }47 }48 49 public boolean clickHelpButton() {50 if (helpButton.isDisplayed()) {51 click(helpButton);52 utils.log().info("Clicked on Help Button");53 return true;54 } else {55 utils.log().info("Help Button is not displayed");56 return false;57 }58 }59 60 public boolean clickaddButton() {61 if (addMembers.isDisplayed()) {62 click(addMembers);63 utils.log().info("Clicked on Add Members plus Button");64 return true;65 } else {66 utils.log().info("Add Members plus Button is not displayed");67 return false;68 }69 }70 71 public WhosHomeNotifyMeWhenHelpPage getWhosHomeNotifyMeWhenHelpPage() {72 WhosHomeNotifyMeWhenHelpPage notifyMeHelpPage = new WhosHomeNotifyMeWhenHelpPage();73 return notifyMeHelpPage;74 }75 76 public WhosHomeAddNewNotificationPage getAddNewNotificationPageObject() {77 WhosHomeAddNewNotificationPage notifyMePage = new WhosHomeAddNewNotificationPage();78 return notifyMePage;79 }80 public boolean verifyPickADeviceDialogUI() {81 82 utils.log().info(" ");83 utils.log().info("************************************************");84 utils.log().info("Details of UI Elements on Whos Home Welcome Page");85 utils.log().info("************************************************");86 try {87 if (notifyMeTitle.isDisplayed())88 utils.log().info(notifyMeTitle.getText() + " Title text is displayed");89 else90 utils.log().info("NOTIFY ME WHEN Title text is not displayed");91 if (backButton.isDisplayed())92 utils.log().info("Back button is displayed");93 else94 utils.log().info("Back button is not displayed");95 96 if (helpButton.isDisplayed())97 utils.log().info("Help button is displayed");98 else99 utils.log().info("Help button is not displayed");100 101 try{102 if (notifyMeMessage.isDisplayed())103 utils.log().info(notifyMeMessage.getText() + " message is displayed");104 }catch(Exception e) {105 utils.log().info("Schedule events to receive notification when a household member enters or exits the house message is not displayed");106 }107 108 try{109 if (tapLabel.isDisplayed())110 utils.log().info(tapLabel.getText() + " message is displayed");111 }catch(Exception e) {112 utils.log().info("Tap (+) icon below to add one message is not displayed");113 }114 if (addMembers.isDisplayed())115 utils.log().info("Add members plus button is displayed");116 else117 utils.log().info("Add members plus button is not displayed");118 return true;119 } catch (Exception e) {120 return false;121 }122 }123 124 public boolean enableNotification(String selector) {125 try {126 String str = super.getDriver().findElement(MobileBy.iOSClassChain(selector)).getAttribute("value");127 int value = Integer.parseInt(str);128 if(value == 0)129 {130 super.getDriver().findElement(MobileBy.iOSClassChain(selector)).click();131 utils.log().info("Notification is enabled");132 }else {133 utils.log().info("Notification is already enabled");134 }135 return true;136 } catch(Exception e) {137 utils.log().info("Issue in enabling Notifications for selected user");138 return true;139 }140 }141 public boolean disableNotification(String selector) {142 try {143 String str = super.getDriver().findElement(MobileBy.iOSClassChain(selector)).getAttribute("value");144 int value = Integer.parseInt(str);145 if(value == 1)146 {147 super.getDriver().findElement(MobileBy.iOSClassChain(selector)).click();148 utils.log().info("Notification is disabled");149 }else {150 utils.log().info("Notification is already disabled");151 }152 return true;153 } catch(Exception e) {154 utils.log().info("Issue in disabling Notifications for selected user");155 return true;156 }157 }158 159 160 161 public boolean verifyMemberNotifications()162 {163 utils.log().info(" ");164 utils.log().info("*************************************************");165 utils.log().info("List of Notifications in the NOTIFY ME WHEN Page ");166 utils.log().info("*************************************************");167 168 int size = super.getDriver().findElements(MobileBy.iOSClassChain("**/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable")).size();169 try {170 for (int i = 1; i <= size; i++) {171 utils.log().info(" ");172 utils.log().info("Notification : " + i);173 utils.log().info("-------------------");174 175 List<MobileElement> entity = (List<MobileElement>) super.getDriver().findElementsByXPath(176 "//XCUIElementTypeApplication[@name=\"SBC Test\"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell["+i+"]");177 for (MobileElement e : entity) {178 utils.log().info("Member Name : " + e.findElementByXPath("//XCUIElementTypeStaticText[@name=\"WH_Notify_Screen_Label_MemberName["+i+"]\"]").getText());179 utils.log().info("Notification : " + e.findElementByXPath("//XCUIElementTypeStaticText[@name=\"WH_Notify_Screen_Label_Occur["+i+"]\"]").getText());180 utils.log().info("Member will be notified : " + e.findElementByXPath("//XCUIElementTypeStaticText[@name=\"WH_Notify_Screen_Label_Event["+i+"]\"]").getText());181 }182 }183 return true;184 } catch (Exception exp) {185 utils.log().info("Error in retrieving Member Notifications ");186 return false;187 }188 }189 190 @Override191 public boolean isAt() {192 if (notifyMeTitle.isDisplayed()) {193 utils.log().info("On NOTIFY ME WHEN Page");194 return true;195 } else {196 utils.log().info("Not on NOTIFY ME WHEN Page");197 return false;198 }199 }200}...
ByParserTest.java
Source:ByParserTest.java
1/*2 * MIT License3 *4 * Copyright (c) 2018 Excelium5 *6 * Permission is hereby granted, free of charge, to any person obtaining a copy7 * of this software and associated documentation files (the "Software"), to deal8 * in the Software without restriction, including without limitation the rights9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10 * copies of the Software, and to permit persons to whom the Software is11 * furnished to do so, subject to the following conditions:12 *13 * The above copyright notice and this permission notice shall be included in all14 * copies or substantial portions of the Software.15 *16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE22 * SOFTWARE.23 */24package excelium.core.by;25import excelium.core.driver.ContextAwareWebDriver;26import io.appium.java_client.MobileBy;27import mockit.Expectations;28import mockit.Mocked;29import org.junit.Assert;30import org.junit.Test;31import org.openqa.selenium.By;32import org.openqa.selenium.support.ByIdOrName;33/**34 * Tests for {@link ByParser}.35 *36 * @author PhungDucKien37 * @since 2018.05.1638 */39public class ByParserTest {40 @Mocked41 private ContextAwareWebDriver webDriver;42 @Test43 public void testParseByWeb() {44 new Expectations() {{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}...
LoginScreen.java
Source:LoginScreen.java
1package IOS.screen;2import com.aventstack.extentreports.Status;3import framework.screen.STWScreen;4import io.appium.java_client.AppiumDriver;5import io.appium.java_client.MobileElement;6import io.appium.java_client.pagefactory.WithTimeout;7import io.appium.java_client.pagefactory.iOSXCUITFindBy;8import org.openqa.selenium.support.ui.ExpectedConditions;9import org.openqa.selenium.support.ui.WebDriverWait;10import java.io.IOException;11import java.time.temporal.ChronoUnit;12public class LoginScreen extends STWScreen {13 public LoginScreen(AppiumDriver driver) {14 super((AppiumDriver) driver);15 }16 @iOSXCUITFindBy( iOSClassChain ="**/XCUIElementTypeTextField[`name == \"CreateAccountViewController_companyIdTextField\"`]" )17 private MobileElement companyId ;18 @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeTextField[`name == \"CreateAccountViewController_phoneNumTextField\"`]")19 private MobileElement phoneNumTextField ;20 @iOSXCUITFindBy(accessibility = "CreateAccountViewController_phoneCodeLabel")21 private MobileElement phoneCodeLabel ;22 @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeSearchField[`label == \"Search\"`]")23 private MobileElement searchBar ;24 @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeButton[`label == \"Mailboxes\"`]")25 private MobileElement mailBoxes;26 @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeNavigationBar[`name == \"ConversationView\"`]/XCUIElementTypeButton[1]")27 private MobileElement backtoInbox;28 public MobileElement getBacktoInbox() {29 return backtoInbox;30 }31 public MobileElement getMailBoxes() {32 return mailBoxes;33 }34 public MobileElement getUseCurrentDevice() {35 return useCurrentDevice;36 }37 @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeButton[`label == \"Use current device\"`]")38 private MobileElement useCurrentDevice ;39 public MobileElement getInboxBtn() {40 return InboxBtn;41 }42 @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeCell[`label == \"Inbox\"`]")43 private MobileElement InboxBtn ;44 @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeStaticText[`label == \"Team on the run\"`][1]")45 private MobileElement MailRecieved ;46 @WithTimeout(time = 5L, chronoUnit = ChronoUnit.SECONDS)47 @iOSXCUITFindBy(xpath = "//*[contains(@label,'com.streamwide.totrInHouseDev')]")48 private MobileElement Link ;49 @WithTimeout(time = 5L, chronoUnit = ChronoUnit.SECONDS)50 @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeCell[`label == \"216, Tunisia (\u202BتÙÙس\u202C\u200E)\"`]")51 private MobileElement CountryCell ;52 // @WithTimeout(time = 35L, chronoUnit = ChronoUnit.SECONDS)53 // private MobileElement CountryCell = new MobileBy.ByIosClassChain("**/XCUIElementTypeCell[`label == \"216, Tunisia (\u202BتÙÙس\u202C\u200E)\"`]");54 @WithTimeout(time = 35L, chronoUnit = ChronoUnit.SECONDS)55 @iOSXCUITFindBy(accessibility = "CreateAccountViewController_registerButton")56 private MobileElement registerButton ;57 public MobileElement getOpenPopupLink() {58 return openPopupLink;59 }60 @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeButton[`label == \"Open\"`]")61 private MobileElement openPopupLink ;62 @WithTimeout(time = 35L, chronoUnit = ChronoUnit.SECONDS)63 @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeButton[`label == \"Next\"`]")64 private MobileElement validButton;65 public MobileElement getWelcomeLabel() {66 return WelcomeLabel;67 }68 @WithTimeout(time = 35L, chronoUnit = ChronoUnit.SECONDS)69 @iOSXCUITFindBy(iOSClassChain = "**/XCUIElementTypeStaticText[`label == \"Welcome!\"`]")70 private MobileElement WelcomeLabel;71 public MobileElement getCompanyId() {72 return companyId;73 }74 public MobileElement getPhoneNumTextField() {75 return phoneNumTextField;76 }77 public MobileElement getPhoneCodeLabel() {78 return phoneCodeLabel;79 }80 public MobileElement getMailRecieved() {81 return MailRecieved;82 }83 public MobileElement getLink() {84 return Link;85 }86 public MobileElement getSearchBar() {87 return searchBar;88 }89 public MobileElement getCountryCell() {90 return CountryCell;91 }92 public MobileElement getRegisterButton() {93 return registerButton;94 }95 public MobileElement getValidButton() {96 return validButton;97 }98 public void setCompanyId(String company){99 clearTextFully(companyId);100 companyId.setValue(company);101 }102 public void clickOnContinue(){103 registerButton.click();104 }105 public void setPhoneNumber(String phone){106 WebDriverWait wait = new WebDriverWait(mDriver, 5);107 wait.until(ExpectedConditions.visibilityOf(phoneNumTextField));108 clearTextFully(phoneNumTextField);109 phoneNumTextField.setValue(phone);110 }111 public void clickCountryCodeflag(){112 phoneCodeLabel.click();113 }114 public void searchCountryAndClick(String countryName) throws InterruptedException {115 searchBar.sendKeys(countryName);116 Thread.sleep(500);117 hideKeyboardIos();118 // Thread.sleep(500);119 selectorToClick("Tunisia");120 }121 public void ClickOnGO(){122 registerButton.click();123 }124 public void openActivationLinkFromMail(String bundleId){125 openApp(bundleId);126 if (isElementDisplayed(mailBoxes))127 mailBoxes.click();128 if (isElementDisplayed(backtoInbox))129 backtoInbox.click();130 if (isElementDisplayed(InboxBtn))131 InboxBtn.click();132 holdAndScrollDown(6, 2700, 0.3, 0.5, 0.5);133 MailRecieved.click();134 mLogger.log(Status.PASS, "5 : open activation mail");135 tapOnElementPosition(Link,0.5,0.5);136 mLogger.log(Status.PASS, "6 : open activation link");137 if (isElementDisplayed(openPopupLink))138 openPopupLink.click();139 }140 public void verifyWelcomePage() throws IOException, InterruptedException {141 checkIfElementIsPresent(getWelcomeLabel(),"welcome");142 mLogger.log(Status.PASS, "check welcome page and login success");143 }144}...
myProfile.java
Source:myProfile.java
1package pages;2import org.junit.jupiter.api.Assertions;3import org.openqa.selenium.By;4import Utils.GeneratedUtils;5import io.appium.java_client.MobileBy;6import nexar_tests.baseTest;7public class myProfile {8 public static void clickUserInformation() {9 // Click 'user information'10 try {11 GeneratedUtils.sleep(500);12 By element = By.xpath(selectors.myProfile.userInformation);13 System.out.println("Clicking on user information");14 baseTest.driver.findElement(element).click();15 } catch (Exception e) {16 e.printStackTrace();17 }18 }19 public static void clickUserName() {20 // Click 'user name'21 try {22 GeneratedUtils.sleep(500);23 By element = MobileBy.iOSNsPredicateString(selectors.myProfile.userName);24 System.out.println("Clicking on user name");25 baseTest.driver.findElement(element).click();26 } catch (Exception e) {27 e.printStackTrace();28 }29 }30 public static void clickUserNameField() {31 try {32 GeneratedUtils.sleep(500);33 By element = By.xpath(selectors.myProfile.userNamefield);34 System.out.println("Clicking on user name field");35 baseTest.driver.findElement(element).click();36 } catch (Exception e) {37 e.printStackTrace();38 }39 }40 public static void writeNewUserName(String newUsername) {41 try {42 // 7. Type 'test' in 'XCUIELEMENTTYPETEXTFIELD3'43 GeneratedUtils.sleep(500);44 By element = By.xpath(selectors.myProfile.userNamefield);45 System.out.println("clearing and writing the new name");46 baseTest.driver.findElement(element).clear();47 baseTest.driver.findElement(element).sendKeys(newUsername);48 } catch (Exception e) {49 e.printStackTrace();50 }51 }52 public static void clickKBDDone() {53 // Click 'user information'54 try {55 // 8. Click 'done1'56 GeneratedUtils.sleep(500);57 By element = MobileBy.ByIosClassChain.iOSClassChain(selectors.myProfile.KBDDone);58 System.out.println("Clicking KeyBoard done");59 baseTest.driver.findElement(element).click();60 } catch (Exception e) {61 e.printStackTrace();62 }63 }64 public static void clickDoneandBack() {65 // Click 'user information'66 try {67 // 9. Click 'Done2'68 GeneratedUtils.sleep(500);69 By element = By.xpath(selectors.myProfile.doneForm);70 System.out.println("Clicking update form done");71 baseTest.driver.findElement(element).click();72 } catch (Exception e) {73 e.printStackTrace();74 }75 }76 public static void editMyinformation(String newUsername) {77 try {78 System.out.println("updating the user infromation");79 clickUserName();80 clickUserNameField();81 writeNewUserName(newUsername);82 clickKBDDone();83 clickDoneandBack();84 System.out.println("update userinformation done");85 } catch (Exception e) {86 e.printStackTrace();87 }88 }89 public static void updateLastNameValidtion(String newUsername) {90 try {91 System.out.println("validating user information");92 GeneratedUtils.sleep(500);93 By element = By.xpath(selectors.myProfile.userNamefieldValidation);94 String currentName = baseTest.driver.findElement(element).getText();95 System.out.println("current name is: " + currentName);96 Assertions.assertTrue(currentName.contains(newUsername), "Validtion failed name is: " + currentName);97 System.out.println("validtion success user information");98 } catch (Exception e) {99 e.printStackTrace();100 }101 }102}...
UIElement.java
Source:UIElement.java
1package com.milestone.uifactory;2import io.appium.java_client.MobileBy;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import java.util.List;9public class UIElement {10 By locator = null;11 public UIElement(By locator) {12 this.locator = locator;13 }14 public WebElement getElement() {15 WebDriver driver = DriverFactory.getDriver();16 return driver.findElement(locator);17 }18 public List<WebElement> getElements() {19 return DriverFactory.getDriver().findElements(locator);20 }21 public static UIElement byClassName(String locator) {22 return new UIElement(By.className(locator));23 }24 public static UIElement byId(String locator) {25 return new UIElement(By.id(locator));26 }27 public static UIElement byXpath(String locator) {28 return new UIElement(By.xpath(locator));29 }30 public static UIElement byAccessibilityID(String locator) {31 return new UIElement(MobileBy.AccessibilityId(locator));32 }33 public static UIElement byIOSClassChain(String locator) {34 return new UIElement(MobileBy.iOSClassChain(locator));35 }36 public static void navigateToURL(String URL) {37 DriverFactory.getDriver().get(URL);38 }39 public static String getURL() {40 return DriverFactory.getDriver().getCurrentUrl();41 }42 public static String getTitle() {43 return DriverFactory.getDriver().getTitle();44 }45 public static void waitForTitle(int time, String titleContains) {46 WebDriverWait wait = new WebDriverWait(DriverFactory.getDriver(), time);47 wait.until(ExpectedConditions.titleContains(titleContains));48 }49 public UIElement waitFor(int timeout) {50 long startTime= System.currentTimeMillis();51 do {52 try {53 if(getElement().isDisplayed()) break;;54 } catch (Exception e) {55 continue;56 }57 } while ((System.currentTimeMillis()- startTime) < timeout * 1000);58 return this;59 }60}...
IosLocatorConverter.java
Source:IosLocatorConverter.java
1package com.github.mishaninss.arma.uidriver.ios;2import com.github.mishaninss.arma.uidriver.LocatorType;3import com.github.mishaninss.arma.uidriver.webdriver.LocatorConverter;4import io.appium.java_client.MobileBy;5import org.openqa.selenium.By;6import org.springframework.context.annotation.Profile;7import org.springframework.stereotype.Component;8/**9 * @author Sergey Mishanin Class for locators handling.10 */11@Component12@Profile("ios")13public final class IosLocatorConverter extends LocatorConverter {14 public static final String LOCATOR_TYPE_IOS_CLASS_CHAIN = "iosclasschain";15 public static final String LOCATOR_TYPE_IOS_NS_PREDICATE_STRING = "iosnspredicatestring";16 public static final String LOCATOR_ACCESSIBILITY_ID = "accessibilityid";17 public IosLocatorConverter() {18 addConverter(LOCATOR_TYPE_IOS_CLASS_CHAIN, this::byIosClassChain);19 addConverter(LOCATOR_TYPE_IOS_NS_PREDICATE_STRING, this::byIosNsPredicateString);20 addConverter(LOCATOR_ACCESSIBILITY_ID, this::byAccessibilityId);21 addConverter(LocatorType.ID, this::byAccessibilityId);22 }23 /**24 * Converter for type "iosClassChain"25 */26 public By byIosClassChain(final String locator) {27 return MobileBy.iOSClassChain(locator);28 }29 /**30 * Converter for type "iOSNsPredicateString"31 */32 public By byIosNsPredicateString(final String locator) {33 return MobileBy.iOSNsPredicateString(locator);34 }35 /**36 * Converter for type "accessibilityId"37 */38 public By byAccessibilityId(final String locator) {39 return MobileBy.AccessibilityId(locator);40 }41}...
MobileBy.ByIosClassChain
Using AI Code Generation
1MobileBy.ByIosClassChain iosClassChain = new MobileBy.ByIosClassChain("XCUIElementTypeWindow[0]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]");2driver.findElement(iosClassChain).click();3ios_class_chain = MobileBy.ByIosClassChain("XCUIElementTypeWindow[0]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]")4driver.find_element(by=ios_class_chain).click()5ios_class_chain = MobileBy::ByIosClassChain.new("XCUIElementTypeWindow[0]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]")6driver.find_element(ios_class_chain).click()7const iosClassChain = MobileBy.ByIosClassChain("XCUIElementTypeWindow[0]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]");8driver.findElement(iosClassChain).click();9const iosClassChain = MobileBy.ByIosClassChain("XCUIElementTypeWindow[0]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]");10driver.findElement(iosClassChain).click();11const iosClassChain = MobileBy.ByIosClassChain("XCUIElementTypeWindow[0]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]");12driver.findElement(iosClassChain).click();13const iosClassChain = MobileBy.ByIosClassChain("XCUIElementTypeWindow[0]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]");14driver.findElement(iosClassChain).click();
MobileBy.ByIosClassChain
Using AI Code Generation
1import io.appium.java_client.MobileBy;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.remote.MobileCapabilityType;4import org.openqa.selenium.remote.DesiredCapabilities;5import java.net.MalformedURLException;6import java.net.URL;7public class appium {8 public static void main(String[] args) throws MalformedURLException, InterruptedException {9 DesiredCapabilities dc = new DesiredCapabilities();10 dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel 3a API 28");11 dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");12 dc.setCapability("appPackage", "com.android.calculator2");13 dc.setCapability("appActivity", "com.android.calculator2.Calculator");14 dc.setCapability("automationName", "UiAutomator2");
MobileBy.ByIosClassChain
Using AI Code Generation
1import io.appium.java_client.MobileBy;2import io.appium.java_client.MobileElement;3import io.appium.java_client.android.AndroidDriver;4import java.net.MalformedURLException;5import java.net.URL;6import org.openqa.selenium.remote.DesiredCapabilities;7public class ClassChainLocator {8 public static void main(String[] args) throws MalformedURLException {9 DesiredCapabilities caps = new DesiredCapabilities();10 caps.setCapability("browserstack.user", "BROWSERSTACK_USERNAME");11 caps.setCapability("browserstack.key", "BROWSERSTACK_ACCESS_KEY");12 caps.setCapability("device", "Google Pixel 3");13 caps.setCapability("os_version", "9.0");14 caps.setCapability("project", "First Java Project");15 caps.setCapability("build", "Java Android");16 caps.setCapability("name", "first_test");17 AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(18 MobileElement element = driver.findElement(MobileBy.ByIosClassChain19 .iosClassChain("**/XCUIElementTypeOther[`name == \"TextFields\"`]/XCUIElementTypeOther[2]"));20 List<MobileElement> elements = driver.findElements(MobileBy.ByIosClassChain21 .iosClassChain("**/XCUIElementTypeOther[`name == \"TextFields\"`]/XCUIElementTypeOther[2]"));22 driver.quit();23 }24}25# importing required packages26from appium import webdriver27from selenium.webdriver.common.by import By28from selenium.webdriver.support.ui import WebDriverWait
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!