diff --git a/ui/espresso/EspressoDeviceSample/app/build.gradle b/ui/espresso/EspressoDeviceSample/app/build.gradle
index 806ea4543..8990d8442 100644
--- a/ui/espresso/EspressoDeviceSample/app/build.gradle
+++ b/ui/espresso/EspressoDeviceSample/app/build.gradle
@@ -6,7 +6,7 @@ android {
compileSdk 33
defaultConfig {
applicationId "com.example.android.testing.espresso.EspressoDeviceSample"
- minSdkVersion 14
+ minSdkVersion 19
targetSdkVersion 33
versionCode 1
versionName "1.0"
@@ -15,13 +15,19 @@ android {
}
productFlavors {
}
+
testOptions {
+
+ emulatorControl {
+ enable = true
+ }
unitTests {
+
includeAndroidResources = true
}
managedDevices {
devices {
- // run with ../gradlew nexusOneApi30DebugAndroidTest
+ // run with ./gradlew nexusOneApi30DebugAndroidTest
nexusOneApi30(com.android.build.api.dsl.ManagedVirtualDevice) {
// A lower resolution device is used here for better emulator performance
device = "Nexus One"
@@ -31,6 +37,16 @@ android {
// to take a screenshot
systemImageSource = "aosp-atd"
}
+ // run with ./gradlew foldApi34DebugAndroidTest
+ foldApi34(com.android.build.api.dsl.ManagedVirtualDevice) {
+ // A lower resolution device is used here for better emulator performance
+ device = "Pixel Fold"
+ apiLevel = 34
+ // Also use the AOSP ATD image for better emulator performance
+ // The androidx.test screenshot APIs will automatically enable hardware rendering
+ // to take a screenshot
+ systemImageSource = "aosp"
+ }
}
}
}
diff --git a/ui/espresso/EspressoDeviceSample/app/src/androidTest/AndroidManifest.xml b/ui/espresso/EspressoDeviceSample/app/src/androidTest/AndroidManifest.xml
index 28336a3ff..9df6d0f59 100644
--- a/ui/espresso/EspressoDeviceSample/app/src/androidTest/AndroidManifest.xml
+++ b/ui/espresso/EspressoDeviceSample/app/src/androidTest/AndroidManifest.xml
@@ -19,8 +19,12 @@
android:versionCode="1"
android:versionName="1.0">
+
+
+
+
diff --git a/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/OnDeviceTest.kt b/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/OnDeviceTest.kt
new file mode 100644
index 000000000..283063a87
--- /dev/null
+++ b/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/OnDeviceTest.kt
@@ -0,0 +1,46 @@
+package com.example.android.testing.espresso.EspressoDeviceSample
+
+import androidx.test.espresso.Espresso.onView
+import androidx.test.espresso.assertion.ViewAssertions.matches
+import androidx.test.espresso.device.DeviceInteraction.Companion.setBookMode
+import androidx.test.espresso.device.DeviceInteraction.Companion.setClosedMode
+import androidx.test.espresso.device.DeviceInteraction.Companion.setFlatMode
+import androidx.test.espresso.device.DeviceInteraction.Companion.setTabletopMode
+import androidx.test.espresso.device.EspressoDevice.Companion.onDevice
+import androidx.test.espresso.device.action.ScreenOrientation
+import androidx.test.espresso.device.controller.DeviceMode.TABLETOP
+import androidx.test.espresso.device.filter.RequiresDeviceMode
+import androidx.test.espresso.device.rules.ScreenOrientationRule
+import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
+import androidx.test.espresso.matcher.ViewMatchers.withId
+import androidx.test.ext.junit.rules.activityScenarioRule
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+/*
+ * Illustrates usage of [onDevice] API to change the mode of foldable devices.
+ */
+@RunWith(AndroidJUnit4::class)
+class OnDeviceTest {
+
+ @get:Rule(order = 1) var activityScenarioRule = activityScenarioRule()
+
+ @get:Rule(order = 2) var screenOrientationRule: ScreenOrientationRule =
+ ScreenOrientationRule(ScreenOrientation.LANDSCAPE)
+
+ @Test
+ @RequiresDeviceMode(TABLETOP)
+ fun tabletopMode_playerIdDisplayed() {
+
+ onDevice().setBookMode()
+ // Type text and then press the button.
+ onView(withId(R.id.hello_tv)).check(matches(isDisplayed()))
+// onDevice().setTabletopMode()
+// onDevice().setClosedMode()
+// onView(withId(R.id.hello_tv)).check(matches(isDisplayed()))
+// onDevice().setFlatMode()
+// onView(withId(R.id.hello_tv)).check(matches(isDisplayed()))
+ }
+}
diff --git a/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/RequiresDisplayTest.kt b/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/RequiresDisplayTest.kt
index 6ba423979..d14c5af1c 100644
--- a/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/RequiresDisplayTest.kt
+++ b/ui/espresso/EspressoDeviceSample/app/src/androidTest/java/com/example/android/testing/espresso/EspressoDeviceSample/RequiresDisplayTest.kt
@@ -15,6 +15,8 @@
*/
package com.example.android.testing.espresso.EspressoDeviceSample
+import androidx.test.espresso.device.EspressoDevice.Companion.onDevice
+import androidx.test.espresso.device.action.setTabletopMode
import androidx.test.espresso.device.filter.RequiresDisplay
import androidx.test.espresso.device.sizeclass.HeightSizeClass
import androidx.test.espresso.device.sizeclass.WidthSizeClass
@@ -27,6 +29,7 @@ import org.junit.runner.RunWith
*/
@RunWith(AndroidJUnit4::class)
class RequiresDisplayTest {
+
@RequiresDisplay(
widthSizeClass = WidthSizeClass.Companion.WidthSizeClassEnum.COMPACT,
heightSizeClass = HeightSizeClass.Companion.HeightSizeClassEnum.COMPACT
@@ -90,4 +93,4 @@ class RequiresDisplayTest {
)
@Test
fun testOnDevicesWithExpandedWidthAndHeight() {}
-}
\ No newline at end of file
+}
diff --git a/ui/espresso/EspressoDeviceSample/app/src/main/AndroidManifest.xml b/ui/espresso/EspressoDeviceSample/app/src/main/AndroidManifest.xml
index 6b29b606b..6f0729028 100644
--- a/ui/espresso/EspressoDeviceSample/app/src/main/AndroidManifest.xml
+++ b/ui/espresso/EspressoDeviceSample/app/src/main/AndroidManifest.xml
@@ -16,6 +16,7 @@
-->
+
-
diff --git a/ui/espresso/EspressoDeviceSample/app/src/main/AppManifest.xml b/ui/espresso/EspressoDeviceSample/app/src/main/AppManifest.xml
index a314a52af..5f6eab579 100644
--- a/ui/espresso/EspressoDeviceSample/app/src/main/AppManifest.xml
+++ b/ui/espresso/EspressoDeviceSample/app/src/main/AppManifest.xml
@@ -18,5 +18,5 @@
-
+
diff --git a/ui/espresso/EspressoDeviceSample/app/src/main/res/layout/activity_main.xml b/ui/espresso/EspressoDeviceSample/app/src/main/res/layout/activity_main.xml
index 3e52e22f1..fc8461066 100644
--- a/ui/espresso/EspressoDeviceSample/app/src/main/res/layout/activity_main.xml
+++ b/ui/espresso/EspressoDeviceSample/app/src/main/res/layout/activity_main.xml
@@ -21,4 +21,9 @@
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin"
tools:context=".MainActivity">
+
diff --git a/ui/espresso/EspressoDeviceSample/build.gradle b/ui/espresso/EspressoDeviceSample/build.gradle
index 8f441bd84..8ddb5c1e8 100644
--- a/ui/espresso/EspressoDeviceSample/build.gradle
+++ b/ui/espresso/EspressoDeviceSample/build.gradle
@@ -2,7 +2,7 @@
buildscript {
ext.kotlinVersion = "1.7.10"
- ext.agpVersion = "8.1.1"
+ ext.agpVersion = "8.3.0-beta02"
repositories {
// Insert local test repo here
google()
@@ -29,5 +29,5 @@ ext {
robolectricVersion = "4.10.3"
extTruthVersion = "1.6.0-alpha01"
extJUnitVersion = "1.2.0-alpha01"
- espressoDeviceVersion = "1.0.0-alpha01"
+ espressoDeviceVersion = "1.0.0-alpha07"
}
diff --git a/ui/espresso/EspressoDeviceSample/gradle.properties b/ui/espresso/EspressoDeviceSample/gradle.properties
index 20d5b5682..6ae4cdced 100644
--- a/ui/espresso/EspressoDeviceSample/gradle.properties
+++ b/ui/espresso/EspressoDeviceSample/gradle.properties
@@ -20,3 +20,4 @@ android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.nonTransitiveRClass=false
android.useAndroidX=true
+android.experimental.androidTest.enableEmulatorControl=true
diff --git a/ui/espresso/EspressoDeviceSample/gradle/wrapper/gradle-wrapper.properties b/ui/espresso/EspressoDeviceSample/gradle/wrapper/gradle-wrapper.properties
index b93c46a5f..1dc51a370 100644
--- a/ui/espresso/EspressoDeviceSample/gradle/wrapper/gradle-wrapper.properties
+++ b/ui/espresso/EspressoDeviceSample/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,6 @@
+#Thu Jan 18 11:36:24 UTC 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists