Use test kit in sample UI tests (#33)
* Update PhotoEditor dependencies and tests * Update FoldingVideo dependencies and tests * Update SourceEditor dependencies and tests * Update TwoNote dependencies and tests * Import ForceClick
This commit is contained in:
Родитель
c14d6a4258
Коммит
e52c21050f
|
@ -35,11 +35,11 @@ android {
|
|||
dependencies {
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.core:core-ktx:1.6.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
|
||||
implementation 'com.google.android.material:material:1.3.0'
|
||||
implementation 'androidx.core:core-ktx:1.7.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
implementation 'androidx.window:window:1.0.0'
|
||||
implementation 'com.google.android.exoplayer:exoplayer:2.14.0'
|
||||
|
||||
|
@ -48,6 +48,7 @@ dependencies {
|
|||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.4.0"
|
||||
androidTestImplementation "androidx.test:rules:1.3.0"
|
||||
androidTestImplementation "androidx.test:rules:1.4.0"
|
||||
androidTestImplementation "androidx.test.uiautomator:uiautomator:2.2.0"
|
||||
androidTestImplementation "com.microsoft.device.dualscreen.testing:testing-kotlin:1.0.0-alpha2"
|
||||
}
|
|
@ -10,10 +10,12 @@ import androidx.test.espresso.Espresso.onView
|
|||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.ext.junit.rules.ActivityScenarioRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.ActivityTestRule
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import com.microsoft.device.dualscreen.testing.resetOrientation
|
||||
import com.microsoft.device.dualscreen.testing.spanFromStart
|
||||
import org.hamcrest.Description
|
||||
import org.hamcrest.Matcher
|
||||
import org.hamcrest.TypeSafeMatcher
|
||||
|
@ -25,7 +27,7 @@ import org.junit.runner.RunWith
|
|||
class UITests {
|
||||
|
||||
@get:Rule
|
||||
val activityRule = ActivityTestRule(MainActivity::class.java)
|
||||
val activityRule = ActivityScenarioRule(MainActivity::class.java)
|
||||
|
||||
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
|
||||
|
@ -60,7 +62,7 @@ class UITests {
|
|||
}
|
||||
|
||||
override fun describeTo(description: Description) {
|
||||
description.appendText("View should have height $size")
|
||||
description.appendText("View should have width $size")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +74,7 @@ class UITests {
|
|||
}
|
||||
|
||||
override fun describeTo(description: Description) {
|
||||
description.appendText("View shouldn't have height $size")
|
||||
description.appendText("View shouldn't have width $size")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +83,7 @@ class UITests {
|
|||
fun dual_landscape() {
|
||||
|
||||
// span app
|
||||
device.swipe(675, 1780, 1350, 900, 400)
|
||||
device.spanFromStart()
|
||||
|
||||
// check bottom background is 0 height
|
||||
onView(withId(R.id.horiz_background)).check(matches(withHeight(0)))
|
||||
|
@ -94,15 +96,14 @@ class UITests {
|
|||
onView(withId(R.id.horiz_background)).check(matches(notWithHeight(0)))
|
||||
|
||||
// reset rotation
|
||||
device.setOrientationNatural()
|
||||
device.unfreezeRotation()
|
||||
device.resetOrientation()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dual_portrait_split_ctrls() {
|
||||
|
||||
// span app
|
||||
device.swipe(675, 1780, 1350, 900, 400)
|
||||
device.spanFromStart()
|
||||
|
||||
// check right background is 0 width
|
||||
onView(withId(R.id.vert_background)).check(matches(withWidth(0)))
|
||||
|
@ -123,7 +124,7 @@ class UITests {
|
|||
@Test
|
||||
fun dual_portrait_split_ctrls_saved() {
|
||||
// span app
|
||||
device.swipe(675, 1780, 1350, 900, 400)
|
||||
device.spanFromStart()
|
||||
|
||||
// check right background is 0 width
|
||||
onView(withId(R.id.vert_background)).check(matches(withWidth(0)))
|
||||
|
@ -139,8 +140,7 @@ class UITests {
|
|||
device.unfreezeRotation()
|
||||
|
||||
// rotate back
|
||||
device.setOrientationNatural()
|
||||
device.unfreezeRotation()
|
||||
device.resetOrientation()
|
||||
|
||||
// check right background is non 0 width - split ctrls have saved
|
||||
onView(withId(R.id.vert_background)).check(matches(notWithWidth(0)))
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.5.0"
|
||||
ext.kotlin_version = "1.6.10"
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.0.0'
|
||||
classpath 'com.android.tools.build:gradle:7.1.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#Tue May 25 17:39:54 EDT 2021
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
|
|
@ -18,7 +18,7 @@ dependencies {
|
|||
task ktlint(type: JavaExec, group: "verification") {
|
||||
description = "Check Kotlin code style."
|
||||
classpath = configurations.ktlint
|
||||
main = "com.pinterest.ktlint.Main"
|
||||
mainClass.set("com.pinterest.ktlint.Main")
|
||||
args "src/**/*.kt"
|
||||
// to generate report in checkstyle format prepend following args:
|
||||
// "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
|
||||
|
@ -28,6 +28,6 @@ task ktlint(type: JavaExec, group: "verification") {
|
|||
task ktlintFormat(type: JavaExec, group: "formatting") {
|
||||
description = "Fix Kotlin code style deviations."
|
||||
classpath = configurations.ktlint
|
||||
main = "com.pinterest.ktlint.Main"
|
||||
mainClass.set("com.pinterest.ktlint.Main")
|
||||
args "-F", "src/**/*.kt"
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
|
@ -41,7 +40,7 @@ dependencies {
|
|||
implementation androidxDependencies.ktxFragment
|
||||
implementation androidxDependencies.windowManager
|
||||
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
|
||||
|
||||
testImplementation testDependencies.junit
|
||||
androidTestImplementation instrumentationTestDependencies.junit
|
||||
|
@ -49,4 +48,5 @@ dependencies {
|
|||
androidTestImplementation instrumentationTestDependencies.testRunner
|
||||
androidTestImplementation instrumentationTestDependencies.testRules
|
||||
androidTestImplementation instrumentationTestDependencies.uiautomator
|
||||
androidTestImplementation instrumentationTestDependencies.kotlinTesting
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import androidx.test.rule.ActivityTestRule
|
|||
import androidx.test.uiautomator.By
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import androidx.test.uiautomator.Until
|
||||
import com.microsoft.device.dualscreen.testing.closeEnd
|
||||
import com.microsoft.device.dualscreen.testing.spanFromStart
|
||||
import org.hamcrest.CoreMatchers.not
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
@ -39,6 +41,8 @@ class PhotoEditorUITest {
|
|||
@get:Rule
|
||||
val activityRule = ActivityTestRule(MainActivity::class.java)
|
||||
|
||||
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
|
||||
/**
|
||||
* Tests visibility of controls when app spanned vs. unspanned
|
||||
*
|
||||
|
@ -56,7 +60,7 @@ class PhotoEditorUITest {
|
|||
onView(withId(R.id.brightness)).check(matches(withEffectiveVisibility(Visibility.INVISIBLE)))
|
||||
onView(withId(R.id.warmth)).check(matches(withEffectiveVisibility(Visibility.INVISIBLE)))
|
||||
|
||||
spanFromLeft()
|
||||
device.spanFromStart()
|
||||
|
||||
// Switched to dual-screen mode, so dropdown should not exist and all sliders should be visible
|
||||
onView(withId(R.id.controls)).check(doesNotExist())
|
||||
|
@ -88,7 +92,7 @@ class PhotoEditorUITest {
|
|||
val prev = activityRule.activity.findViewById<ImageFilterView>(R.id.image).drawable
|
||||
|
||||
val filesPackage =
|
||||
if (Build.MODEL.contains("Emulator")) {
|
||||
if (Build.MODEL.contains("Emulator") || Build.MODEL.contains("Image")) {
|
||||
"com.android.documentsui" // emulator apk package name
|
||||
} else {
|
||||
"com.google.android.documentsui" // device apk package name
|
||||
|
@ -122,90 +126,9 @@ class PhotoEditorUITest {
|
|||
)
|
||||
|
||||
// Close Files app
|
||||
closeRight()
|
||||
device.closeEnd()
|
||||
|
||||
// Unlock rotation
|
||||
device.unfreezeRotation()
|
||||
}
|
||||
|
||||
/**
|
||||
* HELPER FUNCTIONS FOR DUAL-SCREEN BEHAVIOR
|
||||
*
|
||||
* Use the functions below in your tests when testing dual-screen behaviors and transitions.
|
||||
* Run the "testSpanningHelperFunctions" test below to check that the methods produce
|
||||
* the expected behavior on your device.
|
||||
*
|
||||
* If the test fails, modify the swipe parameters as needed- usually either an increase in the
|
||||
* "steps" parameter or a slight shift in the "endX" parameter.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Runs helper functions and checks that they work as expected
|
||||
*
|
||||
* @precondition device in portrait mode, no other applications are open
|
||||
* (so app by default opens on left screen)
|
||||
*/
|
||||
@Test
|
||||
fun testSpanningHelperFunctions() {
|
||||
spanFromLeft()
|
||||
|
||||
unspanToRight()
|
||||
|
||||
spanFromRight()
|
||||
|
||||
unspanToLeft()
|
||||
|
||||
switchToRight()
|
||||
switchToLeft()
|
||||
closeLeft()
|
||||
}
|
||||
|
||||
companion object {
|
||||
// testing device
|
||||
val device: UiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
|
||||
// Swipe constants
|
||||
const val leftX: Int = 675 // middle of left screen
|
||||
const val rightX: Int = 2109 // middle of right screen
|
||||
const val middleX: Int = 1350 // hinge area
|
||||
const val bottomY: Int = 1780 // bottom of screen
|
||||
const val middleY: Int = 900 // middle of screen
|
||||
const val spanSteps: Int = 400 // spanning swipe
|
||||
const val unspanSteps: Int = 200 // unspanning swipe
|
||||
const val switchSteps: Int = 100 // swipe to switch from one screen to the other
|
||||
const val closeSteps: Int = 50 // swipe to close app
|
||||
}
|
||||
|
||||
private fun spanFromLeft() {
|
||||
device.swipe(leftX, bottomY, middleX, middleY, spanSteps)
|
||||
}
|
||||
|
||||
private fun unspanToLeft() {
|
||||
device.swipe(rightX, bottomY, leftX, middleY, unspanSteps)
|
||||
}
|
||||
|
||||
private fun spanFromRight() {
|
||||
device.swipe(rightX, bottomY, middleX, middleY, spanSteps)
|
||||
}
|
||||
|
||||
private fun unspanToRight() {
|
||||
device.swipe(leftX, bottomY, rightX, middleY, unspanSteps)
|
||||
}
|
||||
|
||||
private fun switchToLeft() {
|
||||
device.swipe(rightX, bottomY, leftX, middleY, switchSteps)
|
||||
}
|
||||
|
||||
private fun switchToRight() {
|
||||
device.swipe(leftX, bottomY, rightX, middleY, switchSteps)
|
||||
}
|
||||
|
||||
private fun closeLeft() {
|
||||
device.swipe(leftX, bottomY, leftX, middleY, closeSteps)
|
||||
}
|
||||
|
||||
private fun closeRight() {
|
||||
device.swipe(rightX, bottomY, rightX, middleY, closeSteps)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
*/
|
||||
|
||||
ext {
|
||||
gradlePluginVersion = "4.1.1"
|
||||
kotlinVersion = "1.6.0"
|
||||
gradlePluginVersion = "7.1.1"
|
||||
kotlinVersion = "1.6.10"
|
||||
compileSdkVersion = 31
|
||||
buildToolsVersion = '30.0.3'
|
||||
targetSdkVersion = compileSdkVersion
|
||||
|
@ -62,12 +62,14 @@ ext {
|
|||
testRunnerVersion = "1.2.0"
|
||||
testRulesVersion = "1.2.0"
|
||||
uiautomatorVersion = "2.2.0"
|
||||
kotlinTestingVersion = "1.0.0-alpha2"
|
||||
|
||||
instrumentationTestDependencies = [
|
||||
junit : "androidx.test.ext:junit:$junitInstrumentationVersion",
|
||||
espressoCore: "androidx.test.espresso:espresso-core:$espressoCoreVersion",
|
||||
testRunner : "androidx.test:runner:$testRunnerVersion",
|
||||
testRules : "androidx.test:rules:$testRulesVersion",
|
||||
uiautomator : "androidx.test.uiautomator:uiautomator:$uiautomatorVersion"
|
||||
junit : "androidx.test.ext:junit:$junitInstrumentationVersion",
|
||||
espressoCore : "androidx.test.espresso:espresso-core:$espressoCoreVersion",
|
||||
testRunner : "androidx.test:runner:$testRunnerVersion",
|
||||
testRules : "androidx.test:rules:$testRulesVersion",
|
||||
uiautomator : "androidx.test.uiautomator:uiautomator:$uiautomatorVersion",
|
||||
kotlinTesting : "com.microsoft.device.dualscreen.testing:testing-kotlin:$kotlinTestingVersion"
|
||||
]
|
||||
}
|
|
@ -8,4 +8,4 @@ distributionBase=GRADLE_USER_HOME
|
|||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
|
|
|
@ -18,7 +18,7 @@ dependencies {
|
|||
task ktlint(type: JavaExec, group: "verification") {
|
||||
description = "Check Kotlin code style."
|
||||
classpath = configurations.ktlint
|
||||
main = "com.pinterest.ktlint.Main"
|
||||
mainClass.set("com.pinterest.ktlint.Main")
|
||||
args "src/**/*.kt"
|
||||
// to generate report in checkstyle format prepend following args:
|
||||
// "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
|
||||
|
@ -28,6 +28,6 @@ task ktlint(type: JavaExec, group: "verification") {
|
|||
task ktlintFormat(type: JavaExec, group: "formatting") {
|
||||
description = "Fix Kotlin code style deviations."
|
||||
classpath = configurations.ktlint
|
||||
main = "com.pinterest.ktlint.Main"
|
||||
mainClass.set("com.pinterest.ktlint.Main")
|
||||
args "-F", "src/**/*.kt"
|
||||
}
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
|
@ -42,7 +41,7 @@ dependencies {
|
|||
implementation androidxDependencies.ktxFragment
|
||||
implementation androidxDependencies.windowManager
|
||||
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
|
||||
|
||||
|
||||
testImplementation testDependencies.junit
|
||||
|
@ -53,5 +52,6 @@ dependencies {
|
|||
androidTestImplementation instrumentationTestDependencies.testRunner
|
||||
androidTestImplementation instrumentationTestDependencies.testRules
|
||||
androidTestImplementation instrumentationTestDependencies.uiautomator
|
||||
androidTestImplementation instrumentationTestDependencies.kotlinTesting
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,11 @@ import androidx.test.espresso.matcher.ViewMatchers
|
|||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.filters.MediumTest
|
||||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.ActivityTestRule
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import com.microsoft.device.display.wm_samples.sourceeditor.utils.childOf
|
||||
import com.microsoft.device.display.wm_samples.sourceeditor.utils.setOrientationLeft
|
||||
import com.microsoft.device.display.wm_samples.sourceeditor.utils.setOrientationRight
|
||||
import com.microsoft.device.display.wm_samples.sourceeditor.utils.switchFromSingleToDualScreen
|
||||
import com.microsoft.device.display.wm_samples.sourceeditor.utils.unfreezeRotation
|
||||
import com.microsoft.device.dualscreen.testing.spanFromStart
|
||||
import org.hamcrest.Matchers
|
||||
import org.junit.After
|
||||
import org.junit.Rule
|
||||
|
@ -23,29 +22,30 @@ import org.junit.runner.RunWith
|
|||
class SourceEditorInDualScreenTest {
|
||||
@get:Rule
|
||||
val activityRule = ActivityTestRule(MainActivity::class.java)
|
||||
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
unfreezeRotation()
|
||||
device.unfreezeRotation()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun previewWithoutOrientation() {
|
||||
switchFromSingleToDualScreen()
|
||||
device.spanFromStart()
|
||||
testPreview()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun previewWithOrientationLeft() {
|
||||
switchFromSingleToDualScreen()
|
||||
setOrientationLeft()
|
||||
device.spanFromStart()
|
||||
device.setOrientationLeft()
|
||||
testPreview()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun previewWithOrientationRight() {
|
||||
switchFromSingleToDualScreen()
|
||||
setOrientationRight()
|
||||
device.spanFromStart()
|
||||
device.setOrientationRight()
|
||||
testPreview()
|
||||
}
|
||||
|
||||
|
|
|
@ -12,12 +12,11 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
|||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.filters.MediumTest
|
||||
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.ActivityTestRule
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import com.microsoft.device.display.wm_samples.sourceeditor.utils.SimpleFragmentBackStackListener
|
||||
import com.microsoft.device.display.wm_samples.sourceeditor.utils.forceClick
|
||||
import com.microsoft.device.display.wm_samples.sourceeditor.utils.setOrientationLeft
|
||||
import com.microsoft.device.display.wm_samples.sourceeditor.utils.setOrientationRight
|
||||
import com.microsoft.device.display.wm_samples.sourceeditor.utils.unfreezeRotation
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
|
@ -30,6 +29,7 @@ class SourceEditorInSingleScreenTest {
|
|||
@get:Rule
|
||||
val activityRule = ActivityTestRule(MainActivity::class.java)
|
||||
private var backStackChangeListener = SimpleFragmentBackStackListener()
|
||||
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
|
@ -38,7 +38,7 @@ class SourceEditorInSingleScreenTest {
|
|||
|
||||
@After
|
||||
fun tearDown() {
|
||||
unfreezeRotation()
|
||||
device.unfreezeRotation()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -55,13 +55,13 @@ class SourceEditorInSingleScreenTest {
|
|||
|
||||
@Test
|
||||
fun previewWithOrientationLeft() {
|
||||
setOrientationLeft()
|
||||
device.setOrientationLeft()
|
||||
previewWithoutOrientation()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun previewWithOrientationRight() {
|
||||
setOrientationRight()
|
||||
device.setOrientationRight()
|
||||
previewWithoutOrientation()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.microsoft.device.display.wm_samples.sourceeditor.utils
|
||||
|
||||
import android.view.View
|
||||
import androidx.test.espresso.UiController
|
||||
import androidx.test.espresso.ViewAction
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isClickable
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isEnabled
|
||||
import org.hamcrest.Matcher
|
||||
import org.hamcrest.Matchers.allOf
|
||||
|
||||
/**
|
||||
* Click action for a view without to check the coordinates for the view on the screen. when device is rotated.
|
||||
*/
|
||||
class ForceClick : ViewAction {
|
||||
override fun getConstraints(): Matcher<View> {
|
||||
return allOf(isClickable(), isEnabled())
|
||||
}
|
||||
|
||||
override fun getDescription(): String {
|
||||
return "force click"
|
||||
}
|
||||
|
||||
override fun perform(uiController: UiController?, view: View?) {
|
||||
view?.performClick()
|
||||
uiController?.loopMainThreadForAtLeast(500)
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.microsoft.device.display.wm_samples.sourceeditor.utils
|
||||
|
||||
import android.view.Surface
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
|
||||
// testing device
|
||||
private val device: UiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
|
||||
private const val leftX: Int = 675 // middle of left screen
|
||||
private const val rightX: Int = 2109 // middle of right screen
|
||||
private const val leftMiddleX: Int = 1340 // left of hinge area
|
||||
private const val rightMiddleX: Int = 1434 // right of hinge area
|
||||
private const val bottomY: Int = 1780 // bottom of screen
|
||||
private const val middleY: Int = 900 // middle of screen
|
||||
private const val spanSteps: Int = 400 // spanning/unspanning swipe
|
||||
private const val switchSteps: Int = 600 // switch from one screen to the other
|
||||
|
||||
fun spanFromLeft() {
|
||||
device.swipe(leftX, bottomY, leftMiddleX, middleY, spanSteps)
|
||||
}
|
||||
|
||||
fun unspanToLeft() {
|
||||
device.swipe(rightX, bottomY, leftX, middleY, spanSteps)
|
||||
}
|
||||
|
||||
fun spanFromRight() {
|
||||
device.swipe(rightX, bottomY, rightMiddleX, middleY, spanSteps)
|
||||
}
|
||||
|
||||
fun unspanToRight() {
|
||||
device.swipe(leftX, bottomY, rightX, middleY, spanSteps)
|
||||
}
|
||||
|
||||
fun moveToLeft() {
|
||||
device.swipe(rightX, bottomY, leftX, middleY, switchSteps)
|
||||
}
|
||||
|
||||
fun moveToRight() {
|
||||
device.swipe(leftX, bottomY, rightX, middleY, switchSteps)
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches application from single screen mode to dual screen mode
|
||||
*/
|
||||
fun switchFromSingleToDualScreen() {
|
||||
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
when (device.displayRotation) {
|
||||
Surface.ROTATION_0, Surface.ROTATION_180 -> device.swipe(675, 1780, 1350, 900, 400)
|
||||
Surface.ROTATION_270 -> device.swipe(1780, 675, 900, 1350, 400)
|
||||
Surface.ROTATION_90 -> device.swipe(1780, 2109, 900, 1400, 400)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches application from dual screen mode to single screen
|
||||
*/
|
||||
fun switchFromDualToSingleScreen() {
|
||||
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
when (device.displayRotation) {
|
||||
Surface.ROTATION_0, Surface.ROTATION_180 -> device.swipe(1500, 1780, 650, 900, 400)
|
||||
Surface.ROTATION_270 -> device.swipe(1780, 1500, 900, 650, 400)
|
||||
Surface.ROTATION_90 -> device.swipe(1780, 1250, 900, 1500, 400)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-enables the sensors and un-freezes the device rotation allowing its contents
|
||||
* to rotate with the device physical rotation. During a test execution, it is best to
|
||||
* keep the device frozen in a specific orientation until the test case execution has completed.
|
||||
*/
|
||||
fun unfreezeRotation() {
|
||||
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
device.unfreezeRotation()
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates orienting the device to the left and also freezes rotation
|
||||
* by disabling the sensors.
|
||||
*/
|
||||
fun setOrientationLeft() {
|
||||
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
device.setOrientationLeft()
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates orienting the device into its natural orientation and also freezes rotation
|
||||
* by disabling the sensors.
|
||||
*/
|
||||
fun setOrientationNatural() {
|
||||
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
device.setOrientationNatural()
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates orienting the device to the right and also freezes rotation
|
||||
* by disabling the sensors.
|
||||
*/
|
||||
fun setOrientationRight() {
|
||||
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
device.setOrientationRight()
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.microsoft.device.display.wm_samples.sourceeditor.utils
|
|||
|
||||
import android.view.View
|
||||
import androidx.test.espresso.ViewAction
|
||||
import com.microsoft.device.dualscreen.testing.ForceClick
|
||||
import org.hamcrest.Matcher
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*/
|
||||
|
||||
ext {
|
||||
gradlePluginVersion = "4.1.1"
|
||||
kotlinVersion = "1.6.0"
|
||||
gradlePluginVersion = "7.1.1"
|
||||
kotlinVersion = "1.6.10"
|
||||
compileSdkVersion = 31
|
||||
buildToolsVersion = '30.0.3'
|
||||
targetSdkVersion = compileSdkVersion
|
||||
|
@ -66,6 +66,7 @@ ext {
|
|||
testRulesVersion = "1.2.0"
|
||||
testRunnerVersion = "1.2.0"
|
||||
uiautomatorVersion = "2.2.0"
|
||||
kotlinTesting = "1.0.0-alpha2"
|
||||
|
||||
instrumentationTestDependencies = [
|
||||
junit : "androidx.test.ext:junit:$junitInstrumentationVersion",
|
||||
|
@ -73,6 +74,7 @@ ext {
|
|||
espressoWeb : "androidx.test.espresso:espresso-web:$espressoWebVersion",
|
||||
testRunner : "androidx.test:runner:$testRunnerVersion",
|
||||
testRules : "androidx.test:rules:$testRulesVersion",
|
||||
uiautomator : "androidx.test.uiautomator:uiautomator:$uiautomatorVersion"
|
||||
uiautomator : "androidx.test.uiautomator:uiautomator:$uiautomatorVersion",
|
||||
kotlinTesting: "com.microsoft.device.dualscreen.testing:testing-kotlin:$kotlinTesting"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
|
|
|
@ -19,13 +19,13 @@ dependencies {
|
|||
task ktlint(type: JavaExec, group: "verification") {
|
||||
description = "Check Kotlin code style."
|
||||
classpath = configurations.ktlint
|
||||
main = "com.pinterest.ktlint.Main"
|
||||
mainClass.set("com.pinterest.ktlint.Main")
|
||||
args "src/**/*.kt"
|
||||
}
|
||||
|
||||
task ktlintFormat(type: JavaExec, group: "formatting") {
|
||||
description = "Fix Kotlin code style deviations."
|
||||
classpath = configurations.ktlint
|
||||
main = "com.pinterest.ktlint.Main"
|
||||
mainClass.set("com.pinterest.ktlint.Main")
|
||||
args "-F", "src/**/*.kt"
|
||||
}
|
||||
|
|
|
@ -63,4 +63,5 @@ dependencies {
|
|||
androidTestImplementation instrumentationTestDependencies.testRunner
|
||||
androidTestImplementation instrumentationTestDependencies.testRules
|
||||
androidTestImplementation instrumentationTestDependencies.uiAutomator
|
||||
androidTestImplementation instrumentationTestDependencies.kotlinTesting
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
|
|||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.ActivityTestRule
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import com.microsoft.device.dualscreen.testing.spanFromStart
|
||||
import org.hamcrest.Matchers.allOf
|
||||
import org.hamcrest.Matchers.hasToString
|
||||
import org.junit.After
|
||||
|
@ -34,7 +35,7 @@ class FragmentNavigationTest {
|
|||
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
|
||||
@get:Rule
|
||||
val activityRule = ActivityTestRule<MainActivity>(MainActivity::class.java)
|
||||
val activityRule = ActivityTestRule(MainActivity::class.java)
|
||||
|
||||
@After
|
||||
fun resetOrientation() {
|
||||
|
@ -107,7 +108,7 @@ class FragmentNavigationTest {
|
|||
}
|
||||
|
||||
private fun spanApplication() {
|
||||
device.swipe(675, 1780, 1350, 900, 400)
|
||||
device.spanFromStart()
|
||||
}
|
||||
|
||||
private fun rotateDevice() {
|
||||
|
|
|
@ -84,6 +84,7 @@ ext {
|
|||
testRulesVersion = "1.2.0"
|
||||
testRunnerVersion = "1.2.0"
|
||||
uiAutomatorVersion = "2.2.0"
|
||||
kotlinTestingVersion = "1.0.0-alpha2"
|
||||
|
||||
instrumentationTestDependencies = [
|
||||
junit : "androidx.test.ext:junit:$junitInstrumentationVersion",
|
||||
|
@ -91,5 +92,6 @@ ext {
|
|||
testRunner : "androidx.test:runner:$testRunnerVersion",
|
||||
testRules : "androidx.test:rules:$testRulesVersion",
|
||||
uiAutomator : "androidx.test.uiautomator:uiautomator:$uiAutomatorVersion",
|
||||
kotlinTesting: "com.microsoft.device.dualscreen.testing:testing-kotlin:$kotlinTestingVersion"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#Wed Jul 28 14:47:59 PDT 2021
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
|
|
@ -22,7 +22,6 @@ android {
|
|||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionName rootProject.ext.inkSDKVersionName
|
||||
|
||||
testInstrumentationRunner rootProject.ext.config.testInstrumentationRunner
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
|
|
Загрузка…
Ссылка в новой задаче