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

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

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

SwagLabsLoginIos.java

Source:SwagLabsLoginIos.java Github

copy

Full Screen

1import io.appium.java_client.AppiumBy;2import io.appium.java_client.PerformsTouchActions;3import io.appium.java_client.TouchAction;4import io.appium.java_client.ios.IOSDriver;5import io.appium.java_client.touch.WaitOptions;6import io.appium.java_client.touch.offset.PointOption;7import org.openqa.selenium.By;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.remote.DesiredCapabilities;10import org.testng.annotations.Test;11import java.net.MalformedURLException;12import java.net.URL;13import java.time.Duration;14public class SwagLabsLoginIos {15 @Test16 public void login() throws MalformedURLException, InterruptedException {17 DesiredCapabilities capabilities=new DesiredCapabilities();18 capabilities.setCapability("platformName", "iOS");19 capabilities.setCapability("deviceName", "iPhone 13");20 capabilities.setCapability("automationName", "XCUITest");21 capabilities.setCapability("udid", "CB3931EC-0B2F-4763-AF77-723B5751DC2E");22 capabilities.setCapability("bundleId", "com.saucelabs.SwagLabsMobileApp");23 capabilities.setCapability("app", "/Users/gowthamipv/IdeaProjects/LoginPageios/src/test/resources/app/iOS.Simulator.SauceLabs.Mobile.Sample.app.2.7.1.app");24 IOSDriver driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);25 Thread.sleep(3000);26 driver.findElement(By.xpath("//XCUIElementTypeTextField[@name=\"test-Username\"]")).sendKeys("standard_user");27 Thread.sleep(3000);28 driver.findElement(By.xpath("//XCUIElementTypeSecureTextField[@name=\"test-Password\"]")).sendKeys("secret_sauce");29 Thread.sleep(3000);30 driver.findElement(By.xpath("//XCUIElementTypeOther[@name=\"test-LOGIN\"]")).click();31 Thread.sleep(3000);32 driver.findElement(By.xpath("(//XCUIElementTypeOther[@name=\"test-ADD TO CART\"])[2]")).click();33 Thread.sleep(3000);34 driver.findElement(By.xpath("(//XCUIElementTypeOther[@name=\"1\"])[4]")).click();35 Thread.sleep(3000);36 TouchAction t = new TouchAction(driver);37 t.tap(PointOption.point(186,657)).perform();38 Thread.sleep(3000);39 driver.findElement(By.xpath("//XCUIElementTypeTextField[@name=\"test-First Name\"]")).sendKeys("Gowthami");40 Thread.sleep(3000);41 driver.findElement(By.xpath("//XCUIElementTypeTextField[@name=\"test-Last Name\"]")).sendKeys("PV");42 Thread.sleep(3000);43 driver.findElement(By.xpath("//XCUIElementTypeTextField[@name=\"test-Zip/Postal Code\"]")).sendKeys("563122");44 Thread.sleep(3000);45 driver.findElement(By.xpath("//XCUIElementTypeOther[@name=\"test-CONTINUE\"]")).click();46 Thread.sleep(3000);47 t.press(PointOption.point(206,762)).waitAction(WaitOptions.waitOptions(Duration.ofMillis((3000)))).moveTo(PointOption.point(215,204)).release().perform();48 Thread.sleep(3000);49 driver.findElement(new AppiumBy.ByAccessibilityId("test-FINISH")).click();50 Thread.sleep(3000);51 driver.findElement(new AppiumBy.ByAccessibilityId("test-BACK HOME")).click();52 Thread.sleep(3000);53 driver.quit();54 }55}...

Full Screen

Full Screen

StepDefinitions.java

Source:StepDefinitions.java Github

copy

Full Screen

