0

I'm uploading my Android apk and instrumentationTest apk to aws device farm, but it keeps running my app in portait.

In my app I have set the orientation to landscape in the manifest with

android:screenOrientation="sensorLandscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"

then in my test I run (in the @Before)

UiDevice mDevice = UiDevice.getInstance(getInstrumentation());
try {
    mDevice.setOrientationLeft();
} catch (RemoteException e) {
    e.printStackTrace();
}

But it still runs in portrait.

So is it something I need to set in my app, or is it a setting in AWS device farm, as I can't find anything on the site or in google

Russ Wheeler
  • 2,590
  • 5
  • 30
  • 57

2 Answers2

0

It may be the case that we need to set this inside of the tests itself and not in the @Before. Every execution of a test in device farm is independent of one another. When you get the chance could you try the code in this other SO post?

https://stackoverflow.com/a/6206510/4358385

HTH

jmp
  • 2,175
  • 2
  • 17
  • 16
  • I read that, but the thing is I don't think I have access to an Activity. I am using UiAutomator, which uses UiDevice and just does clicks to coordinates. I can't find views or any Android classes, at least I don't think I can. I copied many diff test examples to get this to work, and can't remember how I did now! Plus I'm using a gaming library called LibGDX, which has no Android classes, just a single Activity. – Russ Wheeler Nov 14 '17 at 00:51
  • Hmm can you get this working on a local physical device? – jmp Nov 17 '17 at 23:45
0

Update: Looking at the sample Android app it would appear they don't put the @before inside of the test class. They do that in a base class and then extend that.

https://github.com/awslabs/aws-device-farm-sample-app-for-android/blob/master/app/src/androidTest/java/com/amazonaws/devicefarm/android/referenceapp/Categories/AlertPageTest.java

When you get the chance could you let me know if you're using the @before inside of the test class and if you could move it to a base class like the example? My hypothesis is that this might work because of Device Farms execution environment. It might not be running the @before like we expect

jmp
  • 2,175
  • 2
  • 17
  • 16
  • I can potentially try, but probably not till the weekend. Why do you think it would work if the @ Before was in a base class? Surely if it runs a @ Before method it does it regardless of being in a base, or main class? – Russ Wheeler Nov 22 '17 at 00:09
  • From my previous experience, device farms parser is weird. It will unzip the tests and then inspect it for the actual test methods. It creates a new instance of the test environment for each test before running it. But the @before in a base class should run before the actual tests are executed so it might take affect for all tests then. – jmp Nov 22 '17 at 01:53