Skip to content

Commit 18a85b3

Browse files
Adds new ResizeDisplayTest
Adds new ResizeDisplayTest
2 parents 910bd7c + e859e49 commit 18a85b3

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed

ui/espresso/EspressoDeviceSample/app/build.gradle

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ android {
66
compileSdk 33
77
defaultConfig {
88
applicationId "com.example.android.testing.espresso.EspressoDeviceSample"
9-
minSdkVersion 14
9+
minSdkVersion 19
1010
targetSdkVersion 33
1111
versionCode 1
1212
versionName "1.0"
@@ -16,12 +16,16 @@ android {
1616
productFlavors {
1717
}
1818
testOptions {
19+
20+
emulatorControl {
21+
enable = true
22+
}
1923
unitTests {
2024
includeAndroidResources = true
2125
}
2226
managedDevices {
2327
devices {
24-
// run with ../gradlew nexusOneApi30DebugAndroidTest
28+
// run with ./gradlew nexusOneApi30DebugAndroidTest
2529
nexusOneApi30(com.android.build.api.dsl.ManagedVirtualDevice) {
2630
// A lower resolution device is used here for better emulator performance
2731
device = "Nexus One"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (C) 2022 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.android.testing.espresso.EspressoDeviceSample
18+
19+
import androidx.test.espresso.device.DeviceInteraction.Companion.setDisplaySize
20+
import androidx.test.espresso.device.EspressoDevice.Companion.onDevice
21+
import androidx.test.espresso.device.filter.RequiresDisplay
22+
import androidx.test.espresso.device.rules.DisplaySizeRule
23+
import androidx.test.espresso.device.sizeclass.HeightSizeClass
24+
import androidx.test.espresso.device.sizeclass.WidthSizeClass
25+
import androidx.test.espresso.device.sizeclass.WidthSizeClass.Companion.WidthSizeClassEnum
26+
import androidx.test.espresso.device.sizeclass.HeightSizeClass.Companion.HeightSizeClassEnum
27+
import androidx.test.ext.junit.rules.activityScenarioRule
28+
import androidx.test.ext.junit.runners.AndroidJUnit4
29+
import org.junit.Rule
30+
import org.junit.Test
31+
import org.junit.runner.RunWith
32+
import androidx.test.espresso.device.sizeclass.WidthSizeClass.Companion.WidthSizeClassEnum.EXPANDED as EXPANDED1
33+
34+
/*
35+
* Illustrates usage of [onDevice] API to change the display size.
36+
*/
37+
@RunWith(AndroidJUnit4::class)
38+
class ResizeDisplayTest {
39+
40+
@get:Rule(order = 1) var activityScenarioRule = activityScenarioRule<MainActivity>()
41+
42+
// Test rule for restoring device to its starting display size when a test case finishes
43+
@get:Rule(order = 2) var displaySizeRule: DisplaySizeRule = DisplaySizeRule()
44+
45+
@Test
46+
fun resizeWindow_compact() {
47+
onDevice().setDisplaySize(
48+
widthSizeClass = WidthSizeClass.COMPACT,
49+
heightSizeClass = HeightSizeClass.COMPACT
50+
)
51+
// Verify visual attributes or state restoration
52+
}
53+
54+
/**
55+
* Setting the display size to EXPANDED would fail in small devices, so the [RequiresDisplay]
56+
* annotation prevents this test from being run on devices outside the EXPANDED buckets.
57+
*/
58+
@RequiresDisplay(
59+
widthSizeClass = WidthSizeClassEnum.EXPANDED,
60+
heightSizeClass = HeightSizeClassEnum.EXPANDED
61+
)
62+
@Test
63+
fun resizeWindow_expanded() {
64+
onDevice().setDisplaySize(
65+
widthSizeClass = WidthSizeClass.EXPANDED,
66+
heightSizeClass = HeightSizeClass.EXPANDED
67+
)
68+
// Verify visual attributes or state restoration
69+
}
70+
}

ui/espresso/EspressoDeviceSample/app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
-->
1717

1818
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
19+
<uses-permission android:name="android.permission.INTERNET" />
1920

2021
<application
2122
android:icon="@drawable/ic_launcher"

ui/espresso/EspressoDeviceSample/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ ext {
2929
robolectricVersion = "4.10.3"
3030
extTruthVersion = "1.6.0-alpha01"
3131
extJUnitVersion = "1.2.0-alpha01"
32-
espressoDeviceVersion = "1.0.0-alpha01"
32+
espressoDeviceVersion = "1.0.0-alpha07"
3333
}

ui/espresso/EspressoDeviceSample/gradle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ android.defaults.buildfeatures.buildconfig=true
2020
android.nonFinalResIds=false
2121
android.nonTransitiveRClass=false
2222
android.useAndroidX=true
23+
android.experimental.androidTest.enableEmulatorControl=true

0 commit comments

Comments
 (0)