appium / appium-espresso-driver

Espresso integration for Appium
Apache License 2.0
188 stars 75 forks source link

During tests app crashes when trying to initialize WorkManager / WorkManager initializer is not invoked from androidx.startup.InitializationProvider #1026

Open Roman-Markov opened 1 month ago

Roman-Markov commented 1 month ago

Appium: 2.10.3 Espresso driver: 3.3.0

When I added dependency to app under test

implementation 'androidx.work:work-runtime:2.9.0'

and later in code invoked

WorkManager.getInstance(context);

the app started to crash during appium tests with espresso driver.

Exception: java.lang.IllegalStateException: WorkManager is not initialized properly. You have explicitly disabled WorkManagerInitializer in your manifest, have not manually called WorkManager#initialize at this point, and your Application does not implement Configuration.Provider.

Merged manifest file of the app under test has it declared to be initialized via androidx.startup.InitializationProvider

        <provider
            android:name="androidx.startup.InitializationProvider"
            android:exported="false"
            android:authorities="com.example.android.testing.espresso.BasicSample.androidx-startup">

            <meta-data
                android:name="androidx.work.WorkManagerInitializer"
                android:value="androidx.startup" />
        </provider>

My custom provider was initialized and worked fine. Also I copied code from androidx.startup.InitializationProvider to my second custom provider. It could initialize WorkManger on app launch before WorkManager.getInstance(context); was invoked.

Here is repos to reproduce the crash:

A bit modified android espresso sample app: https://github.com/Roman-Markov/appium-espresso-reproducible-crash Simple appium test code: https://github.com/Roman-Markov/simple-appium-test-to-reproduce-crash

Roman-Markov commented 1 month ago

Similar issue:

When appium starts it prevents the initialisation of a RealmDB https://github.com/appium/appium-espresso-driver/issues/793