Best io.appium code snippet using io.appium.java_client.remote.IOSMobileCapabilityType
Hooks.java
Source:Hooks.java
...4import io.appium.java_client.android.AndroidElement;5import io.appium.java_client.ios.IOSDriver;6import io.appium.java_client.ios.IOSElement;7import io.appium.java_client.remote.AndroidMobileCapabilityType;8import io.appium.java_client.remote.IOSMobileCapabilityType;9import io.appium.java_client.remote.MobileCapabilityType;10import io.appium.java_client.service.local.AppiumDriverLocalService;11import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException;12import io.appium.java_client.service.local.AppiumServiceBuilder;13import org.openqa.selenium.Platform;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.testng.annotations.*;16import java.io.File;17import java.net.URL;18public class Hooks {19 static URL url;20 private PropertyReader pathReader = new PropertyReader();21 @BeforeSuite22 public void startServer () {23 AppiumDriverLocalService service;24 String appiumPath = pathReader.readProperty("APPIUM_PATH");25 AppiumServiceBuilder appiumServiceBuilder = new AppiumServiceBuilder()26 .withAppiumJS(new File(appiumPath))27 .withIPAddress("127.0.0.1")28 .usingAnyFreePort();29 service = appiumServiceBuilder.build();30 ServiceManager.setService(service);31 ServiceManager.getService().start();32 if (service == null || !service.isRunning()) {33 throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!");34 }35 url = service.getUrl();36 System.out.println("Server started Successfully on " + service.getUrl());37 }38 @AfterSuite39 public void stopServer () {40 if (ServiceManager.getService() != null) {41 ServiceManager.getService().stop();42 }43 }44 @Parameters({"platform", "platformVersion", "deviceName", "port", "udid"})45 @BeforeClass(alwaysRun = true)46 public void launchDriver ( String platform, String platformVersion, String deviceName, String port, String udid ) {47 if (platform.toLowerCase().equals("android")) {48 LocalDriverManager.setWebDriver(getAndroidDriver(platformVersion, deviceName, port, udid));49 DeviceHelper.setDeviceName(deviceName);50 } else {51 LocalDriverManager.setWebDriver(getIOSDriver(platformVersion, deviceName, port, udid));52 DeviceHelper.setDeviceName(deviceName);53 }54 }55 @AfterClass(alwaysRun = true)56 public void disposeDriver () {57 if (LocalDriverManager.getDriver() != null) {58 LocalDriverManager.getDriver().quit();59 }60 }61 private AppiumDriver getIOSDriver ( String platformVersion, String deviceName, String wdaLocalPort, String udid ) {62 if (url != null) {63 File appDir = new File("src/test/resources/");64 File app = new File(appDir, "*.ipa");65 DesiredCapabilities capabilities = new DesiredCapabilities();66 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);67 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, Platform.IOS);68 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);69 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);70 capabilities.setCapability(MobileCapabilityType.APP, app);71 capabilities.setCapability(MobileCapabilityType.ORIENTATION, "PORTRAIT");72 capabilities.setCapability(MobileCapabilityType.NO_RESET, false);73 capabilities.setCapability(IOSMobileCapabilityType.PREVENT_WDAATTACHMENTS, false);74 capabilities.setCapability(IOSMobileCapabilityType.WDA_CONNECTION_TIMEOUT, 80000);75 capabilities.setCapability(IOSMobileCapabilityType.WDA_LAUNCH_TIMEOUT, 80000);76 capabilities.setCapability(IOSMobileCapabilityType.SHOULD_USE_SINGLETON_TESTMANAGER, false);77 capabilities.setCapability(IOSMobileCapabilityType.SIMPLE_ISVISIBLE_CHECK, true);78 capabilities.setCapability(IOSMobileCapabilityType.MAX_TYPING_FREQUENCY, 10);79 capabilities.setCapability("wdaLocalPort", Integer.valueOf(wdaLocalPort));80 capabilities.setCapability("clearSystemFiles", true);81 capabilities.setCapability("udid", udid);82 return new IOSDriver<IOSElement>(url, capabilities);83 } else {84 System.out.println("You have to launch appium server before launching driver");85 return null;86 }87 }88 private AppiumDriver getAndroidDriver ( String platformVersion, String deviceName, String portNumber, String udid ) {89 if (url != null) {90 File appDir = new File("src/test/resources/");91 File app = new File(appDir, "*.apk");92 DesiredCapabilities capabilities = new DesiredCapabilities();...
IOSInitDriver.java
Source:IOSInitDriver.java
...3import io.appium.java_client.MobileElement;4import io.appium.java_client.ios.IOSDriver;5import io.appium.java_client.remote.AndroidMobileCapabilityType;6import io.appium.java_client.remote.AutomationName;7import io.appium.java_client.remote.IOSMobileCapabilityType;8import io.appium.java_client.remote.MobileCapabilityType;9import org.openqa.selenium.remote.DesiredCapabilities;10import java.net.URL;11public class IOSInitDriver {12 /**13 * æä¾å
Œ
±åæ°caps对象14 * @param udid15 * @return16 */17 public static DesiredCapabilities getCommonCaps(String udid) {18 DesiredCapabilities caps = new DesiredCapabilities();// è¦ä¼ éç»æå¡ç«¯çåæ°å¯¹è±¡19 caps.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 8 Plus");// deviceNameçå¼å¨å®åä¸é便åé½å¯ä»¥æå20 caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "ios");// è¦æµè¯ç±»å21 caps.setCapability(AndroidMobileCapabilityType.NO_SIGN, true);// æ¯å¦ä¸éç¾åapp22 caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 600);// 表示æå¡ç«¯sessionè¶
æ¶æ¶é´ï¼é»è®¤æ¯60ç§23 //caps.setCapability(MobileCapabilityType.UDID, udid);// 表示è¦è¿æ¥çåªä¸å°è®¾å¤24 caps.setCapability(MobileCapabilityType.NO_RESET, true);25 caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);26 return caps;27 }28 /**29 * é对æªå®è£
çåºç¨è¿è¡driveråå§åæä½30 * @param udid31 * @param appPath32 * @return33 * @throws Exception34 */35 public static AppiumDriver<MobileElement> initDriverWithNotInstaller(String udid, String appPath)36 throws Exception {37 DesiredCapabilities caps = getCommonCaps(udid);// è¦ä¼ éç»æå¡ç«¯çåæ°å¯¹è±¡38 caps.setCapability(MobileCapabilityType.APP,appPath);39 AppiumDriver<MobileElement> driver = new IOSDriver<>(new URL("http://192.168.0.102:4490/wd/hub"), caps);40 return driver;41 }42 public static AppiumDriver<MobileElement> initDriverWithNotInstallerHunHe(String udid, String appPath)43 throws Exception {44 DesiredCapabilities caps = getCommonCaps(udid);// è¦ä¼ éç»æå¡ç«¯çåæ°å¯¹è±¡45 caps.setCapability(MobileCapabilityType.APP,appPath);46 caps.setCapability(IOSMobileCapabilityType.USE_NEW_WDA, true);47 AppiumDriver<MobileElement> driver = new IOSDriver<>(new URL("http://192.168.0.102:4490/wd/hub"), caps);48 return driver;49 }50 public static AppiumDriver<MobileElement> initZhenJiDriverWithNotInstaller(String udid, String appPath)51 throws Exception {52 DesiredCapabilities caps = getCommonCaps(udid);// è¦ä¼ éç»æå¡ç«¯çåæ°å¯¹è±¡53 caps.setCapability(MobileCapabilityType.APP,appPath);54 caps.setCapability(MobileCapabilityType.UDID, udid);55 caps.setCapability(IOSMobileCapabilityType.USE_NEW_WDA, true);56 AppiumDriver<MobileElement> driver = new IOSDriver<>(new URL("http://192.168.0.102:4490/wd/hub"), caps);57 return driver;58 }59 public static AppiumDriver<MobileElement> initZhenJiDriverWithInstaller(String udid, String bundleid)60 throws Exception {61 DesiredCapabilities caps = getCommonCaps(udid);// è¦ä¼ éç»æå¡ç«¯çåæ°å¯¹è±¡62 caps.setCapability(MobileCapabilityType.UDID, udid);63 caps.setCapability(IOSMobileCapabilityType.USE_NEW_WDA, true);64 caps.setCapability(IOSMobileCapabilityType.BUNDLE_ID, bundleid);65 AppiumDriver<MobileElement> driver = new IOSDriver<>(new URL("http://192.168.0.102:4490/wd/hub"), caps);66 return driver;67 }68 public static AppiumDriver<MobileElement> initZhenJiDriverWithH5(String udid)69 throws Exception {70 DesiredCapabilities caps = getCommonCaps(udid);// è¦ä¼ éç»æå¡ç«¯çåæ°å¯¹è±¡71 caps.setCapability(MobileCapabilityType.UDID, udid);72 caps.setCapability(IOSMobileCapabilityType.USE_NEW_WDA, true);73 caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");74 caps.setCapability(IOSMobileCapabilityType.START_IWDP, true);75 AppiumDriver<MobileElement> driver = new IOSDriver<>(new URL("http://192.168.0.102:4490/wd/hub"), caps);76 return driver;77 }78 public static AppiumDriver<MobileElement> initZhenJiDriverWithHunHe(String udid,String bundleid)79 throws Exception {80 DesiredCapabilities caps = getCommonCaps(udid);// è¦ä¼ éç»æå¡ç«¯çåæ°å¯¹è±¡81 caps.setCapability(MobileCapabilityType.UDID, udid);82 caps.setCapability(IOSMobileCapabilityType.USE_NEW_WDA, true);83 caps.setCapability(IOSMobileCapabilityType.BUNDLE_ID, bundleid);84 caps.setCapability(IOSMobileCapabilityType.START_IWDP, true);85 AppiumDriver<MobileElement> driver = new IOSDriver<>(new URL("http://192.168.0.102:4490/wd/hub"), caps);86 return driver;87 }88}...
IOSDriverManager.java
Source:IOSDriverManager.java
1package driver;2import io.appium.java_client.ios.IOSDriver;3import io.appium.java_client.remote.AutomationName;4import io.appium.java_client.remote.IOSMobileCapabilityType;5import io.appium.java_client.remote.MobileCapabilityType;6import io.appium.java_client.service.local.AppiumServiceBuilder;7import io.appium.java_client.service.local.flags.AndroidServerFlag;8import io.appium.java_client.service.local.flags.GeneralServerFlag;9import io.appium.java_client.service.local.flags.IOSServerFlag;10import org.openqa.selenium.remote.DesiredCapabilities;11import util.NodeConfig;12import java.io.File;13import java.net.URL;14import java.util.concurrent.TimeUnit;15public class IOSDriverManager extends DriverManager{16 NodeConfig nodeConfig = new NodeConfig("iPad_Air2");17 /**18 * Start Appium Service19 */20 @Override21 protected void startService() {22 DesiredCapabilities cap = new DesiredCapabilities();23 cap.setCapability(MobileCapabilityType.UDID,nodeConfig.getCapability("UDID"));24 AppiumServiceBuilder builder = new AppiumServiceBuilder()25 .withArgument(GeneralServerFlag.LOG_LEVEL,"error")26 .withLogFile(new File(nodeConfig.getCapability("TEMPDIRECTORY")+ "/appiumLog.txt"))27 .withArgument(IOSServerFlag.WEBKIT_DEBUG_PROXY_PORT,nodeConfig.getCapability("WEBKIT_DEBUG_PROXY_PORT"))28 .withArgument(AndroidServerFlag.BOOTSTRAP_PORT_NUMBER,nodeConfig.getCapability("BOOTSTRAP_PORT_NUMBER"))29 .withIPAddress("0.0.0.0")30 .withArgument(GeneralServerFlag.TEMP_DIRECTORY,nodeConfig.getCapability("TEMPDIRECTORY") +31 nodeConfig.getCapability("WEBDRIVER_PORT"))32 .withArgument(GeneralServerFlag.SESSION_OVERRIDE)33 .usingPort(Integer.parseInt(nodeConfig.getCapability("WEBDRIVER_PORT")))34 .withArgument(GeneralServerFlag.CONFIGURATION_FILE,nodeConfig.getCapability("CONFIGURATIONFILE"))35 .withCapabilities(cap);36 service = builder.build();37 service.start();38 }39 /**40 * Stop Appium Service41 */42 @Override43 protected void stopService() {44 service.stop();45 if(service.isRunning()){46 service.stop();47 }48 }49 /**50 * Create IOS Driver51 */52 @Override53 protected void createDriver() {54 capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION,nodeConfig.getCapability("PLATFORM_VERSION"));55 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, nodeConfig.getCapability("DEVICE_NAME"));56 capabilities.setCapability(MobileCapabilityType.UDID,nodeConfig.getCapability("UDID"));57 capabilities.setCapability(MobileCapabilityType.NO_RESET, true);58 capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,nodeConfig.getCapability("PLATFORM_NAME"));59 capabilities.setCapability(MobileCapabilityType.APP, "put your app path");60 capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT,50000000);61 capabilities.setCapability("newCommandTimeout",60*15);62 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);63 capabilities.setCapability(IOSMobileCapabilityType.SHOW_IOS_LOG,false);64 capabilities.setCapability("realDeviceLogger","/usr/local/lib/node_modules/deviceconsole/deviceconsole");65 capabilities.setCapability("showXcodeLog",false);66 capabilities.setCapability(MobileCapabilityType.TAKES_SCREENSHOT,"true");67 capabilities.setCapability("autoGrantPermissions",true);68 capabilities.setCapability("autoAcceptAlerts",true);69 capabilities.setCapability("autoDismissAlerts",true);70 capabilities.setCapability("nativeWebTap",true);71 capabilities.setCapability(IOSMobileCapabilityType.WDA_LOCAL_PORT,nodeConfig.getCapability("WEBDRIVER_AGENT_PORT"));72 capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID,"your app bundle id");73 try {74 this.driver = new IOSDriver(new URL(nodeConfig.getCapability("PORT")),capabilities);75 } catch (Exception e) {76 try {77 throw new Exception("IOS Driver Initialization Error", e);78 } catch (Exception exception) {79 exception.printStackTrace();80 }81 }82 this.driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);83 }84}...
BaseTest.java
Source:BaseTest.java
...5import io.appium.java_client.MobileElement;6import io.appium.java_client.android.AndroidDriver;7import io.appium.java_client.ios.IOSDriver;8import io.appium.java_client.remote.AndroidMobileCapabilityType;9import io.appium.java_client.remote.IOSMobileCapabilityType;10import io.appium.java_client.remote.MobileCapabilityType;11import io.appium.java_client.remote.MobilePlatform;12import org.openqa.selenium.NoSuchElementException;13import org.openqa.selenium.remote.DesiredCapabilities;14import org.openqa.selenium.support.ui.FluentWait;15import java.io.IOException;16import java.net.URL;17import java.time.Duration;18public class BaseTest {19 protected static AppiumDriver<MobileElement> appiumDriver;20 protected static FluentWait<AppiumDriver<MobileElement>> appiumFluentWait;21 protected boolean localAndroid = true;22 @BeforeScenario23 public void beforeScenario() throws IOException {24 //System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!Test baslıyor!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");25 //System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");26 if (localAndroid) {27 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();28 desiredCapabilities29 .setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);30 desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");31 desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");32 desiredCapabilities33 .setCapability(AndroidMobileCapabilityType.APP_PACKAGE,34 "com.ozdilek.ozdilekteyim");35 desiredCapabilities36 .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,37 "com.ozdilek.ozdilekteyim.MainActivity");38 desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");39 desiredCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 3000);40 URL url = new URL("http://127.0.0.1:4723/wd/hub");41 appiumDriver = new AndroidDriver(url, desiredCapabilities);42 } else {43 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();44 desiredCapabilities45 .setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);46 desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");47 desiredCapabilities48 .setCapability(MobileCapabilityType.UDID, "00008030-00157936018B802E");49 desiredCapabilities50 .setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.monitise.mea.CCI.TNEXT");51 desiredCapabilities52 .setCapability(MobileCapabilityType.DEVICE_NAME, "iPhonebatu");53 desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "14.0.1");54 desiredCapabilities.setCapability("connectHardwareKeyboard", false);55 desiredCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 300);56 URL url = new URL("http://127.0.0.1:4723/wd/hub");57 appiumDriver = new IOSDriver(url, desiredCapabilities);58 }59 //appiumDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);60 appiumFluentWait = new FluentWait<AppiumDriver<MobileElement>>(appiumDriver);61 appiumFluentWait.withTimeout(Duration.ofSeconds(30))62 .pollingEvery(Duration.ofMillis(450))63 .ignoring(NoSuchElementException.class);64 }...
Ersal.java
Source:Ersal.java
1package iphone;2import io.appium.java_client.ios.IOSDriver;3import io.appium.java_client.ios.IOSElement;4import io.appium.java_client.remote.AutomationName;5import io.appium.java_client.remote.IOSMobileCapabilityType;6import io.appium.java_client.remote.MobileCapabilityType;7import io.appium.java_client.service.local.AppiumDriverLocalService;8import io.appium.java_client.service.local.AppiumServiceBuilder;9import org.apache.tools.ant.taskdefs.WaitFor;10import org.openqa.selenium.By;11import org.openqa.selenium.remote.DesiredCapabilities;12import org.openqa.selenium.support.ui.ExpectedConditions;13import org.openqa.selenium.support.ui.WebDriverWait;14import org.testng.annotations.*;15import java.io.File;16import java.io.IOException;17/**18 * Created by GaneshRam J on 01/08/17.19 */20public class Ersal {21 public static AppiumDriverLocalService service;22 public static IOSDriver<IOSElement> driver;23 @BeforeSuite24 public void beforeClass() throws Exception, IOException {25//local path of node folder26 String Appium_Node_Path = "/usr/local/bin/node";27//local path of main.js28 // String Appium_JS_Path = "/Applications/Appium 3.app/Contents/Resources/app/node_modules/appium/build/lib/main.js";29 String Appium_JS_Path = "/Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js";30 service = AppiumDriverLocalService31 .buildService(new AppiumServiceBuilder()32 // .withIPAddress("127.0.0.1")33 // .usingPort(4723)34 .usingAnyFreePort()35 .usingDriverExecutable(new File(Appium_Node_Path))36 .withAppiumJS(new File (Appium_JS_Path))37 );38 service.start();39 service.isRunning();40// if (service == null || service.isRunning()) {41// throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!");42// }43 File appDir = new File("src/test/resources/file/iphone");44 File app = new File(appDir, "Ersal.zip");45 DesiredCapabilities capabilities = new DesiredCapabilities();46 // capabilities.setCapability("--session-override", true);47 capabilities.setCapability(MobileCapabilityType.NO_RESET,true);48 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);49 capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 6");50 capabilities.setCapability(IOSMobileCapabilityType.PLATFORM, "iOS");51 capabilities.setCapability(IOSMobileCapabilityType.VERSION, "10.3");52 capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "us.fetchr.ersal.CustomerApp-Alpha");53 capabilities.setCapability(IOSMobileCapabilityType.APP_NAME, "Ersal");54 capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, WaitFor.Unit.HOUR);55 capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());56 driver = new IOSDriver(service.getUrl(), capabilities);57 }58 @AfterSuite59 public void afterClass() {60 if (driver != null) {61 driver.quit();62 }63 if (service != null) {64 service.stop();65 }66 }67 @Test68 public void login(){...
BaseClass.java
Source:BaseClass.java
...3import io.appium.java_client.MobileElement;4import io.appium.java_client.android.AndroidDriver;5import io.appium.java_client.ios.IOSDriver;6import io.appium.java_client.remote.AndroidMobileCapabilityType;7import io.appium.java_client.remote.IOSMobileCapabilityType;8import io.appium.java_client.remote.MobileCapabilityType;9import io.appium.java_client.remote.MobilePlatform;10import org.openqa.selenium.remote.DesiredCapabilities;11import org.testng.annotations.AfterTest;12import org.testng.annotations.BeforeTest;13import java.net.MalformedURLException;14import java.net.URL;15public class BaseClass {16 AppiumDriver<MobileElement> appiumDriver;17 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();18 Boolean localAndroid = false;19 @BeforeTest20 public void setup() throws InterruptedException, MalformedURLException {21 if (localAndroid) {22 desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);23 desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator");24 desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "12.0");25 desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.getir.dev");26 desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.getir.core.feature.splash.SplashActivity");27 appiumDriver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);28 Thread.sleep(2000);29 } else {30 desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);31 desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 13");32 desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "15.0");33 desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");34 desiredCapabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.getir.ios.dev.v2");35 desiredCapabilities.setCapability(IOSMobileCapabilityType.PROCESS_ARGUMENTS, "{\n" +36 " \"args\": [\n" +37 " \"getir-is-running-ui-tests\",\n" +38 " \"-AppleLanguages\",\n" +39 " \"(tr)\",\n" +40 " \"-AppleLocale\",\n" +41 " \"tr_TR\"\n" +42 " ]\n" +43 " }".toString());44 appiumDriver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);45 Thread.sleep(2000);46 }47 }48 @AfterTest49 public void tearDown(){...
SetupCustomerCapabilitiesIOS.java
Source:SetupCustomerCapabilitiesIOS.java
...3import io.appium.java_client.android.AndroidElement;4import io.appium.java_client.ios.IOSDriver;5import io.appium.java_client.ios.IOSElement;6import io.appium.java_client.remote.AutomationName;7import io.appium.java_client.remote.IOSMobileCapabilityType;8import io.appium.java_client.remote.MobileCapabilityType;9import org.openqa.selenium.remote.DesiredCapabilities;10import java.net.MalformedURLException;11import java.net.URL;12import java.util.concurrent.TimeUnit;13public class SetupCustomerCapabilitiesIOS14{15 public static IOSDriver<IOSElement> driver;16 public IOSDriver<IOSElement> setup(String deviceName, String udid, String platformName, String platformVersion) throws MalformedURLException {17 DesiredCapabilities cap = new DesiredCapabilities();18 cap.setCapability(MobileCapabilityType.DEVICE_NAME,deviceName);19 cap.setCapability("udid",udid);20 cap.setCapability(MobileCapabilityType.PLATFORM_NAME,platformName);21 cap.setCapability(MobileCapabilityType.PLATFORM_VERSION,platformVersion);22 cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);23 cap.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000);24 cap.setCapability(IOSMobileCapabilityType.COMMAND_TIMEOUTS, "12000");25 //IOSMobileCapabilityType.BUNDLE_ID26 // IOSMobileCapabilityType.U27 cap.setCapability(MobileCapabilityType.APP,"/Users/abvn237/Desktop/CustomerBankingAppProject/" +28 "IOSProject/CustomerBankingApp2/CustomerBankingApp2.app");29 //cap.setCapability("appPackage",appPackage);30 //cap.setCapability("appActivity",appActivity);31 IOSDriver driver = new IOSDriver<IOSElement>(new URL("http://localhost:4723/wd/hub"),cap);32 driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);33 driver.findElementByAccessibilityId("Alert Views").click();34 driver.findElementByXPath("XCUIElementTypeStaticText[@name='Text Entry']").click();35 driver.findElementByXPath("//XCUIElementTypeCell").sendKeys("Hello");36 driver.findElementByAccessibilityId("OK").click();37 driver.findElementByAccessibilityId("Confirm / Cancel").click();38 System.out.println(driver.findElementByXPath("//*[contains[@name,'message']]").getText());39 driver.findElementByAccessibilityId("Confirm").click();40 return driver;...
IOSDemoTest.java
Source:IOSDemoTest.java
...6import org.testng.annotations.Parameters;7import org.testng.annotations.Test;8import io.appium.java_client.ios.IOSDriver;9import io.appium.java_client.ios.IOSElement;10import io.appium.java_client.remote.IOSMobileCapabilityType;11import io.appium.java_client.remote.MobileCapabilityType;12public class IOSDemoTest extends BaseTest {13 protected IOSDriver<IOSElement> driver = null;14 @BeforeMethod15 @Parameters("deviceQuery")16 public void setUp(@Optional("@os='ios'") String deviceQuery) throws Exception {17 init(deviceQuery);18 // Init application / device capabilities19 //dc.setCapability(MobileCapabilityType.APP, "cloud:com.experitest.ExperiBank");20 //dc.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.experitest.ExperiBank");21 dc.setCapability("testName", "IOSDemoTest");22 driver = new IOSDriver<>(new URL(getProperty("url",cloudProperties) + "/wd/hub"), dc);23 }24 @Test25 public void test() {26 // Enter the test code27 }28 @AfterMethod29 public void tearDown() {30 driver.quit();31 }32}...
IOSMobileCapabilityType
Using AI Code Generation
1DesiredCapabilities capabilities = new DesiredCapabilities();2capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.example.apple-samplecode.UICatalog");3capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");4capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");5capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.3");6capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);7capabilities.setCapability(MobileCapabilityType.APP, "/path/to/UICatalog.app");8capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60);
IOSMobileCapabilityType
Using AI Code Generation
1DesiredCapabilities capabilities = new DesiredCapabilities();2capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilecal");3capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 5000);4capabilities.setCapability(IOSMobileCapabilityType.WAIT_FOR_APP_SCRIPT, "$.delay(1000); $.acceptAlert();");5capabilities.setCapability(IOSMobileCapabilityType.AUTO_ACCEPT_ALERTS, true);6capabilities.setCapability(IOSMobileCapabilityType.AUTO_DISMISS_ALERTS, true);7capabilities.setCapability(IOSMobileCapabilityType.SAFARI_ALLOW_POPUPS, true);8capabilities.setCapability(IOSMobileCapabilityType.SAFARI_OPEN_LINKS_IN_BACKGROUND, true);9capabilities.setCapability(IOSMobileCapabilityType.SAFARI_IGNORE_FRAUD_WARNINGS, true);10capabilities.setCapability(IOSMobileCapabilityType.SAFARI_POPUP_BLOCKING, true);11capabilities.setCapability(IOSMobileCapabilityType.SAFARI_USE_UIWEBVIEW, true);12capabilities.setCapability(IOSMobileCapabilityType.SEND_KEY_STRATEGY, "grouped");13capabilities.setCapability(IOSMobileCapabilityType.LOCATION_SERVICES_ENABLED, true);14capabilities.setCapability(IOSMobileCapabilityType.LOCATION_SERVICES_AUTHORIZED, true);15capabilities.setCapability(IOSMobileCapabilityType.SUPPORTS_ALERTS, true);16capabilities.setCapability(IOSMobileCapabilityType.SUPPORTS_JAVASCRIPT_ALERTS, true);17capabilities.setCapability(IOSMobileCapabilityType.SUPPORTS_JAVASCRIPT_DIALOGS, true);18capabilities.setCapability(IOSMobileCapabilityType.SUPPORTS_LOCATION_CONTEXT, true);19capabilities.setCapability(IOSMobileCapabilityType.SUPPORTS_NETWORK_CONNECTION, true);20capabilities.setCapability(IOSMobileCapabilityType.SUPPORTS_REMOTE_BROWSER, true);21capabilities.setCapability(IOSMobileCapabilityType.SUPPORTS_WEB_STORAGE, true);22capabilities.setCapability(IOSMobileCapabilityType.TAKES_SCREENSHOT, true);23capabilities.setCapability(IOSMobileCapabilityType.WEB_INSPECTOR_DEBUGGING_ENABLED, true);24capabilities.setCapability(IOSMobileCapabilityType.WEB_INSPECTOR_DEBUGGING_PORT, 27753);25DesiredCapabilities capabilities = new DesiredCapabilities();26capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilecal");27capabilities.setCapability(IOSMobileCapability
IOSMobileCapabilityType
Using AI Code Generation
1DesiredCapabilities capabilities = new DesiredCapabilities();2capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.calculator");3capabilities.setCapability(IOSMobileCapabilityType.PLATFORM_NAME, "iOS");4capabilities.setCapability(IOSMobileCapabilityType.PLATFORM_VERSION, "11.4");5capabilities.setCapability(IOSMobileCapabilityType.DEVICE_NAME, "iPhone 8");6capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");7capabilities.setCapability(MobileCapabilityType.NO_RESET, true);8capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 120);9capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());10capabilities.setCapability(IOSMobileCapabilityType.XCODE_ORG_ID, "your organization id");11capabilities.setCapability(IOSMobileCapabilityType.XCODE_SIGNING_ID, "iPhone Developer");12capabilities.setCapability(IOSMobileCapabilityType.USE_NEW_WDA, true);13capabilities.setCapability(IOSMobileCapabilityType.WDA_LOCAL_PORT, 8100);14capabilities.setCapability(MobileCapabilityType.UDID, "your device id");15capabilities.setCapability(MobileCapabilityType.FULL_RESET, false);16capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 120000);17capabilities.setCapability(IOSMobileCapabilityType.USE_PREBUILT_WDA, true);18capabilities.setCapability(IOSMobileCapabilityType.WDA_LAUNCH_TIMEOUT, 120000);19capabilities.setCapability(IOSMobileCapabilityType.WDA_STARTUP_RETRY_INTERVAL, 120000);20capabilities.setCapability(IOSMobileCapabilityType.WDA_CONNECTION_TIMEOUT, 120000);21capabilities.setCapability(IOSMobileCapabilityType.WDA_EVENTLOOP_IDLE_DELAY, 120000);22capabilities.setCapability(IOSMobileCapabilityType.WDA_LOCAL_PORT, 8100);23capabilities.setCapability(IOSMobileCapabilityType.WDA_LAUNCH_APP, true);24capabilities.setCapability(IOSMobileCapabilityType.WDA_LOG_LEVEL, "debug");25capabilities.setCapability(IOSMobileCapabilityType.WDA_LOG_FILE, "path to the WDA log file");26capabilities.setCapability(IOSMobileCapabilityType.WDA_LAUNCH_TIMEOUT, 120000);27capabilities.setCapability(IOSMobileCapabilityType.WDA_STARTUP_RETRY_INTERVAL, 120000);28capabilities.setCapability(IOSMobileCapabilityType.WDA_CONNECTION_TIMEOUT, 120000);29capabilities.setCapability(IOSMobileCapabilityType.WDA_EVENTLOOP_IDLE_DELAY, 120000);30capabilities.setCapability(IOSMobileCapabilityType.WDA_LOCAL_PORT, 810
IOSMobileCapabilityType
Using AI Code Generation
1DesiredCapabilities capabilities = new DesiredCapabilities();2capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilecal");3capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_VERSION, "1.0");4capabilities.setCapability(IOSMobileCapabilityType.LANGUAGE, "en");5capabilities.setCapability(IOSMobileCapabilityType.LOCALE, "en_GB");6capabilities.setCapability(IOSMobileCapabilityType.DEVICE_NAME, "iPhone Simulator");7capabilities.setCapability(IOSMobileCapabilityType.UDID, "CEC0E5C8-3E1F-4C3F-9F0F-9B4B4D4E7F4B");8DesiredCapabilities capabilities = new DesiredCapabilities();9capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilecal");10capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_VERSION, "1.0");11capabilities.setCapability(IOSMobileCapabilityType.LANGUAGE, "en");12capabilities.setCapability(IOSMobileCapabilityType.LOCALE, "en_GB");13capabilities.setCapability(IOSMobileCapabilityType.DEVICE_NAME, "iPhone Simulator");14capabilities.setCapability(IOSMobileCapabilityType.UDID, "CEC0E5C8-3E1F-4C3F-9F0F-9B4B4D4E7F4B");15DesiredCapabilities capabilities = new DesiredCapabilities();16capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilecal");17capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_VERSION, "1.0");18capabilities.setCapability(IOSMobileCapabilityType.LANGUAGE, "en");19capabilities.setCapability(IOSMobileCapabilityType.LOCALE, "en_GB");20capabilities.setCapability(IOSMobileCapabilityType.DEVICE_NAME, "iPhone Simulator");21capabilities.setCapability(IOSMobileCapabilityType.UDID, "CEC0E5C8-3E1F-4C3F-9F0F-9B4B4D4E7F4B");
IOSMobileCapabilityType
Using AI Code Generation
1DesiredCapabilities caps = new DesiredCapabilities();2caps.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.MobileAddressBook");3caps.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 50000);4caps.setCapability(IOSMobileCapabilityType.WAIT_FOR_APP_SCRIPT, "$.delay(1000); $.acceptAlert();");5caps.setCapability(IOSMobileCapabilityType.AUTO_ACCEPT_ALERTS, true);6caps.setCapability(IOSMobileCapabilityType.AUTO_DISMISS_ALERTS, true);7var desired = {8IOSMobileCapabilityType.WAIT_FOR_APP_SCRIPT: "$.delay(1000); $.acceptAlert();",9};10desired_caps = {11IOSMobileCapabilityType.WAIT_FOR_APP_SCRIPT: "$.delay(1000); $.acceptAlert();",12}13desired_caps = {14IOSMobileCapabilityType.WAIT_FOR_APP_SCRIPT: "$.delay(1000); $.acceptAlert();",15}16$desiredCapabilities = array(17IOSMobileCapabilityType::WAIT_FOR_APP_SCRIPT => "$.delay(1000); $.acceptAlert();",
IOSMobileCapabilityType
Using AI Code Generation
1DesiredCapabilities capabilities = new DesiredCapabilities();2capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 6");3capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");4capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.4");5capabilities.setCapability(MobileCapabilityType.APP, "/Users/username/Desktop/MyApp.app");6capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");7capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);8capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 50000);9capabilities.setCapability(IOSMobileCapabilityType.SIMPLE_ISVISIBLE_CHECK, true);10IOSMobileOptions options = new IOSMobileOptions();11options.addArguments("–uiautomator2");12options.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 6");13options.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");14options.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.4");15options.setCapability(MobileCapabilityType.APP, "/Users/username/Desktop/MyApp.app");16options.setCapability(MobileCapabilityType.BROWSER_NAME, "");17options.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);18options.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 50000);19options.setCapability(IOSMobileCapabilityType.SIMPLE_ISVISIBLE_CHECK, true);20IOSMobileOptions options = new IOSMobileOptions();21options.addArguments("–uiautomator2");22options.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 6");23options.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");24options.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.4");25options.setCapability(MobileCapabilityType.APP, "/Users/username/Desktop/MyApp.app");26options.setCapability(MobileCapabilityType.BROWSER_NAME, "");27options.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);28options.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 50000);29options.setCapability(IOSMobileCapabilityType
IOSMobileCapabilityType
Using AI Code Generation
1import io.appium.java_client.remote.IOSMobileCapabilityType;2cap.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilesafari");3import io.appium.java_client.remote.IOSMobileCapabilityType;4cap.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilesafari");5import io.appium.java_client.remote.IOSMobileCapabilityType;6cap.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilesafari");7import io.appium.java_client.remote.IOSMobileCapabilityType;8cap.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilesafari");9import io.appium.java_client.remote.IOSMobileCapabilityType;10cap.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilesafari");11import io.appium.java_client.remote.IOSMobileCapabilityType;12cap.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilesafari");13import io.appium.java_client.remote.IOSMobileCapabilityType;14cap.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple.mobilesafari");15import io.appium.java_client.remote.IOSMobileCapabilityType;16cap.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "com.apple
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!!