Speed Up iOS Appium Test Automation

vector-frameworks-appium_2x

     Appium users have the question like how to speed up the iOS tests, citing the length of time it takes to start tests which use the WebDriverAgent library (all tests using the XCUITest driver).

     Most of the perceived speed of an Appium test can’t be improved due to the base speed of booting devices or the UI actions themselves. The slowest part, which users were asking how to avoid, is the initial startup of a test: the time between sending the first POST /session command and the response indicating that your test script can begin sending commands. We can call this time period the “session creation” time.

     There are desired capabilities we can specify to greatly reduce the time it takes to create a session. Appium is built to cater to a large number of devices, for use in many different situations, but we also want to make sure that it is easy to get started automating your first test. When specifying desired capabilities, Appium will analyze the state of your system and choose default values for every desired capability which you don’t specify. By being more specific, we can have Appium skip the work it does to choose the default values.

     Our first improvement is to set the app location to a file already on the host device. Then you can directly use the bundleId 

caps.setCapability(“bundleId”, “io.test.app”);

      Please ignore the remote path of your application in the code instead of that you can use the local application path, once it gets installed on the device avoid the local path and stick to use bundleId

     Running the tests, it’s easy to notice that the app gets reinstalled on the device for each test. This takes a lot of time and can be skipped. You may have certain tests which require a fresh install or need all the app data cleaned, but those tests could be put into a separate suite, leaving the majority of tests to run faster by reusing the same app. Most users should be familiar with the noReset desired capability.

 caps.setCapability(“noReset”, true)

    Appium uses the simctl command-line tool provided by Apple to match the deviceName desired capability to the udid of the device. We can skip this step by specifying the device udid ourselves.

caps.setCapability(“udid”, “009D802528AB4A1BA7C885A9F6FDBE95”);

      When loading the WedDriverAgent server, Appium loads the files from wherever XCode saved it after compilation. This location is called the “Derived Data Directory” and Appium executes an xcodebuild command in order to get the location. Below desired capability derivedDataPath allowing Appium to skip the work of calculating it:

caps.setCapability(“derivedDataPath”, “/Users/sanojs/Library/Developer/Xcode/DerivedData/WebDriverAgent-apridxpigtzdjdecthgzpygcmdkp”);

     The last optimization is to specify the webDriverAgentUrl desired capability. If specified, Appium skips a step where it checks to make sure that there are no obsolete or abandoned WebDriverAgent processes still running. The WebDriverAgent server needs to already be running at this location, so we can only use this desired capability after the first test starts the server.

