3

I have been working on sample UIAutomator project. I have created new Testcases using AndroidX Testing libraries.

I am able to build, run the test cases from the command line. But when I tried to open the app from Android Studio I can see most of the classes are not imported properly. For eg.,

import androidx.test.uiautomator.UiObject2;
import org.junit.Before;

The above two imports are showing as not imported. Likewise lots of classes are showing the same error except android.content.Context, android.content.Intent, etc.,

Can someone through some light on this. I am able to execute the testcases properly from the command line but not able to execute them properly from Android Studio.

I have Restarted PC/Studio, cleared caches, still the problem exists.

below is the dependency I have added in app/build.gradle.

androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'androidx.test:core:1.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.0.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'junit:junit:4.12'

Added the below code in gradle.properties

android.useAndroidX=true
android.enableJetifier=true

I have pretty much followed the same what I have got from android-testing-master/ui/uiautomator sample code, not sure what I am missing.

user2431170
  • 151
  • 2
  • 11

1 Answers1

0

I faced same problem too (Android Studio 3.4.2), uiautomator was red:

import androidx.test.uiautomator.UiDevice

"Clean Project" and "Rebuild Project" didn't help, even invalidating caches. But choosing another Build Variant helped me.

franiis
  • 1,378
  • 1
  • 18
  • 33