Skip to content

Commit

Permalink
#50 meta info (#57)
Browse files Browse the repository at this point in the history
* meta info for espresso, espresso web, uiautomator and compose
  • Loading branch information
alex-tiurin committed Oct 29, 2023
1 parent 4560ccc commit 5e1a4fc
Show file tree
Hide file tree
Showing 68 changed files with 1,669 additions and 918 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.atiurin.sampleapp.framework

data class DummyMetaObject(val value: String)
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.atiurin.ultron.extensions.getDescription
fun hasProgress(value: Float) = SemanticsMatcher.expectValue(GetProgress, value)
fun UltronComposeSemanticsNodeInteraction.assertProgress(expected: Float) = perform (
UltronComposeOperationParams(
operationName = "Assert '${semanticsNodeInteraction.getDescription()}' has progress $expected",
operationDescription = "Compose assertProgress = $expected in '${semanticsNodeInteraction.getDescription()}' during $timeoutMs ms"
operationName = "Assert '${elementInfo.name}' has progress $expected",
operationDescription = "Compose assertProgress = $expected in '${elementInfo.name}' during $timeoutMs ms"
)
) {
semanticsNodeInteraction.assert(hasProgress(expected))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ fun UltronWebElement.appendText(text: String) = apply {
webInteractionBlock = {
webInteractionBlock().perform(DriverAtoms.webKeys(text))
},
name = "WebElement(${locator.type} = '$value') appendText '$text'",
description = "WebElement(${locator.type} = '$value') appendText '$text' during $timeoutMs ms"
name = "${elementInfo.name} appendText '$text'",
description = "${elementInfo.name} appendText '$text' during $timeoutMs ms"
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.atiurin.ultron.core.uiautomator.uiobject2.UltronUiObject2
fun UltronUiObject2.appendText(appendText: String) = apply {
executeAction(
actionBlock = { uiObject2ProviderBlock()!!.text += appendText },
name = "AppendText '$appendText' to $selectorDesc",
description = "UiObject2 action '${UiAutomatorActionType.ADD_TEXT}' $selectorDesc appendText '$appendText' during $timeoutMs ms"
name = "AppendText '$appendText' to ${elementInfo.name}",
description = "UiObject2 action '${UiAutomatorActionType.ADD_TEXT}' ${elementInfo.name} appendText '$appendText' during $timeoutMs ms"
)
}

Expand All @@ -21,8 +21,8 @@ enum class CustomUltronOperations : UltronOperationType {
fun UltronUiObject2.assertHasAnyChild() = apply {
executeAssertion(
assertionBlock = { uiObject2ProviderBlock()!!.childCount > 0 },
name = "Assert $selectorDesc has any child",
name = "Assert ${elementInfo.name} has any child",
type = CustomUltronOperations.ASSERT_HAS_ANY_CHILD,
description = "UiObject2 assertion '${CustomUltronOperations.ASSERT_HAS_ANY_CHILD}' of $selectorDesc during $timeoutMs ms"
description = "UiObject2 assertion '${CustomUltronOperations.ASSERT_HAS_ANY_CHILD}' of ${elementInfo.name} during $timeoutMs ms"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ object ComposeElementsPage : Page<ComposeElementsPage>() {
val progressBar = hasTestTag(ComposeElementsActivity.progressBar)
val maleRadioButton = hasTestTag(radioButtonMaleTestTag)
val femaleRadioButton = hasTestTag(radioButtonFemaleTestTag)
val notExistedElement = hasTestTag("NotExistedTestTag")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ class WebViewPage : Page<WebViewPage>() {
val titleWithCss = className("css_title")
val appleLink = id("apple_link")
val buttons = classNames("button")
val notExistedElement = id("Not existed element")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.atiurin.sampleapp.tests.compose

import com.atiurin.sampleapp.activity.ComposeElementsActivity
import com.atiurin.sampleapp.framework.DummyMetaObject
import com.atiurin.sampleapp.framework.utils.AssertUtils
import com.atiurin.sampleapp.pages.ComposeElementsPage
import com.atiurin.ultron.core.compose.config.UltronComposeConfig
Expand Down Expand Up @@ -74,4 +75,39 @@ class ComposeConfigTest {
fun isSuccess_true() {
Assert.assertTrue(page.editableText.isSuccess { assertExists() })
}


@Test
fun withName_inOperationProps_ultronInteraction() {
val name = "ElementName"
page.notExistedElement.withTimeout(100).withName(name).withResultHandler { result ->
Assert.assertEquals(name, result.operation.elementInfo.name)
}.assertIsDisplayed()
}

@Test
fun withName_inOperationProps_matcherExt() {
val name = "ElementName"
page.notExistedElement.withName(name).withTimeout(100).withResultHandler { result ->
Assert.assertEquals(name, result.operation.elementInfo.name)
}.assertIsDisplayed()
}

@Test
fun withName_inExceptionMessage() {
val name = "ElementNameToBeInException"
runCatching {
page.notExistedElement.withTimeout(100).withName(name).assertIsDisplayed()
}.onFailure { exception ->
Assert.assertTrue(exception.message!!.contains(name))
}
}

@Test
fun withMeta() {
val meta = DummyMetaObject("ElementMetaInfo")
page.notExistedElement.withTimeout(100).withMetaInfo(meta).withResultHandler { result ->
Assert.assertEquals(meta, result.operation.elementInfo.meta)
}.assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.atiurin.sampleapp.tests.espresso

import androidx.test.espresso.matcher.ViewMatchers
import com.atiurin.sampleapp.framework.DummyMetaObject
import com.atiurin.sampleapp.framework.Log
import com.atiurin.sampleapp.framework.utils.AssertUtils
import com.atiurin.sampleapp.pages.UiElementsPage
Expand All @@ -10,7 +12,11 @@ import com.atiurin.ultron.core.espresso.EspressoOperationResult
import com.atiurin.ultron.core.espresso.UltronEspressoOperation
import com.atiurin.ultron.exceptions.UltronException
import com.atiurin.ultron.extensions.click
import com.atiurin.ultron.extensions.hasText
import com.atiurin.ultron.extensions.isDisplayed
import com.atiurin.ultron.extensions.isSuccess
import com.atiurin.ultron.extensions.withAssertion
import com.atiurin.ultron.extensions.withName
import com.atiurin.ultron.extensions.withResultHandler
import com.atiurin.ultron.extensions.withTimeout
import com.atiurin.ultron.testlifecycle.setupteardown.SetUp
Expand All @@ -19,6 +25,7 @@ import com.atiurin.ultron.testlifecycle.setupteardown.TearDown
import com.atiurin.ultron.testlifecycle.setupteardown.TearDownRule
import org.junit.Assert
import org.junit.Test
import kotlin.system.measureTimeMillis

class UltronEspressoConfigTest : UiElementsTest() {
val page = UiElementsPage
Expand Down Expand Up @@ -171,4 +178,72 @@ class UltronEspressoConfigTest : UiElementsTest() {
Assert.assertFalse(result!!.operation.description.isNullOrEmpty())
Assert.assertEquals(100, result!!.operation.timeoutMs)
}


@Test
fun customAssertionTest() {
val text = "some text"
val execTime = measureTimeMillis {
page.editTextContentDesc.withAssertion("demo name") {
page.editTextContentDesc.hasText(text)
}.replaceText(text)
}
Assert.assertTrue(execTime < UltronConfig.Espresso.ACTION_TIMEOUT)
}

@Test
fun withAssertion_failedAssertion() {
AssertUtils.assertException {
page.editTextContentDesc.withTimeout(1000).withAssertion {
ViewMatchers.withText("asd23213 12312").withTimeout(500).isDisplayed()
}.typeText("1")
}
}

@Test
fun withAssertion_failedAssertion_timeout() {
val operationTime = 1000L
val execTime = measureTimeMillis {
page.editTextContentDesc.isSuccess {
withTimeout(operationTime).withAssertion {
ViewMatchers.withText("asd23213 12312").withTimeout(100).isDisplayed()
}.typeText("1")
}
}
Assert.assertTrue(execTime > operationTime)
}

@Test
fun withName_inOperationProps_ultronInteraction() {
val name = "ElementName"
page.notExistElement.withTimeout(100).withName(name).withResultHandler { result ->
Assert.assertEquals(name, result.operation.elementInfo.name)
}.isDisplayed()
}

@Test
fun withName_inOperationProps_matcherExt() {
val name = "ElementName"
page.notExistElement.withName(name).withTimeout(100).withResultHandler { result ->
Assert.assertEquals(name, result.operation.elementInfo.name)
}.isDisplayed()
}

@Test
fun withName_inExceptionMessage() {
val name = "ElementNameToBeInException"
runCatching {
page.notExistElement.withTimeout(100).withName(name).isDisplayed()
}.onFailure { exception ->
Assert.assertTrue(exception.message!!.contains(name))
}
}

@Test
fun withMeta() {
val meta = DummyMetaObject("ElementMetaInfo")
page.notExistElement.withTimeout(100).withMetaInfo(meta).withResultHandler { result ->
Assert.assertEquals(meta, result.operation.elementInfo.meta)
}.isDisplayed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.atiurin.ultron.custom.espresso.action.getText
import com.atiurin.ultron.custom.espresso.assertion.hasAnyDrawable
import com.atiurin.ultron.custom.espresso.assertion.hasDrawable
import com.atiurin.ultron.extensions.*
import com.atiurin.ultron.log.UltronLog
import com.atiurin.ultron.utils.getTargetString
import org.junit.Assert
import org.junit.Test
Expand Down Expand Up @@ -71,7 +72,9 @@ class ViewInteractionActionsTest : UiElementsTest() {
var success = false
with(page.eventStatus) {
textContains(getResourceString(R.string.button_event_click))
success = isSuccess { withTimeout(3000).textContains("1") } || isSuccess { withTimeout(2000).textContains("2") }
success = isSuccess { withTimeout(3000).textContains("1") } || isSuccess {
withTimeout(2000).textContains("2")
}
}
Assert.assertTrue(success)
}
Expand Down Expand Up @@ -135,7 +138,9 @@ class ViewInteractionActionsTest : UiElementsTest() {

@Test
fun pressKey_notExisted() {
AssertUtils.assertException { page.notExistElement.withTimeout(100).pressKey(KeyEvent.KEYCODE_DEL) }
AssertUtils.assertException {
page.notExistElement.withTimeout(100).pressKey(KeyEvent.KEYCODE_DEL)
}
}

@Test
Expand All @@ -151,7 +156,10 @@ class ViewInteractionActionsTest : UiElementsTest() {

@Test
fun pressEspressoKey_notExisted() {
AssertUtils.assertException { page.notExistElement.withTimeout(100).pressKey(EspressoKey.Builder().withKeyCode(KeyEvent.KEYCODE_DEL).build()) }
AssertUtils.assertException {
page.notExistElement.withTimeout(100)
.pressKey(EspressoKey.Builder().withKeyCode(KeyEvent.KEYCODE_DEL).build())
}
}

@Test
Expand Down Expand Up @@ -229,7 +237,9 @@ class ViewInteractionActionsTest : UiElementsTest() {

@Test
fun hasAnyDrawable_noDrawable() {
AssertUtils.assertException { page.emptyNotClickableImageView.withTimeout(1000).hasAnyDrawable() }
AssertUtils.assertException {
page.emptyNotClickableImageView.withTimeout(1000).hasAnyDrawable()
}
}

@Test
Expand All @@ -244,39 +254,10 @@ class ViewInteractionActionsTest : UiElementsTest() {

@Test
fun getContentDesc_descNotNull() {
Assert.assertEquals(getTargetString(R.string.button_default_content_desc), page.button.getContentDescription())
}

@Test
fun customAssertionTest() {
val text = "some text"
val execTime = measureTimeMillis {
page.editTextContentDesc.withAssertion("demo name") {
page.editTextContentDesc.hasText(text)
}.replaceText(text)
}
Assert.assertTrue(execTime < UltronConfig.Espresso.ACTION_TIMEOUT)
}

@Test
fun withAssertion_failedAssertion() {
AssertUtils.assertException {
page.editTextContentDesc.withTimeout(1000).withAssertion {
withText("asd23213 12312").withTimeout(500).isDisplayed()
}.typeText("1")
}
Assert.assertEquals(
getTargetString(R.string.button_default_content_desc),
page.button.getContentDescription()
)
}

@Test
fun withAssertion_failedAssertion_timeout() {
val operationTime = 1000L
val execTime = measureTimeMillis {
page.editTextContentDesc.isSuccess {
withTimeout(operationTime).withAssertion {
withText("asd23213 12312").withTimeout(100).isDisplayed()
}.typeText("1")
}
}
Assert.assertTrue(execTime > operationTime)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package com.atiurin.sampleapp.tests.espresso_web

import androidx.test.espresso.web.assertion.WebViewAssertions.webMatches
import androidx.test.espresso.web.webdriver.DriverAtoms.getText
import com.atiurin.sampleapp.framework.DummyMetaObject
import com.atiurin.sampleapp.framework.ultronext.appendText
import com.atiurin.sampleapp.framework.utils.AssertUtils
import com.atiurin.sampleapp.pages.WebViewPage
import com.atiurin.ultron.core.espressoweb.webelement.UltronWebElement.Companion.className
import com.atiurin.ultron.core.espressoweb.webelement.UltronWebElement.Companion.id
import com.atiurin.ultron.core.espressoweb.webelement.UltronWebElement.Companion.xpath
import com.atiurin.ultron.extensions.withName
import com.atiurin.ultron.extensions.withTimeout
import org.hamcrest.Matchers.`is`
import org.junit.Assert
import org.junit.Test
Expand All @@ -20,7 +24,7 @@ class UltronWebElementTest : BaseWebViewTest() {

@Test
fun webClick_onNotExistedElement() {
AssertUtils.assertException { id("notExistId").withTimeout(100).webClick() }
AssertUtils.assertException { xpath("notExistId").withTimeout(100).withName("Custome name").webClick() }
}

@Test
Expand Down Expand Up @@ -222,4 +226,39 @@ class UltronWebElementTest : BaseWebViewTest() {
}.webClick()
}
}


@Test
fun withName_inOperationProps_ultronInteraction() {
val name = "ElementName"
page.notExistedElement.withTimeout(100).withName(name).withResultHandler { result ->
Assert.assertEquals(name, result.operation.elementInfo.name)
}.exists()
}

@Test
fun withName_inOperationProps_matcherExt() {
val name = "ElementName"
page.notExistedElement.withName(name).withTimeout(100).withResultHandler { result ->
Assert.assertEquals(name, result.operation.elementInfo.name)
}.exists()
}

@Test
fun withName_inExceptionMessage() {
val name = "ElementNameToBeInException"
runCatching {
page.notExistedElement.withTimeout(100).withName(name).exists()
}.onFailure { exception ->
Assert.assertTrue(exception.message!!.contains(name))
}
}

@Test
fun withMeta() {
val meta = DummyMetaObject("ElementMetaInfo")
page.notExistedElement.withTimeout(100).withMetaInfo(meta).withResultHandler { result ->
Assert.assertEquals(meta, result.operation.elementInfo.meta)
}.exists()
}
}

0 comments on commit 5e1a4fc

Please sign in to comment.