How to use AppiumBy.ByImage class of io.appium.java_client package

Best io.appium code snippet using io.appium.java_client.AppiumBy.ByImage

MobileBy.java

Source:MobileBy.java Github

copy

Full Screen

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 java.io.Serializable;18import org.openqa.selenium.By;19/**20 * Appium locating strategies.21 *22 * @deprecated Use {@link AppiumBy} instead.23 */24@SuppressWarnings("serial")25@Deprecated26public abstract class MobileBy extends AppiumBy {27 protected MobileBy(String selector, String locatorString, String locatorName) {28 super(selector, locatorString, locatorName);29 }30 /**31 * Refer to https://developer.android.com/training/testing/ui-automator32 * @deprecated Use {@link AppiumBy#androidUIAutomator(String)} instead.33 * @param uiautomatorText is Android UIAutomator string34 * @return an instance of {@link ByAndroidUIAutomator}35 */36 @Deprecated37 public static By AndroidUIAutomator(final String uiautomatorText) {38 return new ByAndroidUIAutomator(uiautomatorText);39 }40 /**41 * About Android accessibility42 * https://developer.android.com/intl/ru/training/accessibility/accessible-app.html43 * About iOS accessibility44 * https://developer.apple.com/library/ios/documentation/UIKit/Reference/45 * UIAccessibilityIdentification_Protocol/index.html46 * @deprecated Use {@link AppiumBy#accessibilityId(String)} instead.47 * @param accessibilityId id is a convenient UI automation accessibility Id.48 * @return an instance of {@link ByAndroidUIAutomator}49 */50 @Deprecated51 public static By AccessibilityId(final String accessibilityId) {52 return new ByAccessibilityId(accessibilityId);53 }54 /**55 * This locator strategy is available in XCUITest Driver mode.56 * @deprecated Use {@link AppiumBy#iOSClassChain(String)} instead.57 * @param iOSClassChainString is a valid class chain locator string.58 * See <a href="https://github.com/facebookarchive/WebDriverAgent/wiki/Class-Chain-Queries-Construction-Rules">59 * the documentation</a> for more details60 * @return an instance of {@link ByIosClassChain}61 */62 @Deprecated63 public static By iOSClassChain(final String iOSClassChainString) {64 return new ByIosClassChain(iOSClassChainString);65 }66 /**67 * This locator strategy is only available in Espresso Driver mode.68 * @deprecated Use {@link AppiumBy#androidDataMatcher(String)} instead.69 * @param dataMatcherString is a valid json string detailing hamcrest matcher for Espresso onData().70 * See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">71 * the documentation</a> for more details72 * @return an instance of {@link ByAndroidDataMatcher}73 */74 @Deprecated75 public static By androidDataMatcher(final String dataMatcherString) {76 return new ByAndroidDataMatcher(dataMatcherString);77 }78 /**79 * This locator strategy is only available in Espresso Driver mode.80 * @deprecated Use {@link AppiumBy#androidViewMatcher(String)} instead.81 * @param viewMatcherString is a valid json string detailing hamcrest matcher for Espresso onView().82 * See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">83 * the documentation</a> for more details84 * @return an instance of {@link ByAndroidViewMatcher}85 */86 @Deprecated87 public static By androidViewMatcher(final String viewMatcherString) {88 return new ByAndroidViewMatcher(viewMatcherString);89 }90 /**91 * This locator strategy is available in XCUITest Driver mode.92 * @deprecated Use {@link AppiumBy#iOSNsPredicateString(String)} instead.93 * @param iOSNsPredicateString is an iOS NsPredicate String94 * @return an instance of {@link ByIosNsPredicate}95 */96 @Deprecated97 public static By iOSNsPredicateString(final String iOSNsPredicateString) {98 return new ByIosNsPredicate(iOSNsPredicateString);99 }100 /**101 * The Windows UIAutomation selector.102 * @deprecated Not supported on the server side.103 * @param windowsAutomation The element name in the Windows UIAutomation selector104 * @return an instance of {@link MobileBy.ByWindowsAutomation}105 */106 @Deprecated107 public static By windowsAutomation(final String windowsAutomation) {108 return new ByWindowsAutomation(windowsAutomation);109 }110 /**111 * This locator strategy is available in Espresso Driver mode.112 * @deprecated Use {@link AppiumBy#androidViewTag(String)} instead.113 * @since Appium 1.8.2 beta114 * @param tag is an view tag string115 * @return an instance of {@link ByAndroidViewTag}116 */117 @Deprecated118 public static By AndroidViewTag(final String tag) {119 return new ByAndroidViewTag(tag);120 }121 /**122 * This locator strategy is available only if OpenCV libraries and123 * NodeJS bindings are installed on the server machine.124 *125 * @deprecated Use {@link AppiumBy#image(String)} instead.126 * @see <a href="https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md">127 * The documentation on Image Comparison Features</a>128 * @see <a href="https://github.com/appium/appium-base-driver/blob/master/lib/basedriver/device-settings.js">129 * The settings available for lookup fine-tuning</a>130 * @since Appium 1.8.2131 * @param b64Template base64-encoded template image string. Supported image formats are the same132 * as for OpenCV library.133 * @return an instance of {@link ByImage}134 */135 @Deprecated136 public static By image(final String b64Template) {137 return new ByImage(b64Template);138 }139 /**140 * This type of locator requires the use of the 'customFindModules' capability and a141 * separately-installed element finding plugin.142 *143 * @deprecated Use {@link AppiumBy#custom(String)} instead.144 * @param selector selector to pass to the custom element finding plugin145 * @return an instance of {@link ByCustom}146 * @since Appium 1.9.2147 */148 @Deprecated149 public static By custom(final String selector) {150 return new ByCustom(selector);151 }152 /**153 * Refer to https://developer.android.com/training/testing/ui-automator154 *155 * @deprecated Use {@link AppiumBy.ByAndroidUIAutomator} instead.156 */157 @Deprecated158 public static class ByAndroidUIAutomator extends AppiumBy.ByAndroidUIAutomator {159 public ByAndroidUIAutomator(String uiautomatorText) {160 super(uiautomatorText);161 }162 @Override public String toString() {163 return "By.AndroidUIAutomator: " + getRemoteParameters().value();164 }165 }166 /**167 * About Android accessibility168 * https://developer.android.com/intl/ru/training/accessibility/accessible-app.html169 * About iOS accessibility170 * https://developer.apple.com/library/ios/documentation/UIKit/Reference/171 * UIAccessibilityIdentification_Protocol/index.html172 * @deprecated Use {@link AppiumBy.ByAccessibilityId} instead.173 */174 @Deprecated175 public static class ByAccessibilityId extends AppiumBy.ByAccessibilityId {176 public ByAccessibilityId(String accessibilityId) {177 super(accessibilityId);178 }179 @Override public String toString() {180 return "By.AccessibilityId: " + getRemoteParameters().value();181 }182 }183 /**184 * This locator strategy is available in XCUITest Driver mode.185 * See <a href="https://github.com/facebookarchive/WebDriverAgent/wiki/Class-Chain-Queries-Construction-Rules">186 * the documentation</a> for more details187 * @deprecated Use {@link AppiumBy.ByIosClassChain} instead.188 */189 @Deprecated190 public static class ByIosClassChain extends AppiumBy.ByIosClassChain {191 protected ByIosClassChain(String locatorString) {192 super(locatorString);193 }194 @Override public String toString() {195 return "By.IosClassChain: " + getRemoteParameters().value();196 }197 }198 /**199 * This locator strategy is only available in Espresso Driver mode.200 * See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">201 * the documentation</a> for more details202 * @deprecated Use {@link AppiumBy.ByAndroidDataMatcher} instead.203 */204 @Deprecated205 public static class ByAndroidDataMatcher extends AppiumBy.ByAndroidDataMatcher {206 protected ByAndroidDataMatcher(String locatorString) {207 super(locatorString);208 }209 @Override public String toString() {210 return "By.AndroidDataMatcher: " + getRemoteParameters().value();211 }212 }213 /**214 * This locator strategy is only available in Espresso Driver mode.215 * See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">216 * the documentation</a> for more details217 * @deprecated Use {@link AppiumBy.ByAndroidViewMatcher} instead.218 */219 @Deprecated220 public static class ByAndroidViewMatcher extends AppiumBy.ByAndroidViewMatcher {221 protected ByAndroidViewMatcher(String locatorString) {222 super(locatorString);223 }224 @Override public String toString() {225 return "By.AndroidViewMatcher: " + getRemoteParameters().value();226 }227 }228 /**229 * This locator strategy is available in XCUITest Driver mode.230 * @deprecated Use {@link AppiumBy.ByIosNsPredicate} instead.231 */232 @Deprecated233 public static class ByIosNsPredicate extends AppiumBy.ByIosNsPredicate {234 protected ByIosNsPredicate(String locatorString) {235 super(locatorString);236 }237 @Override public String toString() {238 return "By.IosNsPredicate: " + getRemoteParameters().value();239 }240 }241 /**242 * The Windows UIAutomation selector.243 * @deprecated Not supported on the server side.244 */245 @Deprecated246 public static class ByWindowsAutomation extends MobileBy implements Serializable {247 protected ByWindowsAutomation(String locatorString) {248 super("-windows uiautomation", locatorString, "windowsAutomation");249 }250 @Override public String toString() {251 return "By.windowsAutomation: " + getRemoteParameters().value();252 }253 }254 /**255 * This locator strategy is available only if OpenCV libraries and256 * NodeJS bindings are installed on the server machine.257 * @deprecated Use {@link AppiumBy.ByImage} instead.258 */259 @Deprecated260 public static class ByImage extends AppiumBy.ByImage {261 protected ByImage(String b64Template) {262 super(b64Template);263 }264 @Override public String toString() {265 return "By.Image: " + getRemoteParameters().value();266 }267 }268 /**269 * This type of locator requires the use of the 'customFindModules' capability and a270 * separately-installed element finding plugin.271 * @deprecated Use {@link AppiumBy.ByCustom} instead.272 */273 @Deprecated274 public static class ByCustom extends AppiumBy.ByCustom {275 protected ByCustom(String selector) {276 super(selector);277 }278 @Override public String toString() {279 return "By.Custom: " + getRemoteParameters().value();280 }281 }282 /**283 * This locator strategy is available in Espresso Driver mode.284 * @deprecated Use {@link AppiumBy.ByAndroidViewTag} instead.285 */286 @Deprecated287 public static class ByAndroidViewTag extends AppiumBy.ByAndroidViewTag {288 public ByAndroidViewTag(String tag) {289 super(tag);290 }291 @Override public String toString() {292 return "By.AndroidViewTag: " + getRemoteParameters().value();293 }294 }295}...

Full Screen

Full Screen

AppiumBy.java

Source:AppiumBy.java Github

copy

Full Screen

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 lombok.Getter;18import org.apache.commons.lang3.Validate;19import org.openqa.selenium.By;20import org.openqa.selenium.By.Remotable;21import org.openqa.selenium.SearchContext;22import org.openqa.selenium.WebElement;23import java.io.Serializable;24import java.util.List;25public abstract class AppiumBy extends By implements Remotable {26 @Getter private final Parameters remoteParameters;27 private final String locatorName;28 protected AppiumBy(String selector, String locatorString, String locatorName) {29 Validate.notBlank(locatorString, "Must supply a not empty locator value.");30 this.remoteParameters = new Parameters(selector, locatorString);31 this.locatorName = locatorName;32 }33 @Override public List<WebElement> findElements(SearchContext context) {34 return context.findElements(this);35 }36 @Override public WebElement findElement(SearchContext context) {37 return context.findElement(this);38 }39 @Override public String toString() {40 return String.format("%s.%s: %s", AppiumBy.class.getSimpleName(), locatorName, remoteParameters.value());41 }42 /**43 * About Android accessibility44 * https://developer.android.com/intl/ru/training/accessibility/accessible-app.html45 * About iOS accessibility46 * https://developer.apple.com/library/ios/documentation/UIKit/Reference/47 * UIAccessibilityIdentification_Protocol/index.html48 * @param accessibilityId id is a convenient UI automation accessibility Id.49 * @return an instance of {@link AppiumBy.ByAndroidUIAutomator}50 */51 public static By accessibilityId(final String accessibilityId) {52 return new ByAccessibilityId(accessibilityId);53 }54 /**55 * This locator strategy is only available in Espresso Driver mode.56 * @param dataMatcherString is a valid json string detailing hamcrest matcher for Espresso onData().57 * See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">58 * the documentation</a> for more details59 * @return an instance of {@link AppiumBy.ByAndroidDataMatcher}60 */61 public static By androidDataMatcher(final String dataMatcherString) {62 return new ByAndroidDataMatcher(dataMatcherString);63 }64 /**65 * Refer to https://developer.android.com/training/testing/ui-automator66 * @param uiautomatorText is Android UIAutomator string67 * @return an instance of {@link AppiumBy.ByAndroidUIAutomator}68 */69 public static By androidUIAutomator(final String uiautomatorText) {70 return new ByAndroidUIAutomator(uiautomatorText);71 }72 /**73 * This locator strategy is only available in Espresso Driver mode.74 * @param viewMatcherString is a valid json string detailing hamcrest matcher for Espresso onView().75 * See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">76 * the documentation</a> for more details77 * @return an instance of {@link AppiumBy.ByAndroidViewMatcher}78 */79 public static By androidViewMatcher(final String viewMatcherString) {80 return new ByAndroidViewMatcher(viewMatcherString);81 }82 /**83 * This locator strategy is available in Espresso Driver mode.84 * @since Appium 1.8.2 beta85 * @param tag is a view tag string86 * @return an instance of {@link ByAndroidViewTag}87 */88 public static By androidViewTag(final String tag) {89 return new ByAndroidViewTag(tag);90 }91 /**92 * For IOS it is the full name of the XCUI element and begins with XCUIElementType.93 * For Android it is the full name of the UIAutomator2 class (e.g.: android.widget.TextView)94 * @param selector the class name of the element95 * @return an instance of {@link ByClassName}96 */97 public static By className(final String selector) {98 return new ByClassName(selector);99 }100 /**101 * For IOS the element name.102 * For Android it is the resource identifier.103 * @param selector element id104 * @return an instance of {@link ById}105 */106 public static By id(final String selector) {107 return new ById(selector);108 }109 /**110 * For IOS the element name.111 * For Android it is the resource identifier.112 * @param selector element id113 * @return an instance of {@link ByName}114 */115 public static By name(final String selector) {116 return new ByName(selector);117 }118 /**119 * This type of locator requires the use of the 'customFindModules' capability and a120 * separately-installed element finding plugin.121 *122 * @param selector selector to pass to the custom element finding plugin123 * @return an instance of {@link ByCustom}124 * @since Appium 1.9.2125 */126 public static By custom(final String selector) {127 return new ByCustom(selector);128 }129 /**130 * This locator strategy is available only if OpenCV libraries and131 * NodeJS bindings are installed on the server machine.132 *133 * @see <a href="https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md">134 * The documentation on Image Comparison Features</a>135 * @see <a href="https://github.com/appium/appium-base-driver/blob/master/lib/basedriver/device-settings.js">136 * The settings available for lookup fine-tuning</a>137 * @since Appium 1.8.2138 * @param b64Template base64-encoded template image string. Supported image formats are the same139 * as for OpenCV library.140 * @return an instance of {@link ByImage}141 */142 public static By image(final String b64Template) {143 return new ByImage(b64Template);144 }145 /**146 * This locator strategy is available in XCUITest Driver mode.147 * @param iOSClassChainString is a valid class chain locator string.148 * See <a href="https://github.com/facebookarchive/WebDriverAgent/wiki/Class-Chain-Queries-Construction-Rules">149 * the documentation</a> for more details150 * @return an instance of {@link AppiumBy.ByIosClassChain}151 */152 public static By iOSClassChain(final String iOSClassChainString) {153 return new ByIosClassChain(iOSClassChainString);154 }155 /**156 * This locator strategy is available in XCUITest Driver mode.157 * @param iOSNsPredicateString is an iOS NsPredicate String158 * @return an instance of {@link AppiumBy.ByIosNsPredicate}159 */160 public static By iOSNsPredicateString(final String iOSNsPredicateString) {161 return new ByIosNsPredicate(iOSNsPredicateString);162 }163 public static class ByAccessibilityId extends AppiumBy implements Serializable {164 public ByAccessibilityId(String accessibilityId) {165 super("accessibility id", accessibilityId, "accessibilityId");166 }167 }168 public static class ByAndroidDataMatcher extends AppiumBy implements Serializable {169 protected ByAndroidDataMatcher(String locatorString) {170 super("-android datamatcher", locatorString, "androidDataMatcher");171 }172 }173 public static class ByAndroidUIAutomator extends AppiumBy implements Serializable {174 public ByAndroidUIAutomator(String uiautomatorText) {175 super("-android uiautomator", uiautomatorText, "androidUIAutomator");176 }177 }178 public static class ByAndroidViewMatcher extends AppiumBy implements Serializable {179 protected ByAndroidViewMatcher(String locatorString) {180 super("-android viewmatcher", locatorString, "androidViewMatcher");181 }182 }183 public static class ByAndroidViewTag extends AppiumBy implements Serializable {184 public ByAndroidViewTag(String tag) {185 super("-android viewtag", tag, "androidViewTag");186 }187 }188 public static class ById extends AppiumBy implements Serializable {189 protected ById(String selector) {190 super("id", selector, "id");191 }192 }193 public static class ByName extends AppiumBy implements Serializable {194 protected ByName(String selector) {195 super("name", selector, "name");196 }197 }198 public static class ByClassName extends AppiumBy implements Serializable {199 protected ByClassName(String selector) {200 super("class name", selector, "className");201 }202 }203 public static class ByCustom extends AppiumBy implements Serializable {204 protected ByCustom(String selector) {205 super("-custom", selector, "custom");206 }207 }208 public static class ByImage extends AppiumBy implements Serializable {209 protected ByImage(String b64Template) {210 super("-image", b64Template, "image");211 }212 }213 public static class ByIosClassChain extends AppiumBy implements Serializable {214 protected ByIosClassChain(String locatorString) {215 super("-ios class chain", locatorString, "iOSClassChain");216 }217 }218 public static class ByIosNsPredicate extends AppiumBy implements Serializable {219 protected ByIosNsPredicate(String locatorString) {220 super("-ios predicate string", locatorString, "iOSNsPredicate");221 }222 }223}...

