Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[do not merge]: no compose dependencies [skip ci] #879

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
16 changes: 8 additions & 8 deletions espresso-server/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test:${kotlinVersion}")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion")
testImplementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
testImplementation("androidx.compose.ui:ui-test:${composeVersion}")
testImplementation("androidx.compose.ui:ui-test-junit4:${composeVersion}")
// testImplementation("androidx.compose.ui:ui-test:${composeVersion}")
// testImplementation("androidx.compose.ui:ui-test-junit4:${composeVersion}")

androidTestImplementation("androidx.annotation:annotation:${annotationVersion}")
androidTestImplementation("androidx.test.espresso:espresso-contrib:${espressoVersion}") {
Expand All @@ -137,12 +137,12 @@ dependencies {
androidTestImplementation("org.nanohttpd:nanohttpd-webserver:${Version.nanohttpd}")
androidTestImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
androidTestImplementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
androidTestImplementation("androidx.compose.ui:ui-test:${composeVersion}") {
because("Android Compose support")
}
androidTestImplementation("androidx.compose.ui:ui-test-junit4:${composeVersion}") {
because("Android Compose support")
}
// androidTestImplementation("androidx.compose.ui:ui-test:${composeVersion}") {
// because("Android Compose support")
// }
// androidTestImplementation("androidx.compose.ui:ui-test-junit4:${composeVersion}") {
// because("Android Compose support")
// }

// additionalAndroidTestDependencies placeholder (don't change or delete this line)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.junit.Rule
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import androidx.compose.ui.test.junit4.AndroidComposeTestRule

/**
* Instrumentation test, which will execute on an Android device.
Expand All @@ -41,24 +40,6 @@ import androidx.compose.ui.test.junit4.AndroidComposeTestRule
@LargeTest
class EspressoServerRunnerTest {

@get:Rule
val composeRule = AndroidComposeTestRule(
activityRule = EmptyTestRule(),
activityProvider = { error("Can't provide current activity") }
).also {
composeTestRule = it
}

private val syncComposeClock = Thread {
while (!Server.isStopRequestReceived) {
if (context.currentStrategyType == DriverContext.StrategyType.COMPOSE) {
composeTestRule.mainClock.advanceTimeByFrame()
}
// Let Android run measure, draw and in general any other async operations. AndroidComposeTestRule.android.kt:325
Thread.sleep(ANDROID_ASYNC_WAIT_TIME_MS)
}
}

@Test
@Throws(InterruptedException::class, IOException::class, DuplicateRouteException::class)
fun startEspressoServer() {
Expand All @@ -68,13 +49,11 @@ class EspressoServerRunnerTest {
}
try {
Server.start()
syncComposeClock.start()
while (!Server.isStopRequestReceived) {
Thread.sleep(1000)
}
} finally {
Server.stop()
syncComposeClock.join()
}

assertEquals(true, true) // Keep Codacy happy
Expand All @@ -85,7 +64,6 @@ class EspressoServerRunnerTest {
}

companion object {
lateinit var composeTestRule: AndroidComposeTestRule<*, *>
val context = DriverContext()
const val ANDROID_ASYNC_WAIT_TIME_MS = 10L
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@

package io.appium.espressoserver.lib.handlers

import androidx.compose.ui.test.performTextClearance
import androidx.test.espresso.PerformException
import io.appium.espressoserver.lib.handlers.exceptions.InvalidElementStateException
import io.appium.espressoserver.lib.model.AppiumParams
import io.appium.espressoserver.lib.model.EspressoElement

import androidx.test.espresso.action.ViewActions.clearText
import io.appium.espressoserver.lib.handlers.exceptions.StaleElementException
import io.appium.espressoserver.lib.helpers.getNodeInteractionById

class Clear : RequestHandler<AppiumParams, Unit> {

Expand All @@ -36,14 +33,4 @@ class Clear : RequestHandler<AppiumParams, Unit> {
throw InvalidElementStateException("clear", params.elementId!!, e)
}
}

override fun handleCompose(params: AppiumParams) {
try {
getNodeInteractionById(params.elementId).performTextClearance()
} catch (e: AssertionError) {
throw StaleElementException(params.elementId!!)
} catch (e: IllegalArgumentException) {
throw InvalidElementStateException("Clear", params.elementId!!, e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@

package io.appium.espressoserver.lib.handlers

import androidx.compose.ui.test.performClick
import androidx.test.espresso.PerformException
import io.appium.espressoserver.lib.handlers.exceptions.InvalidElementStateException
import io.appium.espressoserver.lib.model.AppiumParams
import io.appium.espressoserver.lib.model.EspressoElement

import androidx.test.espresso.action.ViewActions.click
import io.appium.espressoserver.lib.handlers.exceptions.StaleElementException
import io.appium.espressoserver.lib.helpers.getNodeInteractionById

class Click : RequestHandler<AppiumParams, Unit> {

Expand All @@ -36,14 +33,4 @@ class Click : RequestHandler<AppiumParams, Unit> {
throw InvalidElementStateException("click", params.elementId!!, e)
}
}

override fun handleCompose(params: AppiumParams) {
try {
getNodeInteractionById(params.elementId).performClick()
} catch (e: AssertionError) {
throw StaleElementException(params.elementId!!)
} catch (e: IllegalArgumentException) {
throw InvalidElementStateException("Click", params.elementId!!, e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package io.appium.espressoserver.lib.handlers

import io.appium.espressoserver.lib.helpers.getNodeInteractionById
import io.appium.espressoserver.lib.helpers.takeComposeNodeScreenshot
import io.appium.espressoserver.lib.helpers.takeEspressoViewScreenshot
import io.appium.espressoserver.lib.model.AppiumParams
import io.appium.espressoserver.lib.model.EspressoElement
Expand All @@ -26,7 +24,4 @@ class ElementScreenshot : RequestHandler<AppiumParams, String> {

override fun handleEspresso(params: AppiumParams): String =
takeEspressoViewScreenshot(EspressoElement.getCachedViewStateById(params.elementId).view)

override fun handleCompose(params: AppiumParams): String =
takeComposeNodeScreenshot(getNodeInteractionById(params.elementId!!))
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package io.appium.espressoserver.lib.handlers

import android.widget.NumberPicker
import android.widget.ProgressBar
import androidx.compose.ui.test.performTextClearance
import androidx.compose.ui.test.performTextInput
import androidx.test.espresso.PerformException

import io.appium.espressoserver.lib.handlers.exceptions.InvalidArgumentException
Expand All @@ -30,7 +28,6 @@ import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.action.ViewActions.typeText
import io.appium.espressoserver.lib.handlers.exceptions.InvalidElementStateException
import io.appium.espressoserver.lib.helpers.AndroidLogger
import io.appium.espressoserver.lib.helpers.getNodeInteractionById
import io.appium.espressoserver.lib.viewaction.ViewTextGetter

class ElementValue(private val isReplacing: Boolean) : RequestHandler<TextValueParams, Unit> {
Expand Down Expand Up @@ -76,18 +73,6 @@ class ElementValue(private val isReplacing: Boolean) : RequestHandler<TextValueP
}
}

override fun handleCompose(params: TextValueParams) {
val value: String = extractTextToEnter(params)
try {
if (isReplacing) {
getNodeInteractionById(params.elementId).performTextClearance()
}
getNodeInteractionById(params.elementId).performTextInput(value)
} catch (e: IllegalArgumentException) {
throw InvalidElementStateException("Clear", params.elementId!!, e)
}
}

private fun extractTextToEnter(params: TextValueParams) =
when (Pair(params.value == null, params.text == null)) {
Pair(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package io.appium.espressoserver.lib.handlers
import io.appium.espressoserver.lib.handlers.exceptions.*
import io.appium.espressoserver.lib.helpers.*
import io.appium.espressoserver.lib.model.BaseElement
import io.appium.espressoserver.lib.model.ComposeElement
import io.appium.espressoserver.lib.model.EspressoElement
import io.appium.espressoserver.lib.model.Locator
import io.appium.espressoserver.lib.viewaction.ViewGetter
Expand All @@ -46,15 +45,4 @@ class FindElement : RequestHandler<Locator, BaseElement> {
// If we have a match, return success
return EspressoElement(viewState)
}

override fun handleCompose(params: Locator): BaseElement {
val nodeInteractions = toNodeInteractionsCollection(params)
if (nodeInteractions.fetchSemanticsNodes(false).isEmpty()) throw NoSuchElementException(
String.format(
"Could not find a compose element with strategy '%s' and selector '%s'",
params.using, params.value
)
)
return ComposeElement(nodeInteractions[0])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import io.appium.espressoserver.lib.handlers.exceptions.InvalidArgumentException
import io.appium.espressoserver.lib.handlers.exceptions.InvalidSelectorException
import io.appium.espressoserver.lib.helpers.*
import io.appium.espressoserver.lib.model.BaseElement
import io.appium.espressoserver.lib.model.ComposeElement
import io.appium.espressoserver.lib.model.EspressoElement
import io.appium.espressoserver.lib.model.Locator
import io.appium.espressoserver.lib.viewaction.ViewGetter
Expand All @@ -39,10 +38,4 @@ class FindElements : RequestHandler<Locator, List<BaseElement>> {
params.value ?: throw InvalidArgumentException()
).map { EspressoElement(it) }
}

override fun handleCompose(params: Locator): List<BaseElement> {
val nodeInteractions = toNodeInteractionsCollection(params)
return List(nodeInteractions.fetchSemanticsNodes(false).size)
{ index -> ComposeElement(nodeInteractions[index]) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import io.appium.espressoserver.lib.drivers.DriverContext
import io.appium.espressoserver.lib.handlers.exceptions.AppiumException
import io.appium.espressoserver.lib.handlers.exceptions.NotYetImplementedException
import io.appium.espressoserver.lib.helpers.AndroidLogger
import io.appium.espressoserver.lib.helpers.getSemanticsNode
import io.appium.espressoserver.lib.model.*
import io.appium.espressoserver.lib.viewaction.ViewTextGetter

Expand All @@ -39,15 +38,7 @@ class GetAttribute : RequestHandler<AppiumParams, String?> {
throw AppiumException("Attribute name cannot be null or empty")
}

return when (EspressoServerRunnerTest.context.currentStrategyType) {
DriverContext.StrategyType.COMPOSE -> getComposeAttribute(params.elementId!!, attributeName)
DriverContext.StrategyType.ESPRESSO -> getEspressoAttribute(params.elementId!!, attributeName)
}
}


private fun getComposeAttribute(elementId: String, attributeName: String): String? {
return ComposeNodeElement(getSemanticsNode(elementId)).getAttribute(attributeName)
return getEspressoAttribute(params.elementId!!, attributeName)
}

private fun getEspressoAttribute(elementId: String, attributeName: String): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package io.appium.espressoserver.lib.handlers

import androidx.compose.ui.test.assertIsDisplayed
import io.appium.espressoserver.lib.helpers.getNodeInteractionById
import io.appium.espressoserver.lib.model.AppiumParams
import io.appium.espressoserver.lib.model.EspressoElement
import io.appium.espressoserver.lib.model.ViewElement
Expand All @@ -26,13 +24,5 @@ class GetDisplayed : RequestHandler<AppiumParams, Boolean> {

override fun handleEspresso(params: AppiumParams): Boolean =
ViewElement(EspressoElement.getCachedViewStateById(params.elementId, false).view).isVisible

override fun handleCompose(params: AppiumParams): Boolean =
try {
getNodeInteractionById(params.elementId).assertIsDisplayed()
true
} catch (e: AssertionError) {
false
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@

package io.appium.espressoserver.lib.handlers

import io.appium.espressoserver.lib.helpers.getSemanticsNode
import io.appium.espressoserver.lib.model.AppiumParams
import io.appium.espressoserver.lib.model.ViewElement
import io.appium.espressoserver.lib.model.EspressoElement
import io.appium.espressoserver.lib.model.ComposeNodeElement

class GetEnabled : RequestHandler<AppiumParams, Boolean> {

override fun handleEspresso(params: AppiumParams): Boolean =
ViewElement(EspressoElement.getCachedViewStateById(params.elementId).view).isEnabled

override fun handleCompose(params: AppiumParams): Boolean =
ComposeNodeElement(getSemanticsNode(params.elementId!!)).isEnabled
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,15 @@

package io.appium.espressoserver.lib.handlers

import io.appium.espressoserver.lib.helpers.getSemanticsNode
import io.appium.espressoserver.lib.model.AppiumParams
import io.appium.espressoserver.lib.model.Location
import io.appium.espressoserver.lib.model.ViewElement
import io.appium.espressoserver.lib.model.EspressoElement
import io.appium.espressoserver.lib.model.ComposeNodeElement

class GetLocation : RequestHandler<AppiumParams, Location> {

override fun handleEspresso(params: AppiumParams): Location {
val viewElement = ViewElement(EspressoElement.getCachedViewStateById(params.elementId).view)
return Location(viewElement.bounds.left, viewElement.bounds.top)
}

override fun handleCompose(params: AppiumParams): Location {
val composeNodeElement = ComposeNodeElement(getSemanticsNode(params.elementId!!))
return Location(composeNodeElement.bounds.left, composeNodeElement.bounds.top)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@

package io.appium.espressoserver.lib.handlers

import io.appium.espressoserver.lib.helpers.getSemanticsNode
import io.appium.espressoserver.lib.model.AppiumParams
import io.appium.espressoserver.lib.model.ViewElement
import io.appium.espressoserver.lib.model.EspressoElement
import io.appium.espressoserver.lib.model.ComposeNodeElement

class GetName : RequestHandler<AppiumParams, String?> {

override fun handleEspresso(params: AppiumParams): String? {
val viewState = EspressoElement.getCachedViewStateById(params.elementId)
return ViewElement(viewState.view).contentDescription?.toString()
}

override fun handleCompose(params: AppiumParams): String? {
val composeNodeElement = ComposeNodeElement(getSemanticsNode(params.elementId!!))
return composeNodeElement.contentDescription?.toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package io.appium.espressoserver.lib.handlers

import io.appium.espressoserver.lib.helpers.getSemanticsNode
import io.appium.espressoserver.lib.model.AppiumParams
import io.appium.espressoserver.lib.model.ComposeNodeElement
import io.appium.espressoserver.lib.model.EspressoElement
import io.appium.espressoserver.lib.model.Rect
import io.appium.espressoserver.lib.model.ViewElement
Expand All @@ -27,7 +25,4 @@ class GetRect : RequestHandler<AppiumParams, Rect> {

override fun handleEspresso(params: AppiumParams): Rect =
ViewElement(EspressoElement.getCachedViewStateById(params.elementId).view).rect

override fun handleCompose(params: AppiumParams): Rect =
ComposeNodeElement(getSemanticsNode(params.elementId!!)).rect
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package io.appium.espressoserver.lib.handlers

import io.appium.espressoserver.lib.helpers.getSemanticsNode
import io.appium.espressoserver.lib.model.AppiumParams
import io.appium.espressoserver.lib.model.ComposeNodeElement
import io.appium.espressoserver.lib.model.EspressoElement

import io.appium.espressoserver.lib.model.ViewElement
Expand All @@ -27,7 +25,4 @@ class GetSelected : RequestHandler<AppiumParams, Boolean> {

override fun handleEspresso(params: AppiumParams): Boolean =
ViewElement(EspressoElement.getCachedViewStateById(params.elementId).view).isSelected

override fun handleCompose(params: AppiumParams): Boolean =
ComposeNodeElement(getSemanticsNode(params.elementId!!)).isSelected
}
Loading
Loading