1package com.saucelabs.yy.cucumber.steps;2import com.saucelabs.yy.cucumber.tests.RunTest;3import io.appium.java_client.AppiumBy;4import io.appium.java_client.AppiumDriver;5import io.cucumber.java.After;6import io.cucumber.java.Scenario;7import io.cucumber.java.Status;8import io.cucumber.java.en.And;9import io.cucumber.java.en.Given;10import io.cucumber.java.en.Then;11import io.cucumber.java.en.When;12import org.openqa.selenium.By;13import org.openqa.selenium.JavascriptExecutor;14import org.openqa.selenium.OutputType;15import org.openqa.selenium.Platform;16import org.testng.Assert;17public class StepDefinitions extends RunTest {18 public ThreadLocal<AppiumDriver> driver = RunTest.driver;19 @Given("I open the iOS application")20 public void iOpenTheIOSApplication() {21 //do nothing22 }23 @Then("I should see Swag Labs login page")24 public void iShouldSeeSwagLabsLoginPage() {25 Assert.assertTrue(driver.get().findElement(By.id("test-LOGIN")).isDisplayed());26 }27 @When("I enter valid login credentials")28 public void iEnterValidLoginCredentials() {29 driver.get().findElement(By.id("test-Username")).sendKeys("standard_user");30 driver.get().findElement(By.id("test-Password")).sendKeys("secret_sauce");31 }32 @When("I enter invalid login credentials")33 public void iEnterInvalidLoginCredentials() {34 driver.get().findElement(By.id("test-Username")).sendKeys("bla");35 driver.get().findElement(By.id("test-Password")).sendKeys("bla");36 }37 @And("I click on login button")38 public void iClickOnLoginButton() {39 driver.get().findElement(By.id("test-LOGIN")).click();40 }41 @Then("take a screenshot")42 public void takeAScreenshot() {43 driver.get().getScreenshotAs(OutputType.FILE);44 }45 @Then("I am on the Inventory page")46 public void iAmOnTheInventoryPage() {47 Platform platform = driver.get().getCapabilities().getPlatformName();48 if (platform.is(Platform.ANDROID)) {49 Assert.assertTrue(driver.get().findElement(By.xpath("(//android.view.ViewGroup[@content-desc=\"test-ADD TO CART\"])[1]")).isDisplayed());50 } else if (platform.is(Platform.IOS)) {51 Assert.assertTrue(driver.get().findElement(By.xpath("(//XCUIElementTypeOther[@name=\"test-ADD TO CART\"])[1]")).isDisplayed());52 }53 }54 @Then("I have got an login error message")55 public void iHaveGotAnLoginErrorMessage() {56 Assert.assertTrue(driver.get().findElement(new AppiumBy.ByAccessibilityId("test-Error message")).isDisplayed());57 }58 @After59 public void teardown(Scenario scenario) {60 driver.get().executeScript("sauce:job-name=" + scenario.getName());61 ((JavascriptExecutor) driver.get()).executeScript("sauce:job-result=" + (scenario.getStatus().equals(Status.PASSED) ? "passed" : "failed"));62 driver.get().quit();63 }64}...

Full Screen

Full Screen

LoginTests.java

Source:LoginTests.java Github

copy

Full Screen

1package com.saucelabs.yy.Tests.Appium.SwagLabsApp.EmulatorSimulator;2import io.appium.java_client.AppiumBy;3import org.openqa.selenium.By;4import org.testng.Assert;5import org.testng.annotations.Test;6import java.lang.reflect.Method;7import java.net.MalformedURLException;8public class LoginTests extends TestBase {9 @Test(dataProvider = "EmulatorSimulatorDataProvider")10 public void invalidCredentials(String platform, String deviceName, String platformVersion, Method methodName) throws MalformedURLException {11 createDriver(platform, deviceName, platformVersion, methodName.getName());12 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Username")).sendKeys("bad");13 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Password")).sendKeys("bad");14 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-LOGIN")).click();15 Assert.assertTrue(getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Error message")).isDisplayed());16 }17 @Test(dataProvider = "EmulatorSimulatorDataProvider")18 public void blankCredentials(String platform, String deviceName, String platformVersion, Method methodName) throws MalformedURLException {19 createDriver(platform, deviceName, platformVersion, methodName.getName());20 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Username")).sendKeys("");21 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Password")).sendKeys("");22 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-LOGIN")).click();23 Assert.assertTrue(getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Error message")).isDisplayed());24 }25 @Test(dataProvider = "EmulatorSimulatorDataProvider")26 public void validCredentials(String platform, String deviceName, String platformVersion, Method methodName) throws MalformedURLException {27 createDriver(platform, deviceName, platformVersion, methodName.getName());28 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Username")).sendKeys("standard_user");29 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Password")).sendKeys("secret_sauce");30 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-LOGIN")).click();31 if (platform.equalsIgnoreCase("Android")) {32 Assert.assertTrue(getDriver().findElement(By.xpath("(//android.view.ViewGroup[@content-desc=\"test-ADD TO CART\"])[1]")).isDisplayed());33 } else {34 Assert.assertTrue(getDriver().findElement(By.xpath("(//XCUIElementTypeOther[@name=\"test-ADD TO CART\"])[1]")).isDisplayed());35 }36 }37}...

Full Screen

Full Screen

AddItemsTests.java

Source:AddItemsTests.java Github

copy

Full Screen

1package com.saucelabs.yy.Tests.Appium.SwagLabsApp.EmulatorSimulator;2import io.appium.java_client.AppiumBy;3import org.openqa.selenium.By;4import org.testng.Assert;5import org.testng.annotations.Test;6import java.lang.reflect.Method;7import java.net.MalformedURLException;8public class AddItemsTests extends TestBase {9 @Test(dataProvider = "EmulatorSimulatorDataProvider")10 public void addOneItemtoCart(String platform, String deviceName, String platformVersion, Method methodName) throws MalformedURLException {11 createDriver(platform, deviceName, platformVersion, methodName.getName());12 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Username")).sendKeys("standard_user");13 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-Password")).sendKeys("secret_sauce");14 getDriver().findElement(new AppiumBy.ByAccessibilityId("test-LOGIN")).click();15 if (platform.equalsIgnoreCase("Android")) {16 getDriver().findElement(By.xpath("(//android.view.ViewGroup[@content-desc=\"test-ADD TO CART\"])[1]")).click();17 getDriver().findElement(By.xpath("//android.view.ViewGroup[@content-desc=\"test-Cart\"]/android.view.ViewGroup/android.widget.TextView")).click();18 Assert.assertEquals(getDriver().findElement(By.xpath("(//android.view.ViewGroup[@content-desc=\"test-Description\"])[1]/android.widget.TextView[1]")).getText(), "Sauce Labs Backpack");19 } else {20 getDriver().findElement(By.xpath("(//XCUIElementTypeOther[@name=\"test-ADD TO CART\"])[1]")).click();21 getDriver().findElement(By.xpath("(//XCUIElementTypeOther[@name=\"1\"])[4]")).click();22 Assert.assertTrue(getDriver().findElement(By.xpath("(//XCUIElementTypeOther[@name=\"1\"])[4]")).isDisplayed());23 }24 }25}...

