Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kautomator - cannot show external application in foreground #695

Open
comdiv opened this issue Jan 4, 2025 · 0 comments
Open

Kautomator - cannot show external application in foreground #695

comdiv opened this issue Jan 4, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@comdiv
Copy link

comdiv commented Jan 4, 2025

Correspond StackOverflow - https://stackoverflow.com/questions/79328816/startactivity-on-external-application-not-bring-it-foreground-in-task-of-testi

Think - it's my own lack of knowledge, but may be it's bug

  1. Where is some external APK
  2. It's required to do some automation tests on it
  3. I'm trying to use Kaspresso+Kautomator (wrapper over express+uiautomator) to accomplish it
  4. If application is already launched, tests work

Phone: POCO X3 Pro, Android version: 11 RKQ1.200826.002, MIUI 12.5.6

In AndroidManifest.xml i quiry visibility of external package

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <application>...</application>
    <queries>
        <package android:name="client.app" /> <!-- real package here -->
    </queries>
</manifest>

So, PackageManager now allows to navigate to required package

In tests:

package my.app

import android.util.Log
import com.kaspersky.components.kautomator.component.text.UiButton
import com.kaspersky.components.kautomator.screen.UiScreen
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import org.junit.Test

class ClientAppTest: TestCase() {
 
    val clientPackage = "client.app"
    object ClientAppScreen : UiScreen<ClientAppScreen >() {
        override val packageName: String = clientPackage 
        val someButton = UiButton{withText("Some")}
    }

    @Test
    fun testPlus() = run {
        step("Open Rosneft") {
            with(device.targetContext) {
                val intent = packageManager.getLaunchIntentForPackage(clientPackage)
                intent!!.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                startActivity(intent)
            }
            ClientAppScreen{
                someButton.isEnabled()
                someButton.click()
            }
        }
    }
}

If not to do intent!!.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - it will be failed - required for application extra to current context.

Problem is that application somehow "started" but not shown in foreground.
So tests failed

If i manually launch application and bring it to front - test pass.

Other links in StackOverflow not cover problem for me

@comdiv comdiv added the bug Something isn't working label Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant