Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions espresso/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
implementation libs.material
implementation libs.junit
implementation libs.androidx.junit
implementation libs.androidx.espresso.device
api(libs.androidx.uiautomator)
api(libs.espresso.core)
api(libs.espresso.contrib)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.progressive.kherkin.espresso.steps.actions

import androidx.test.espresso.device.DeviceInteraction.Companion.setScreenOrientation
import androidx.test.espresso.device.EspressoDevice.Companion.onDevice
import androidx.test.espresso.device.action.ScreenOrientation
import com.progressive.kherkin.common.testcore.Gherkin

/**
* Rotates the emulator or device to landscape orientation.
* Remember to rotate back to portrait, or use a rule to start tests in the desired orientation.
*/
fun Gherkin.IRotateToLandscape() {
onDevice().setScreenOrientation(ScreenOrientation.LANDSCAPE)
}

/**
* Rotates the emulator or device to portrait orientation.
*/
fun Gherkin.IRotateToPortrait() {
onDevice().setScreenOrientation(ScreenOrientation.PORTRAIT)
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.code.style=official
android.experimental.androidTest.enableEmulatorControl=true
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ appcompat = "1.7.1"
composeBom = "2025.06.01"
constraintlayout = "2.2.1"
espresso = "3.6.1"
espressoDevice = "1.1.0"
findbugs = "3.0.2"
fragmentKtx = "1.8.8"
javaxInject = "1"
Expand All @@ -25,6 +26,7 @@ viewbinding = "8.11.0"
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }
androidx-espresso-device = { module = "androidx.test.espresso:espresso-device", version.ref = "espressoDevice" }
androidx-fragment-ktx = { module = "androidx.fragment:fragment-ktx", version.ref = "fragmentKtx" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidxJunit" }
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycleViewmodelKtx" }
Expand Down
3 changes: 3 additions & 0 deletions sampleapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ android {
}
}
}
emulatorControl {
enable = true
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.progressive.sampleapp.tests.espresso

import com.progressive.kherkin.common.testcore.And
import com.progressive.kherkin.common.testcore.Given
import com.progressive.kherkin.common.testcore.Then
import com.progressive.kherkin.common.testcore.When
import com.progressive.kherkin.espresso.steps.actions.IRotateToLandscape
import com.progressive.kherkin.espresso.steps.actions.IRotateToPortrait
import com.progressive.kherkin.espresso.steps.assertion.IShouldNotSee
import com.progressive.kherkin.espresso.steps.assertion.IShouldSee
import com.progressive.kherkin.espresso.steps.setup.IRenderScreen
import com.progressive.kherkin.sampleapp.R
import com.progressive.sampleapp.screens.espresso.MainScreen
import com.progressive.sampleapp.setup.SampleBaseIntegrationTestCase
import org.junit.Test

class TestScreenOrientationSteps : SampleBaseIntegrationTestCase() {

@Test
fun testRotateToLandscapeStep() {
Given.IRenderScreen(MainScreen())
When.IRotateToLandscape()
Then.IShouldSee(R.id.buttonNav)
And.IShouldNotSee(R.id.kherkin_logo)
And.IRotateToPortrait()
}

@Test
fun testRotateToPortraitStep() {
Given.IRenderScreen(MainScreen())
And.IRotateToLandscape()
And.IShouldNotSee(R.id.kherkin_logo)
When.IRotateToPortrait()
Then.IShouldSee(R.id.kherkin_logo)
}
}
4 changes: 4 additions & 0 deletions sampleapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Permissions needed to rotate emulator or device -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Loading