Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Access App Store from Appium Script

It’s quite common in mobile app testing that application and test Script with a test session needs an access to various locations. For example, some test scripts need to access URLs, databases, back-end servers or even App Stores (e.g. Google Play or Apple App Store). With the access, test session can get, download or update certain applications from app stores before the actual test session will begin.

In this blog, we’ll take a look of how Appium test script can access Apple App Store and how to use certain XCUIElement components to assist your script with that.

With the help of test automation it’s possible to combine different APIs and even frameworks to get applications tested out. We’ve covered some examples how to use Cucumber with Appium for test automation before and naturally it’s possible to combine other frameworks too.

In iOS test automation, it’s quite common also to combine higher abstraction frameworks with the API foundation that XCTest provides. Few good examples of using KIF framework on iOS and using XCUITest with test recorder are covered also here in Bitbar blog.

Using XCUIElement for UI Object Identification

One of the greatest things in test automation is how it can be used across different frameworks. In this example as well, we’re using Appium with XCUITest and its API. For instance, XCUIElementTypeSearchField is used to get the class name for Appium’s driver instance:

driver.findElement(By.className("XCUIElementTypeSearchField")).sendKeys("Application's Name");

XCUITest and Xcode Test Recorder offers great help for identifying UI elements and those details that are needed for a test script. In addition, there are bunch great tools available for Appium to identify UI elements and yet get the details of Appium automation engine.

Desired Capabilities for Test Session

Naturally, when Appium is used you need to configure suitable desired capabilities to ensure app and test does and access what you want them to do/access. In case of App Store, bundleId should be com.apple.AppStore and for automation run you should configure it be XCUITest (not actually Appium as we’re using XCUIElement function calls as part of it).

The desired capabilities for a working example could be as follows:

capabilities.setCapability("bundleId", "com.apple.AppStore");
capabilities.setCapability("automationName", "XCUITest");
capabilities.setCapability("deviceName", "device");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("udid", deviceUDID);

TIP! If you look for a way to find out what applications have been installed on a device, you can use ideviceinstaller to get that information, plus their bundle ID information. It can be used as follows:

$ ideviceinstaller --list-apps -o list_all

For full detailed instructions on how to create IPA and test package check these verified instructions out!

Code Example for App Store Access from Test Script

And as we’ve gone through the basic things of how to build a test script that can access app store, interact with its UI elements, here is the AppStoreTest() function for your reference:

    @Test
    public void AppStoreTest() throws Exception {

        // Search button at bottom menu
        driver.findElement(By.id("Search")).click();

        // Search text field
        driver.findElement(By.className("XCUIElementTypeSearchField"))
                .sendKeys("Pineapple Pen");

        // driver.hideKeyboard() enclosed within try/catch
        hideKeyboard();

        // Find the parent element of the desired app
        MobileElement parent = driver.findElement(By.id("Pineapple Pen, Ketchapp"));

        // Try to find and click the GET and then INSTALL buttons under the parent
        try {
            driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
            parent.findElement(By.id("GET")).click();
            parent.findElement(By.id("INSTALL")).click();
        } catch (NoSuchElementException e) {
            // If GET button wasn't found, the app has been purchased before and there's a Download button instead
            parent.findElement(By.id("Download")).click();
        }

        // Increase implicit wait time for the download
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.MINUTES);

        // Open the app from within App Store
        driver.findElement(By.id("OPEN")).click();

        // Put implicit wait back to our default value
        driver.manage().timeouts().implicitlyWait(defaultWaitTime, TimeUnit.SECONDS);

        // Allow notifications pop-up
        driver.findElement(By.id("Allow")).click();
        takeScreenshot("PPAP");
    }

The logic with the script is that first ‘search’ button is pressed on App Store and whatever application is searched using .sendKeys. We are also identifying parent window which needs to be inline what app is meant to be installed.

In iOS, after the search provides results the icon first indicates ‘GET’ and after a click it turn ‘INSTALL’ or ‘DOWNLOAD’ depending on whether app has been installed before. After this, it’s possible to open application for a test run or alternatively just keep it on background (e.g. if other application needs to interact/share some details with recently installed app).

That’s it for this time – hopefully you’ll find it useful!

Happy Testing Folks!



This post first appeared on Mobile App Testing Blog, With Games And Web | Test, please read the originial post: here

Share the post

How to Access App Store from Appium Script

×

Subscribe to Mobile App Testing Blog, With Games And Web | Test

Get updates delivered right to your inbox!

Thank you for your subscription

×