Full Screen

Full Screen

AppiumBy.ByAccessibilityId

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.remote.MobileCapabilityType;5import org.openqa.selenium.By;6import org.openqa.selenium.remote.DesiredCapabilities;7import java.net.URL;8public class AppiumByByAccessibilityId {9 public static void main(String[] args) throws Exception {10 DesiredCapabilities capabilities = new DesiredCapabilities();11 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");12 capabilities.setCapability("platformName", "Android");13 capabilities.setCapability("platformVersion", "7.1.1");14 capabilities.setCapability("appPackage", "com.android.calculator2");15 capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen

AppiumBy.ByAccessibilityId

Using AI Code Generation

copy

Full Screen

1package appium.java;2import org.openqa.selenium.By;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.support.ui.ExpectedConditions;5import org.openqa.selenium.support.ui.WebDriverWait;6import org.testng.annotations.Test;7import io.appium.java_client.AppiumDriver;8import io.appium.java_client.MobileElement;9import io.appium.java_client.android.AndroidDriver;10import io.appium.java_client.android.AndroidElement;11import io.appium.java_client.remote.MobileCapabilityType;12import java.net.MalformedURLException;13import java.net.URL;14import java.util.concurrent.TimeUnit;15import org.openqa.selenium.remote.DesiredCapabilities;16public class AppiumByAccessibilityId {17 public static AppiumDriver<MobileElement> driver;18 public static void main(String[] args) throws MalformedURLException {19 DesiredCapabilities cap = new DesiredCapabilities();20 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");21 cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");22 cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10");23 cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");24 cap.setCapability("appPackage", "com.android.calculator2");25 cap.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen

AppiumBy.ByAccessibilityId

Using AI Code Generation

copy

Full Screen

1By accessibilityId = AppiumBy.ByAccessibilityId("AccessibilityId");2By iosNsPredicate = AppiumBy.ByIosNsPredicate("iOS predicate string");3By iosUIAutomation = AppiumBy.ByIosUIAutomation("iOS UIAutomation");4By iosClassChain = AppiumBy.ByIosClassChain("iOS class chain");5By androidUIAutomator = AppiumBy.ByAndroidUIAutomator("Android UIAutomator");6By androidViewTag = AppiumBy.ByAndroidViewTag("Android ViewTag");7By androidDataMatcher = AppiumBy.ByAndroidDataMatcher("Android Data Matcher");8By androidViewMatcher = AppiumBy.ByAndroidViewMatcher("Android View Matcher");9By windowsAutomation = AppiumBy.ByWindowsAutomation("Windows Automation");

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