How to rotate activity, I mean: screen orientation change using Espresso?

前端 未结 6 1322
萌比男神i
萌比男神i 2020-12-30 00:11

I have decided that one of the testing criteria for my application tests with Google\'s Espresso is:

Test should maintain Activity state after s

6条回答
  •  独厮守ぢ
    2020-12-30 00:37

    You can do it with uiautomator library

    dependencies {
      androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' 
    }
    

    ui automator require min sdk version 18 so if your app has a lower min sdk you need to create a new AndroidManifest.xml in androidTest folder

    
    
        
    
    

    and then in your test

    UiDevice device = UiDevice.getInstance(getInstrumentation());
    
    device.setOrientationLeft();
    device.setOrientationNatural();
    device.setOrientationRight();
    

提交回复
热议问题