HakAl / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

Perform screen rotation #78

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Can't seem to force a screen orientation change to test CR-5 from the test list 
in the Core App Quality test list 
http://developer.android.com/distribute/essentials/quality/core.html#tests

I've tried making my own ViewAction but it crashes:

onView(isRoot()).perform(new ViewAction() {
            @Override
            public Matcher<View> getConstraints() {
                return isRoot();
            }

            @Override
            public String getDescription() {
                return " rotate screen to landscape";
            }

            @Override
            public void perform(UiController uiController, View view) {
                uiController.loopMainThreadUntilIdle();
                final Activity activity = (Activity) view.getContext();
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                while (activity.getResources().getConfiguration().orientation != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                    uiController.loopMainThreadForAtLeast(50);
                }
            }
        });

Here's the stack trace:
06-02 11:05:05.543    9207-9207/uk.co.imagitech.learn2 E/GoogleInstr﹕ 
Exception encountered by: uk.co.imagitech.learn2.QuestionActivity@42955738. 
Dumping thread state to outputs and pining for the fjords.
06-02 11:05:05.568    9207-9207/uk.co.imagitech.learn2 E/THREAD_STATE﹕ 
Thread[Picasso-refQueue,5,main]
    java.lang.Object.wait(Native Method)
    java.lang.Object.wait(Object.java:401)
    java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:102)
    java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:73)
    com.squareup.picasso.Picasso$CleanupThread.run(Picasso.java:352)
    Thread[Instr: com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner,5,main]
    java.lang.Object.wait(Native Method)
    java.lang.Thread.parkFor(Thread.java:1231)
    sun.misc.Unsafe.park(Unsafe.java:323)
    java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
    java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:813)
    java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:973)
    java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1282)
    java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:219)
    java.util.concurrent.FutureTask.get(FutureTask.java:82)
    com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:155)
    com.google.android.apps.common.testing.ui.espresso.ViewInteraction.doPerform(ViewInteraction.java:90)
    com.google.android.apps.common.testing.ui.espresso.ViewInteraction.perform(ViewInteraction.java:73)
    uk.co.imagitech.learn2.test.ExamQuestionActivityTest.test_resultsOrientation(ExamQuestionActivityTest.java:70)
    java.lang.reflect.Method.invokeNative(Native Method)
    java.lang.reflect.Method.invoke(Method.java:511)
    android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
    android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
    android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
    junit.framework.TestCase.runBare(TestCase.java:134)
    junit.framework.TestResult$1.protect(TestResult.java:115)
    junit.framework.TestResult.runProtected(TestResult.java:133)
    junit.framework.TestResult.run(TestResult.java:118)
    junit.framework.TestCase.run(TestCase.java:124)
    android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:192)
    android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:177)
    android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
    com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167)
    android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1619)
    Thread[Binder_2,5,main]
    dalvik.system.NativeStart.run(Native Method)
    Thread[JDWP,5,system]
    dalvik.system.NativeStart.run(Native Method)
    Thread[Picasso-Idle,5,main]
    java.lang.Object.wait(Native Method)
    java.lang.Thread.parkFor(Thread.java:1231)
    sun.misc.Unsafe.park(Unsafe.java:323)
    java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
    java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2022)
    java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413)
    java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1009)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1069)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    java.lang.Thread.run(Thread.java:856)
    com.squareup.picasso.Utils$PicassoThread.run(Utils.java:218)
    Thread[Picasso-Idle,5,main]
    java.lang.Object.wait(Native Method)
    java.lang.Thread.parkFor(Thread.java:1231)
    sun.misc.Unsafe.park(Unsafe.java:323)
    java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
    java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2022)
    java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413)
    java.
06-02 11:05:05.568    9207-9207/uk.co.imagitech.learn2 E/GoogleInstr﹕ Dying 
now...

What version of the product are you using? On what operating system?
Android 4.1.2, Android Studio 0.5.9

Original issue reported on code.google.com by zboa...@gmail.com on 2 Jun 2014 at 10:07

GoogleCodeExporter commented 9 years ago
The activity gets destroyed and re-created upon rotation, so you're holding on 
to a stale object.

After the rotation, try using ActivityLifecyleMonitor to aquire the currently 
resumed activity: 
https://code.google.com/p/android-test-kit/source/browse/testrunner/src/main/jav
a/com/google/android/apps/common/testing/testrunner/ActivityLifecycleMonitor.jav
a#89

Here's an example of how it's done: 
https://code.google.com/p/android-test-kit/source/browse/espresso/lib/src/main/j
ava/com/google/android/apps/common/testing/ui/espresso/base/RootViewPicker.java#
153

Original comment by vale...@google.com on 9 Jun 2014 at 9:52

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Somewhat related, here is a custom ViewAction I created for making this 
simpler, in case people stumble upon this when looking for how to do change 
orientation:
https://gist.github.com/nbarraille/03e8910dc1d415ed9740

Original comment by nathan.b...@gmail.com on 9 Mar 2015 at 7:14