UI Test Automation: Testing with Deep Links

Beyza Budak
ÇSTech
7 min readDec 16, 2022

--

Authors: Beyza Budak & Can Kaygusuz

1.1 What is a Deep link?

We often use mobile applications, which have become an indispensable part of our daily lives. While shopping, listening to music, looking for directions, etc. The links in the push notifications or sms that come to us caught our attention. When we click on these, we observe that if the application is installed, for example, if a product is on sale, we can go to its details. So how is this achieved? What makes us redirect to the page in the application when we click on the notifications? The answer is Deep links. Deep linking in mobile applications can be expressed with a URI (Uniform Resource Identifier) that points to a screen (contents, processes, etc.) within the mobile application instead of launching the application. Deep linking allows app developers to link to specific app products or pages. Also, they’re not easy to implement and require careful testing. If you do not add testing deep links to the test processes, you will cause users to have a negative experience in case of possible errors.

1.2 Why did we need to test using the Deep link?

The first reason we did this was to reach the pages that we cannot go to with a click (button, banner, or similar) through deep links and to test them as well. For example, in our application, there was a visual confirmation form sent by the flower dealer when the customer shopped for flowers. This form was only allowed to be opened in the application by clicking the sms and push notification sent by the dealer, there was no text, button, etc. directed here. As the automation team, we were responsible for the UI control of every page in the application, and we thought to launch the pages in this way in the application. So how did we achieve this, let’s learn together how to do it on both android and ios below.

Figure 1: How Deep Links works

2.1 The choice of the method we use?

Above, we have explained deep links and why we want to do a deep link test. In this section, we will talk about which methods and why we prefer when using them.

Let’s start with Android first. There are 3 different methods for testing deep links in Android and they are testing with ADB, testing with espresso intents, and testing with ActivityScenarioRule. The logic of all of them is the same, to launch an intent. Since we used espresso in our UI tests, we chose to use espresso for integrity while testing the deep links. We used Espresso’s espresso-intents extension to make our app perform what we expect when we click a link. Espresso-intents make easy these checks with the intended() method, which verifies that an Intent was seen during testing that matches the given criteria. We opened the page and made an in-page assert using other functions of espresso. With some simple settings, we can use it to check whether the application sees the links we enter.

We were using the XCode UI test on IOS and there were 2 different methods to do this. One is to go to the deep link by clicking on iMessage and the other is to type the deep link through Safari and click open in the application.

2.2 Test Scenarios

Figure 2: Test steps without using deep link

Title: What is Collection Page — Control of title and button on what is collection page

Description: It should be seen that the title of the What is Collection page is correct and when the button is clicked, it goes to the collection creation screen.

Precondition: Login if not opened with deep link

Test Steps:

1. The application opens with the live api selected

2. Click on the Favorites tab, click on the sign in button, and redirect to the login page and login.

3. It is observed that the collection listing page appears and the first collection is clicked on from the listing page.

4. After going to the collection detail page, the top settings are pressed and it is observed that the bottom sheet dialog is opened.

5. After clicking on what is a collection option, the title and button are checked on the page that opens.

As you can see above, the What is a collection page can be accessed from within the application with these steps, without using manual or deep links. We talked about pages that cannot be opened from within the application. In addition, if only those pages will be tested on the pages opened from within the application (if no end-to-end testing will be performed), we can use deep links to save time. Let’s see how many steps it takes to use a deep link.

Figure 3: Test steps without using deep link

Title: What is Collection Page — Control of title and button on what is collection page

Description: It should be seen that the title of the What is Collection page is correct and when the button is clicked, it goes to the collection creation screen.

Precondition: Login if not opened with deep link

Test Steps:

1. The application opens with the live api selected. Also Pop up select case works in setup every time.

2. Assert the title and button are checked on the page that opens.

3. Usages And Experiences Shared

3.1 Usage in Android

First of all, we implement the espresso-intents extension into the build.gradle in our project.

    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'

We create our test class and define our rule in it. Here we normally use MainActivity as an activity in our tests, but here we will use the class where deep links are handled in the application. For more information and implementation about ActivityTestRule please click.

@Rule
@JvmField
var deepLinkActivityHandler = ActivityTestRule(MyDLHandlerActivity::class.java, true, false)

Uri (uniform resource identifier) is a standard used to name a resource or data. It also qualifies the source. This type of information is required when using Intent. Therefore, we parsed the URI we defined for the intent and added it as a variable. You can also choose to write in the code, we preferred to define Constanta. Because it stops more regularly and when it changes, we can change the URI from one place instead of going to the places we call one by one.

private val DEEPLINK_URI_WHAT_IS_COLLECTION = Uri.parse("cstest://0/about-collection")
@Test
fun test_what_is_collection_deeplink(){
val intent = Intent(Intent.ACTION_VIEW, DEEPLINK_URI_WHAT_IS_COLLECTION)
// New task and clearing previous tasks
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
deepLinkActivityHandler.launchActivity(intent)
// Get the title from the toolbar and assert it
Assert.assertEquals(
getToolbar()?.title,
WHAT_IS_COLLECTİON_TITLE
)
/* click(), withIdAccess(), accessItemIsDisplayedOnView(), isDisplayed()
warning :extension used */
R.id.button.accessItemIsDisplayedOnView().isDisplayed()
R.id.button.withIdAccess().click()
}
Figure 4: Android Test Results

3.2 Usage in IOS

Here we were defining the app in normal cases.

    var app: XCUIApplication!

Likewise, we make a definition for Safari, and just like we call it app.launch, we also launch for Safari in our tests.

let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
safari.launch()

After starting Safari, we do the test steps given below and then write our tests for the usual application.

1-application setup settings are made
2-the application is run
3-open the safari
4- deep link is written in the address bar
5-Press the “Open” button on the pop-up
6-It is checked whether the desired page has been reached.

 struct DeepLinkUtils {
static func openFromSafari(with urlString: String) {
let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
safari.launch()
XCTAssert(safari.wait(for: .runningForeground, timeout: 3))
tapIfExists(app: safari, title: "Continue")
safari.otherElements["URL"].tap()
safari.textFields["Address"].tap()
tapIfExists(app: safari, title: "Continue")
safari.typeText(urlString)
safari.buttons["Go"].tap()
tapIfExists(app: safari, title: "Open")
}
 func test_DeepLink_What_Is_Collection(){
DeepLinkUtils.openFromSafari(with: shareDeepLink)
// shareDeepLink was identified in ConstantClass as a String
}

Thank you for reading. You can contact us for the places you do not understand or the problems you experience while applying. Stay tuned for more UI Test Automation content.

--

--