1
0
Форкнуть 0

Fix PhotoEditor drag&drop UI test (#38)

* Update dependencies

* Add "Files" package to android manifest

So the launch intent for the Files package can be accessed (https://developer.android.com/training/package-visibility)

* Use target context and different intent flag

* Use test kit coordinates instead of hardcoding
This commit is contained in:
Kristen Halper 2022-05-02 09:00:35 -04:00 коммит произвёл GitHub
Родитель 188efc5a2e
Коммит b4ace80301
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 28 добавлений и 17 удалений

Просмотреть файл

@ -24,6 +24,7 @@ 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.getDeviceModel
import com.microsoft.device.dualscreen.testing.spanFromStart
import org.hamcrest.CoreMatchers.not
import org.junit.Rule
@ -77,6 +78,8 @@ class PhotoEditorUITest {
*
* @precondition device in portrait mode, no other applications are open
* (so app by default opens on left screen)
* For Android 11 devices, the most recently downloaded file must also be an image for the test to pass,
* because the "Downloads" section opens by default instead of the "Recent" section
*/
@Test
fun testDragAndDrop() {
@ -99,11 +102,11 @@ class PhotoEditorUITest {
}
// Open Files app
val context = InstrumentationRegistry.getInstrumentation().context
val intent = context.packageManager.getLaunchIntentForPackage(filesPackage)?.apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
val targetContext = InstrumentationRegistry.getInstrumentation().targetContext
val intent = targetContext.packageManager.getLaunchIntentForPackage(filesPackage)?.apply {
addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT)
}
context.startActivity(intent)
targetContext.startActivity(intent)
device.wait(Until.hasObject(By.pkg(filesPackage).depth(0)), 3000) // timeout at 3 seconds
// Before import, drawable is equal to prev
@ -112,11 +115,17 @@ class PhotoEditorUITest {
iz(activityRule.activity.findViewById<ImageFilterView>(R.id.image).drawable)
)
// Hardcoded to select most recently saved file in Files app - must be an image file
device.swipe(1550, 1230, 1550, 1230, 100)
// Calculate start and end coordinates based on device model
val model = device.getDeviceModel()
val fileOffsetX = model.middleX + 200
val fileOffsetY = model.middleY - 200
val dropTargetX = model.paneWidth - 100
// Long press most recently saved/downloaded file in Files app - must be an image file
device.swipe(fileOffsetX, fileOffsetY, fileOffsetX, fileOffsetY, 100)
// Slowly drag selected image file to other screen for import
device.swipe(1550, 1230, 1200, 1100, 600)
device.swipe(fileOffsetX, fileOffsetY, dropTargetX, fileOffsetY, 500)
// After import, drawable has changed
onIdle()

Просмотреть файл

@ -29,6 +29,8 @@
android:exported="true">
</activity>
</application>
<queries>
<package android:name="com.google.android.documentsui" />
</queries>
</manifest>

Просмотреть файл

@ -22,12 +22,12 @@ ext {
]
//AndroidX versions
appCompatVersion = "1.2.0"
constraintLayoutVersion = "2.1.2"
appCompatVersion = '1.4.1'
constraintLayoutVersion = '2.1.3'
recyclerViewVersion = "1.1.0"
cardViewVersion = "1.0.0"
ktxCoreVersion = "1.5.0"
ktxFragmentVersion = "1.3.6"
ktxFragmentVersion = '1.4.1'
viewPager2Version = "1.0.0"
windowManagerVersion = "1.0.0"
@ -43,24 +43,24 @@ ext {
]
//Google dependencies
materialVersion = "1.3.0"
materialVersion = '1.5.0'
googleDependencies = [
material: "com.google.android.material:material:$materialVersion"
]
//Test dependencies version
junitVersion = "4.13"
junitVersion = '4.13.2'
testDependencies = [
junit: "junit:junit:$junitVersion"
]
//Android test dependencies version
junitInstrumentationVersion = "1.1.1"
espressoCoreVersion = "3.2.0"
testRunnerVersion = "1.2.0"
testRulesVersion = "1.2.0"
junitInstrumentationVersion = '1.1.3'
espressoCoreVersion = '3.4.0'
testRunnerVersion = '1.4.0'
testRulesVersion = '1.4.0'
uiautomatorVersion = "2.2.0"
kotlinTestingVersion = "1.0.0-alpha2"