caps.setCapability(“webDriverAgentUrl”, “http://localhost:8100”);

       I hope the above tips will help you to speed up the iOS automation using Appium. Please try to change your Desired Capability today to get a better speed of automation on the iOS platform.

Refer the tips to improve the speed for Android @https://journeyofquality.wordpress.com/category/speed-up-android-appium-test-automation/

Reference: Appium Pro

make it perfect!

AI for Appium Test Automation

Capture

     Perhaps the most buzzy of the buzzwords in tech these days is “AI” (Artificial Intelligence), or “AI/ML” (throwing in Machine Learning). To most of us, these phrases seem like magical fairy dust that promises to make the hard parts of our tech jobs go away. To be sure, AI is largely over-hyped, or at least its methods and applications are largely misunderstood and therefore assumed to be much more magical than they are.

         How you can use AI with Appium! It’s a bit surprising, but the Appium project has developed an AI-powered element finding plugin for use specifically with Appium.

          First, let’s discuss element finding plugin. In a recent addition to Appium, added the ability for third-party developers to create “plugins” for Appium that can use an Appium driver together with their own unique capabilities to find elements. As we’ll see below, users can access these plugins simply by installing the plugin as an NPM module in their Appium directory, and then using the customFindModules capability to register the plugin with the Appium server.

       The first plugin worked on within this new structure was one that incorporates a machine learning model from Test.ai designed to classify app icons, the training data for which was just open-sourced. This is a model which can tell us, given the input of an icon, what sort of thing the icon represents (for example, a shopping cart button, or a back arrow button). The application we developed with this model was the Appium Classifier Plugin, which conforms to the new element finding plugin format.

      Basically, we can use this plugin to find icons on the screen based on their appearance, rather than knowing anything about the structure of our app or needing to ask developers for internal identifiers to use as selectors. For the time being the plugin is limited to finding elements by their visual appearance, so it really only works for elements which display a single icon. Luckily, these kinds of elements are pretty common in mobile apps.

         This approach is more flexible than existing locator strategies (like accessibility id, or image) in many cases, because the AI model is trained to recognize icons without needing any context, and without requiring them to match only one precise image style. What this means is that using the plugin to find a “cart” icon will work across apps and across platforms, without needing to worry about minor differences.

         So let’s take a look at a concrete example, demonstrating the simplest possible use case. If you fire up an iOS simulator you have access to the Photos application, which looks something like this:

The Photos app with search icon

        Notice the little magnifying glass icon near the top which, when clicked, opens up a search bar:

The Photos app with search bar and cancel text

             Let’s write a test that uses the new plugin to find and click that icon. First, we need to follow the setup instructions to make sure everything will work. Then, we can set up our Desired Capabilities for running a test against the Photos app:

DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("platformName", "iOS");
        caps.setCapability("platformVersion", "11.4");
        caps.setCapability("deviceName", "iPhone 6");
        caps.setCapability("bundleId", "com.apple.mobileslideshow"); 

Now we need to add some new capabilities: customFindModules (to tell Appium about the AI plugin we want to use), and shouldUseCompactResponses (because the plugin itself told us we need to set this capability in its setup instructions):

HashMap<String, String> customFindModules = new HashMap<>();
      customFindModules.put("ai", "test-ai-classifier");
      caps.setCapability("customFindModules", customFindModules);
      caps.setCapability("shouldUseCompactResponses", false); 

         You can see that customFindModules is a capability which has some internal structure: in this case “ai” is the shortcut name for the plugin that we can use internally in our test, and “test-ai-classifier” is the fully-qualified reference that Appium will need to be able to find and require the plugin when we request elements with it.

Once we’ve done all this, finding the element is super simple:

driver.findElement(MobileBy.custom("ai:search")); 

           Here we’re using a new custom locator strategy so that Appium knows we want a plugin, not one of its supported locator strategies. Then, we’re prefixing our selector with ai: to let Appium know which plugin specifically we want to use for this request (because there could be multiple). Of course since we are in fact only using one plugin for this test, we could do away with the prefix (and for good measure we could use the different find command style, too):

driver.findElementByCustom("search");

           And that’s it! As mentioned above, this technology has some significant limitations at the current time, for example that it can really only reliably find elements which are one of the icons that the model has been trained to detect. On top of that, the process is fairly slow, both in the plugin code (since it has to retrieve every element on screen in order to send information into the model), and in the model itself. All of these areas will see improvement in the future, however. And even if this particular plugin isn’t useful for your day-to-day, it demonstrates that concrete applications of AI in the testing space are not only possible, but actual!

Please try to implement above mentioned AI component in your automation script.

make it perfect !

Reference: Appium Pro

Automation with SeeTest Cloud

image2016-3-15 12_13_22

     From my experience with automation execution on Cloud tools, I had done the executions with Perfecto Cloud, Sauce Labs, Browserstack; now am with SeeTest Cloud. In SeeTest Cloud, easily run your Selenium and Appium tests against real iOS, Android & desktop browsers, ensuring that you are testing real user scenarios accurately.

       Start testing mobile and web applications on the cloud. It will support both manual and automation tests. Allows you to easily create automated tests for your mobile application using our large selection of real iOS and Android.

     Here I would like to share what are the capabilities required to execute your automation scripts in SeeTest Cloud for Mobile Native (iOS and Android), Mobile Web (iOS and Android) and Desktop Browsers. Before start setup the capabilities and script execution, you need a account in SeeTest Cloud. For the account, you need to register with SeeTest Cloud (https://cloud.seetest.io/) and get the access key, specify the access key in the set of test capabilities to gain access to remote testing. Once the access key ready, you can set the Desired Capabilities and instantiate the driver for Automation scripts. Following steps helps to get the access key from your registered SeeTest Cloud account,

In the cloud, click on your profile → Get Access Key

Capture.PNG

For Mobile Native - Android

AndroidDriver driver = null;
DesiredCapabilities dc = new DesiredCapabilities(); 
dc.setCapability("testName", "Android Mobile Native Test Execution"); 
dc.setCapability("accessKey", "your_SeeTest_acess_key");
dc.setCapability("deviceQuery", "@os='android'"); 
dc.setCapability("deviceModel", "device_name"); 
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "device OS_version"); 
dc.setCapability(MobileCapabilityType.UDID, "device_UDID"); 
dc.setCapability(MobileCapabilityType.APP, "application_location_in_SeeTest"); 
dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "application_package_name"); 
dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "application_activity_name"); 
driver = new AndroidDriver<>(new URL("https://cloud.seetest.io/wd/hub"), dc);
For Mobile Native - iOS

IOSDriver driver = null;
DesiredCapabilities dc = new DesiredCapabilities(); 
dc.setCapability("testName", "iOS Mobile Native Test Execution");
dc.setCapability("accessKey", "your_SeeTest_acess_key");
dc.setCapability("deviceQuery", "@os='ios'"); 
dc.setCapability("deviceModel", "device_name"); 
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "device_OS_version"); 
dc.setCapability(MobileCapabilityType.UDID, "device_UDID"); 
dc.setCapability(MobileCapabilityType.APP, "application_location_in_SeeTest Cloud"); 
dc.setCapability(IOSMobileCapabilityType.BUNDLE_ID, "Bundle_ID of the application");
driver = new IOSDriver<>(new URL("https://cloud.seetest.io/wd/hub"), dc);
For Mobile Web - Android

AndroidDriver driver = null;
DesiredCapabilities dc = new DesiredCapabilities(); 
dc.setCapability("testName", "Android Mobile Web Test Execution");
dc.setCapability("accessKey", "your_SeeTest_acess_key");
dc.setCapability("deviceQuery", "@os='android'"); 
dc.setCapability("deviceModel", "device_name"); 
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "device_OS_version"); 
dc.setCapability(MobileCapabilityType.UDID, "device_UDID"); 
dc.setBrowserName(MobileBrowserType.CHROMIUM);
driver = new AndroidDriver<>(new URL("https://cloud.seetest.io/wd/hub"), dc);
For Mobile Web- iOS

IOSDriver driver = null;
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("testName", "iOS Mobile Web Test Execution");
dc.setCapability("accessKey", "your_SeeTest_acess_key");
dc.setCapability("deviceQuery", "@os='ios'");
dc.setCapability("deviceModel", "device_name");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "selected_device_OS_version");
dc.setCapability(MobileCapabilityType.UDID, "device_UDID");
dc.setBrowserName(MobileBrowserType.SAFARI);
driver = new IOSDriver<>(new URL("https://cloud.seetest.io/wd/hub"), dc);
For Desktop Web

WebDriver driver;
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("testName", "Desktop Web Test Execution");
dc.setCapability("accessKey", "your_SeeTest_acess_key");
dc.setCapability(CapabilityType.PLATFORM, "desktop_OS_name"); 
dc.setCapability(CapabilityType.BROWSER_NAME, "name of the browser"); 
dc.setCapability(CapabilityType.VERSION, "browser_version");
driver = new RemoteWebDriver(new URL("https://cloud.seetest.io/wd/hub"), dc);

Now, the capabilities and driver is ready, next you can start writing your automation scripts and execute it on SeeTest Cloud.

make it perfect !

 

Mobile Web Automation using Appium and important Desired Capabilities

mobile_app_testing_automation_appium_android_studio_selenium-680x321

     Mobile apps which are written in HTML/JS/CSS and deployed via a web server. Users access them by navigating to a URL in the mobile browser of their choice (e.g., Safari, Chrome).

    Appium enables you to automate any kind of app, across both iOS and Android platforms. The only difference is in how you set up the desired capabilities, and then in the commands you have access to once the session is started. An Appium-based mobile web test is just the same thing as a Selenium test! In fact, you can even use a standard Selenium client to speak to the Appium server and automate a mobile web app. The key is to use the browserName capability instead of the app capability. Appium will then take care of launching the specified browser and getting you automatically into the web context so you have access to all the regular Selenium methods you’re used to (like finding elements by CSS, navigating to URLs, etc…). Following are the important desired capabilities for mobile web application automation using appium,

Mobile Web Android
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “OS version of your test device”);
capabilities.setCapability(“udid”, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, “Chrome”);

Mobile Web iOS
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “iOS”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(“udid”, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.SAFARI);
capabilities.setCapability(“startIWDP”, true);
capabilities.setCapability(IOSMobileCapabilityType.START_IWDP, true);
capabilities.setCapability(“app”, “path of SAFAILAUNCHERAPPPATH”);
//SAFAILAUNCHERAPPPATH = “/usr/local/lib/node_modules/appium/node_modules/appium-ios-driver/build/SafariLauncher/SafariLauncher.app”
capabilities.setCapability(“automationName”, “XCUITest”);
capabilities.setCapability(“realDeviceLogger”, “path of DEVICECONSOLEPATH”);
//DEVICECONSOLEPATH=”/usr/local/lib/node_modules/deviceconsole/deviceconsole”

     For running Safari tests on a real device, or hybrid tests on a real device, IWDP (ios-webkit-debug-proxy) must be installed on your system.

brew install ios-webkit-debug-proxy

Once you’ve got IWDP installed, you simply need to add capability to desired capability.

capabilities.setCapability(“startIWDP”, true);

     If you don’t include the startIWDP capability, you must run IWDP on your own via terminal and Appium will just assume it’s there listening for proxy requests. Once you set your Desired Capabilities, next need to instantiate the drivers for Android and iOS in the following way:

For Android
WebDriver driver;
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”;), capabilities)

For iOS
WebDriver driver;
driver = new IOSDriver(new URL(“http://127.0.0.1:4723/wd/hub”;), capabilities)

Try to use above mentioned Desired Capabilities in your automation scripts for mobile web automation.

make it perfect !

Appium Desired Capabilities for Android and iOS

Screen-Shot-2016-09-28-at-11.03.39-AM

     Most of the time I observed that people facing the issues at the initial stage of running their automation scripts due to lack of knowledge in the selection of Desired Capabilities based on their Automation platform. Here, I would like to explain important Desired Capabilities for following:

  • Mobile Web Android
  • Mobile Web iOS
  • Mobile Native Android
  • Mobile Native iOS

Mobile Web Android
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “OS version of your test device”);
capabilities.setCapability(“udid”, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, “Chrome”);

Mobile Web iOS
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “iOS”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(“udid”, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.SAFARI);
capabilities.setCapability(nativeWebTap, true);
capabilities.setCapability(“startIWDP”, true);
capabilities.setCapability(IOSMobileCapabilityType.START_IWDP, true);
capabilities.setCapability(“app”, “path of SAFAILAUNCHERAPPPATH”);
//SAFAILAUNCHERAPPPATH = “/usr/local/lib/node_modules/appium/node_modules/appium-ios-driver/build/SafariLauncher/SafariLauncher.app”
capabilities.setCapability(“automationName”, “XCUITest”);
capabilities.setCapability(“realDeviceLogger”, “path of DEVICECONSOLEPATH”);
//DEVICECONSOLEPATH=”/usr/local/lib/node_modules/deviceconsole/deviceconsole”

Mobile Native Android
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “Android”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “OS version of your test device”);
capabilities.setCapability(MobileCapabilityType.UDID, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
capabilities.setCapability(MobileCapabilityType.APP, “location of your .APK”);
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, “package name of your Android application”);
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, “activity name of your Android application”);

Mobile Native iOS
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, “iOS”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “name of your test device”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “OS version of your test device”);
capabilities.setCapability(MobileCapabilityType.UDID, “UDID of your test device”);
capabilities.setCapability(MobileCapabilityType.APP, “location of your .iPA or .APP”);
capabilities.setCapability(IOSMobileCapabilityType.BUNDLE_ID, “bundle ID of your iOS application”);
capabilities.setCapability(“automationName”, “XCUITest”);
capabilities.setCapability(“realDeviceLogger”, “path of DEVICECONSOLEPATH”);
//DEVICECONSOLEPATH=”/usr/local/lib/node_modules/deviceconsole/deviceconsole”

     Once you set your Desired Capabilities, next need to instantiate the drivers for Android and iOS in the following way:

For Android
WebDriver driver;
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub&#8221;), capabilities)

For iOS
WebDriver driver;
driver = new IOSDriver(new URL(“http://127.0.0.1:4723/wd/hub&#8221;), capabilities)

Try to use above mentioned Desired Capabilities in your automation scripts.

make it perfect !