Full Screen

Full Screen

LocatorMap.java

Source:LocatorMap.java Github

copy

Full Screen

1package qa.justtestlah.locator;2import static com.codeborne.selenide.Selenide.$;3import static com.codeborne.selenide.Selenide.$$;4import com.codeborne.selenide.ElementsCollection;5import com.codeborne.selenide.SelenideElement;6import io.appium.java_client.AppiumBy;7import java.util.HashMap;8import java.util.Map;9import java.util.Properties;10import java.util.regex.Matcher;11import java.util.regex.Pattern;12import org.apache.commons.lang3.tuple.Pair;13import org.openqa.selenium.By;14import org.slf4j.Logger;15import org.slf4j.LoggerFactory;16import qa.justtestlah.base.ByImage;17import qa.justtestlah.configuration.Platform;18import qa.justtestlah.stubs.OCR;19import qa.justtestlah.stubs.TemplateMatcher;20import qa.justtestlah.utils.ImageUtils;21/** Map to hold element locators. */22public class LocatorMap {23 private static final Logger LOG = LoggerFactory.getLogger(LocatorMap.class);24 private Map<String, Map<String, Map<String, Object>>> map;25 private Properties staticPlaceholders;26 private TemplateMatcher templateMatcher;27 private OCR ocr;28 private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("\\$\\{(\\w*)\\}");29 private static final String CSS = "css";30 private static final String XPATH = "xpath";31 private static final String ID = "id";32 private static final String ACCESIBILITY_ID = "accesibilityId";33 private static final String UIAUTOMATOR = "uiAutomator";34 private static final String IMAGE = "image"; // Appium35 private static final String OPENCV = "opencv";36 /** Default constructor. */37 public LocatorMap() {38 this.map = new HashMap<>();39 }40 /**41 * Construct a locator map from an existing {@link Map} object.42 *43 * @param map locator map44 * @param staticPlaceholders static placeholders to be replaced in any locator45 */46 public LocatorMap(47 Map<String, Map<String, Map<String, Object>>> map,48 Properties staticPlaceholders,49 TemplateMatcher templateMatcher,50 OCR ocr) {51 this.map = map;52 this.staticPlaceholders = staticPlaceholders;53 this.templateMatcher = templateMatcher;54 this.ocr = ocr;55 }56 /**57 * Get a Selenide locator.58 *59 * @param key locator key60 * @param platform platform61 * @param params locator key parameters62 * @return {@link SelenideElement}63 */64 public SelenideElement getLocator(String key, Platform platform, Object... params) {65 Map<String, Object> platformKey = getRawLocator(key, platform, params);66 if (platformKey == null) {67 LOG.error("Locator with key {} is undefined for platform {}.", key, platform);68 return null;69 }70 String type = platformKey.get("type").toString();71 String rawValue = platformKey.get("value").toString();72 LOG.debug("Getting locator {} of type {}", rawValue, type);73 if (type.equalsIgnoreCase(CSS)) {74 return $(By.cssSelector(formatValue(rawValue, params)));75 } else if (type.equalsIgnoreCase(XPATH)) {76 return $(By.xpath(formatValue(rawValue, params)));77 } else if (type.equalsIgnoreCase(ID)) {78 return $(By.id(formatValue(rawValue, params)));79 } else if (type.equalsIgnoreCase(ACCESIBILITY_ID)) {80 return $(AppiumBy.accessibilityId(formatValue(rawValue, params)));81 } else if (type.equalsIgnoreCase(UIAUTOMATOR)) {82 return $(AppiumBy.androidUIAutomator(formatValue(rawValue, params)));83 } else if (type.equalsIgnoreCase(IMAGE)) {84 return $(AppiumBy.image(ImageUtils.getImageAsBase64String(rawValue)));85 } else if (type.equalsIgnoreCase(OPENCV)) {86 return $(87 ByImage.image(88 formatValue(rawValue, params), getThreshold(platformKey), templateMatcher, ocr));89 } else {90 return $(formatValue(rawValue, params));91 }92 }93 /**94 * Get a Selenide collection locator.95 *96 * @param key locator key97 * @param platform platform98 * @param params locator key parameters99 * @return {@link ElementsCollection}100 */101 public ElementsCollection getCollectionLocator(String key, Platform platform, Object... params) {102 Map<String, Object> platformKey = getRawLocator(key, platform, params);103 String type = platformKey.get("type").toString();104 String rawValue = platformKey.get("value").toString();105 if (type.equalsIgnoreCase(CSS)) {106 return $$(By.cssSelector(formatValue(rawValue, params)));107 } else if (type.equalsIgnoreCase(XPATH)) {108 return $$(By.xpath(formatValue(rawValue, params)));109 } else if (type.equalsIgnoreCase(ID)) {110 return $$(By.id(formatValue(rawValue, params)));111 } else if (type.equalsIgnoreCase(ACCESIBILITY_ID)) {112 return $$(AppiumBy.accessibilityId(formatValue(rawValue, params)));113 } else if (type.equalsIgnoreCase(UIAUTOMATOR)) {114 return $$(AppiumBy.androidUIAutomator(formatValue(rawValue, params)));115 } else if (type.equalsIgnoreCase(IMAGE)) {116 return $$(AppiumBy.image(ImageUtils.getImageAsBase64String(rawValue)));117 } else if (type.equalsIgnoreCase(OPENCV)) {118 return $$(119 ByImage.image(120 formatValue(rawValue, params), getThreshold(platformKey), templateMatcher, ocr));121 } else {122 return $$(formatValue(rawValue, params));123 }124 }125 /**126 * Get the raw locator (type and value). This is exposed for logging purposes.127 *128 * @param key locator key129 * @param platform platform130 * @param params locator key parameters131 * @return {@link Pair}132 */133 public Map<String, Object> getRawLocator(String key, Platform platform, Object... params) {134 return map.get(key).get(platform.getPlatformName());135 }136 /**137 * @param platform {@link Platform}138 * @return a map of all UI locators specified for the given platform139 */140 public Map<String, Pair<String, String>> getLocatorsForPlatform(Platform platform) {141 Map<String, Pair<String, String>> result = new HashMap<>();142 for (Map.Entry<String, Map<String, Map<String, Object>>> entry : map.entrySet()) {143 Map<String, Object> tuple = entry.getValue().get(platform.getPlatformName());144 if (tuple != null) {145 result.put(146 entry.getKey(),147 Pair.of(148 tuple.get("type").toString(), replacePlaceholders(tuple.get("value").toString())));149 }150 }151 return result;152 }153 protected String formatValue(String rawValue, Object... params) {154 if (rawValue == null) {155 return null;156 }157 return String.format(replacePlaceholders(rawValue), params);158 }159 protected String replacePlaceholders(String rawValue) {160 if (rawValue == null) {161 return null;162 }163 Matcher matcher = PLACEHOLDER_PATTERN.matcher(rawValue);164 StringBuffer strBuffer = new StringBuffer();165 while (matcher.find()) {166 matcher.appendReplacement(strBuffer, staticPlaceholders.get(matcher.group(1)).toString());167 }168 matcher.appendTail(strBuffer);169 return strBuffer.toString();170 }171 private double getThreshold(Map<String, ?> platformKey) {172 try {173 return (double) platformKey.get("threshold");174 } catch (Exception e) {175 LOG.warn(176 "Invalid or no threshold value {}. Using default: {}",177 platformKey.get("threshold"),178 ByImage.DEFAULT_THRESHOLD);179 }180 return ByImage.DEFAULT_THRESHOLD;181 }182}...

Full Screen

Full Screen

AppiumBy.ByImage

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.AppiumDriver;2import io.appium.java_client.MobileElement;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.android.AndroidElement;5import io.appium.java_client.ios.IOSDriver;6import io.appium.java_client.ios.IOSElement;7import io.appium.ja

Full Screen

Full Screen

AppiumBy.ByImage

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.android.AndroidElement;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.AndroidBy;4public class AppiumByImageExample {5 public static void main(String[] args) {6 String imagePath = "C:\\Users\\user\\Desktop\\Appium\\AppiumByImage\\appium.png";7 AndroidDriver driver;8 DesiredCapabilities caps = new DesiredCapabilities();9 caps.setCapability("platformName", "Android");10 caps.setCapability("deviceName", "emulator-5554");11 caps.setCapability("app", "C:\\Users\\user\\Desktop\\Appium\\ApiDemos-debug.apk");12 caps.setCapability("appPackage", "io.appium.android.apis");13 caps.setCapability("appActivity", ".ApiDemos");14 try {

Full Screen

Full Screen

AppiumBy.ByImage

Using AI Code Generation

copy

Full Screen

1public static void main(String[] args) throws MalformedURLException, InterruptedException {2 AppiumDriver<MobileElement> driver;3 DesiredCapabilities capabilities = new DesiredCapabilities();4 capabilities.setCapability("deviceName", "Pixel 3 XL API 28");5 capabilities.setCapability("udid", "emulator-5554");6 capabilities.setCapability("platformName", "Android");7 capabilities.setCapability("platformVersion", "9.0");8 capabilities.setCapability("appPackage", "com.android.calculator2");9 capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");10 capabilities.setCapability("noReset", "true");

Full Screen

Full Screen

AppiumBy.ByImage

Using AI Code Generation

copy

Full Screen

1# from appium import AppiumBy2# driver = AppiumDriver()3# element = driver.find_element_by_image("path/to/image.png")4# from appium import AppiumBy5# driver = AppiumDriver()6# element = driver.find_element_by_image("path/to/image.png")

Full Screen

Full Screen

AppiumBy.ByImage

Using AI Code Generation

copy

Full Screen

1ByImage byImage = new ByImage(new File("path/to/image/file"));2WebElement element = driver.findElement(byImage);3by_image = Appium::ByImage.new('path/to/image/file')4element = driver.find_element(by_image)5from appium.webdriver.common.by_image import ByImage6by_image = ByImage('path/to/image/file')7element = driver.find_element(by_image)8by_image = ByImage("path/to/image/file")9element = driver.find_element(by_image)10byImage := appium.ByImage("path/to/image/file")11element := driver.FindElement(byImage)12using OpenQA.Selenium.Appium;13ByImage byImage = new ByImage("path/to/image/file");14IWebElement element = driver.FindElement(byImage);15import { ByImage } from 'appium';16const byImage = new ByImage('path/to/image/file');17const element = driver.findElement(byImage);18import io.appium.scala.ByImage19val byImage = new ByImage("path/to/image/file")20val element = driver.findElement(byImage)21import io.appium.kotlin.ByImage22val byImage = ByImage("path/to/image/file")23val element = driver.findElement(byImage)

Full Screen

Full Screen

AppiumBy.ByImage

Using AI Code Generation

copy

Full Screen

1WebElement imageElement = driver.findElementByImage("/Users/username/Downloads/image.jpg");2WebElement imageElement = driver.findElementByImage(new File("/Users/username/Downloads/image.jpg"));3List<WebElement> imageElements = driver.findElementsByImage("/Users/username/Downloads/image.jpg");4List<WebElement> imageElements = driver.findElementsByImage(new File("/Users/username/Downloads/image.jpg"));5image_element = driver.find_element :image, File.new("/Users/username/Downloads/image.jpg")6image_elements = driver.find_elements :image, File.new("/Users/username/Downloads/image.jpg")7image_element = driver.find_element_by_image("/Users/username/Downloads/image.jpg")8image_element = driver.find_element_by_image(File("/Users/username/Downloads/image.jpg"))9image_elements = driver.find_elements_by_image("/Users/username/Downloads/image.jpg")10image_elements = driver.find_elements_by_image(File("/Users/username/Downloads/image.jpg"))11imageElement = driver.findElementByImage("/Users/username/Downloads/image.jpg");12imageElement = driver.findElementByImage(new File("/Users/username/Downloads/image.jpg"));13imageElements = driver.findElementsByImage("/Users/username/Downloads/image.jpg");14imageElements = driver.findElementsByImage(new File("/Users/username

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful