android / android/android-test

ActivityScenarioRule does not close ChromeCustomTab when deep linking to app is initiated through button click in web page.

Open
#1,208 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
1.2k
Forks
342
Avg merge
11h 29m
Merged PRs (30d)
2

Description

### Description
There is a difference in behaviour between the deprecated ActivityTestRule and ActivityScenarioRule in combination with deep linking back to the mobile app. This difference in behaviour depends if the deep linking is automatically started in the web page after the page is loaded or the deep linking is initiated by clicking a button in the web page.

**Automatic deep linking from webpage**
When the mobile app launches the ChromeCustomTab to a webpage that automatically redirects back to the mobile app using a deep link, both ActivityScenarioRule and ActivityTestRule correctly re-open the mobile app and show the MainActivity that launched the ChromeCustomTab.

**PROBLEM: Manual deep linking from webpage using button click**
When the mobile app launches the ChromeCustomTab to a webpage that displays a button, and when this button is clicked. Only the tests using the ActivityTestRule correctly re-opens the mobile app and shows the MainActivity that launched the ChromeCustomTab.

The same manual test using the ActivityScenarioRule will re-open the mobile app correctly after the deep link, but instead of showing the MainActivity, the ChromeCustomTab is shown again.

### Steps to Reproduce
The public git repo
https://github.com/siebeprojects/samples-deeplink
contains two AndroidTest classes and to reproduce this problem it is easiest to clone the repo and run these automated UI Tests.

**DeprecatedActivityTestRuleTest class**
This class contains two tests:

1. Test manual deep linking using ActivityTestRule - Test successful
2. Test automatic deep linking using ActivityTestRule - Test successful

**RecommendedActivityScenarioRuleTest class**
This class contains two tests:

1. Test manual deep linking using ActivityScenarioRule - Test failed because it reopens the ChromeCustomTab
2. Test automatic deep linking using ActivityScenarioRule - Test successful
### Expected Results
The tests for both ActivityTestRule and ActivityScenarioRule should close the ChromeCustomTab and show the MainActivity after the deep linking is completed.

### Actual Results
When the deep linking is initiated by a button click in the web page, only the ActivityScenarioTest will relaunch the ChromeCustomTab and will not show the MainActivity after the deep linking is completed. This is perhaps because the ChromeCustomTab has gained focus and therefor will not be closed.

### AndroidX Test and Android OS Versions
**Device**
Name: Pixel_4_API_30_TEST
CPU/ABI: Google Play Intel Atom (x86_64)
Target: google_apis_playstore [Google Play] (API level 30)
Skin: pixel_4
SD Card: 512 MB
fastboot.chosenSnapshotFile:
runtime.network.speed: full
hw.accelerometer: yes
hw.device.name: pixel_4
hw.lcd.width: 1080
hw.initialOrientation: Portrait
image.androidVersion.api: 30
tag.id: google_apis_playstore
hw.mainKeys: no
hw.camera.front: emulated
avd.ini.displayname: Pixel 4 API 30 TEST
hw.gpu.mode: auto
hw.ramSize: 1536
PlayStore.enabled: true
fastboot.forceColdBoot: no
hw.cpu.ncore: 4
hw.keyboard: yes
hw.sensors.proximity: yes
hw.dPad: no
hw.lcd.height: 2280
vm.heapSize: 256
skin.dynamic: yes
hw.device.manufacturer: Google
hw.gps: yes
hw.audioInput: yes
image.sysdir.1: system-images/android-30/google_apis_playstore/x86_64/
showDeviceFrame: yes
hw.camera.back: virtualscene
AvdId: Pixel_4_API_30_TEST
hw.lcd.density: 440
hw.arc: false
hw.device.hash2: MD5:6b5943207fe196d842659d2e43022e20
fastboot.forceChosenSnapshotBoot: no
fastboot.forceFastBoot: yes
hw.trackBall: no
hw.battery: yes
hw.sdCard: yes
tag.display: Google Play
runtime.network.latency: none
disk.dataPartition.size: 6G
hw.sensors.orientation: yes
avd.ini.encoding: UTF-8
hw.gpu.enabled: yes

**Versions**
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.browser:browser:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.4.0"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'

### Link to a public git repo demonstrating the problem:
https://github.com/siebeprojects/samples-deeplink

Contributor guide

Open the contributing guide

Research direction

Clone the linked samples-deeplink repository and run the two AndroidTest classes, comparing DeprecatedActivityTestRuleTest with RecommendedActivityScenarioRuleTest. Trace ActivityScenarioRule handling of the manual button-triggered deep link; done means both rule variants close the ChromeCustomTab and display the launching MainActivity, while automatic deep linking remains successful.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.