Skip to content

Commit

Permalink
2.0.4
Browse files Browse the repository at this point in the history
- textView color matchers
  • Loading branch information
alex-tiurin committed Dec 30, 2022
1 parent c860bcd commit 0bca22f
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 134 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ kotlin.code.style=official
android.useAndroidX=true
GROUP=com.atiurin
POM_ARTIFACT_ID=ultron
VERSION_NAME=2.0.3
VERSION_NAME=2.0.4

POM_NAME=ultron
POM_PACKAGING=aar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ import com.atiurin.ultron.extensions.getDescription

fun hasProgress(value: Float): SemanticsMatcher = SemanticsMatcher.expectValue(GetProgress, value)

enum class ComposeOperationTypeExt : UltronOperationType { ASSERT_PROGRESS }

fun UltronComposeSemanticsNodeInteraction.assertProgress(expected: Float) = apply {
executeOperation(
operationBlock = { semanticsNodeInteraction.assert(hasProgress(expected)) },
name = "Assert '${semanticsNodeInteraction.getDescription()}' has progress $expected",
type = ComposeOperationTypeExt.ASSERT_PROGRESS, //it's not required, you can skip this param. DEFAULT one will be used
description = "Compose assertProgress = $expected in '${semanticsNodeInteraction.getDescription()}' during $timeoutMs ms",
description = "Compose assertProgress = $expected in '${semanticsNodeInteraction.getDescription()}' during $timeoutMs ms"
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.atiurin.sampleapp.framework.ultronext

import com.atiurin.ultron.core.common.UltronOperationType
import com.atiurin.ultron.core.uiautomator.UiAutomatorActionType
import com.atiurin.ultron.core.uiautomator.uiobject2.UltronUiObject2

Expand All @@ -11,4 +12,17 @@ fun UltronUiObject2.appendText(appendText: String) = apply {
name = "AppendText '$appendText' to $selectorDesc",
description = "UiObject2 action '${UiAutomatorActionType.ADD_TEXT}' $selectorDesc appendText '$appendText' during $timeoutMs ms"
)
}
}

enum class CustomUltronOperations : UltronOperationType {
ADD_TEXT_PREFIX, ASSERT_HAS_ANY_CHILD
}
// add extension function to UltronUiObject2 that calls `executeAssertion`
fun UltronUiObject2.assertHasAnyChild() = apply {
executeAssertion(
assertionBlock = { uiObject2ProviderBlock()!!.childCount > 0 },
name = "Assert $selectorDesc has any child",
type = CustomUltronOperations.ASSERT_HAS_ANY_CHILD,
description = "UiObject2 assertion '${CustomUltronOperations.ASSERT_HAS_ANY_CHILD}' of $selectorDesc during $timeoutMs ms"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import com.atiurin.ultron.core.common.options.TextContainsOption
import com.atiurin.ultron.core.common.options.TextEqualsOption
import com.atiurin.ultron.core.compose.createUltronComposeRule
import com.atiurin.ultron.core.compose.nodeinteraction.click
import com.atiurin.ultron.core.compose.operation.ComposeOperationResult
import com.atiurin.ultron.core.compose.operation.ComposeOperationType
import com.atiurin.ultron.core.compose.operation.UltronComposeOperation
import com.atiurin.ultron.core.compose.option.ComposeSwipeOption
import com.atiurin.ultron.extensions.*
import org.junit.Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ class ViewInteractionActionsTest : UiElementsTest() {
val text = "some text"
val execTime = measureTimeMillis {
page.editTextContentDesc.withAssertion("demo name") {
executeWithoutListeners {
page.editTextContentDesc.hasText(text)
}
page.editTextContentDesc.hasText(text)
}.replaceText(text)
}
Assert.assertTrue(execTime < UltronConfig.Espresso.ACTION_TIMEOUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import com.atiurin.sampleapp.framework.utils.AssertUtils
import com.atiurin.sampleapp.framework.utils.TestDataUtils.getResourceString
import com.atiurin.sampleapp.pages.UiElementsPage
import com.atiurin.sampleapp.tests.UiElementsTest
import com.atiurin.ultron.custom.espresso.assertion.hasCurrentHintTextColor
import com.atiurin.ultron.custom.espresso.assertion.hasCurrentTextColor
import com.atiurin.ultron.custom.espresso.assertion.hasHighlightColor
import com.atiurin.ultron.custom.espresso.assertion.hasShadowColor
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.containsString
import org.junit.Assert
Expand Down Expand Up @@ -43,23 +47,23 @@ class ViewInteractionAssertionsTest : UiElementsTest() {

//doesNotExist
@Test
fun doesNotExist_notExisted(){
fun doesNotExist_notExisted() {
page.notExistElement.doesNotExist()
}

@Test
fun doesNotExist_existed(){
fun doesNotExist_existed() {
AssertUtils.assertException { page.button.withTimeout(100).doesNotExist() }
}

//exists
@Test
fun exists_ExistedHiddenView(){
fun exists_ExistedHiddenView() {
page.hiddenButton.exists()
}

@Test
fun exists_NotExisted(){
fun exists_NotExisted() {
AssertUtils.assertException { page.notExistElement.withTimeout(100).exists() }
}

Expand Down Expand Up @@ -390,5 +394,62 @@ class ViewInteractionAssertionsTest : UiElementsTest() {
}
}

@Test
fun hasCurrentTextColor() {
page.eventStatus.hasCurrentTextColor(R.color.colorPrimary)
}

@Test
fun hasCurrentTextColor_invalidColor() {
AssertUtils.assertException { page.eventStatus.withTimeout(100).hasCurrentTextColor(R.color.invalid) }
}

@Test
fun hasCurrentHintTextColor() {
page.eventStatus.hasCurrentHintTextColor(R.color.colorHint)
}

@Test
fun hasCurrentHintTextColor_invalidColor() {
AssertUtils.assertException { page.eventStatus.withTimeout(100).hasCurrentHintTextColor(R.color.invalid) }
}

@Test
fun hasShadowColor() {
page.eventStatus.hasShadowColor(R.color.colorShadow)
}

@Test
fun hasShadowColor_invalidColor() {
AssertUtils.assertException { page.eventStatus.withTimeout(100).hasShadowColor(R.color.invalid) }
}

@Test
fun hasHighlightColor() {
page.eventStatus.hasHighlightColor(R.color.colorHighlight)
}

@Test
fun hasHighlightColor_invalidColor() {
AssertUtils.assertException { page.eventStatus.withTimeout(100).hasHighlightColor(R.color.invalid) }
}

@Test
fun textViewColors() {
page.eventStatus
.hasCurrentTextColor(R.color.colorPrimary)
.hasCurrentHintTextColor(R.color.colorHint)
.hasShadowColor(R.color.colorShadow)
.hasHighlightColor(R.color.colorHighlight)
}

@Test
fun appCompatTextViewTextColor() {
page.appCompatTextView.hasCurrentTextColor(R.color.colorPrimary)
}

@Test
fun appCompatTextViewTextColor_invalidColor() {
AssertUtils.assertException { page.appCompatTextView.withTimeout(100).hasCurrentTextColor(R.color.invalid) }
}
}
5 changes: 5 additions & 0 deletions sample-app/src/main/res/layout/activity_uielements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
android:id="@+id/last_event_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:textColorHint="@color/colorHint"
android:shadowColor="@color/colorShadow"
android:textColorHighlight="@color/colorHighlight"
android:text="@string/button_text" />

<RadioGroup
Expand Down Expand Up @@ -97,6 +101,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="@color/colorPrimary"
android:text="@string/app_compat_text" />

<LinearLayout
Expand Down
6 changes: 6 additions & 0 deletions sample-app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#2A4B9F</color>
<color name="colorLight">#58E1CA</color>
<color name="colorHint">#8158E1</color>
<color name="colorShadow">#A1E158</color>
<color name="colorHighlight">#E158BF</color>
<color name="invalid">#221F21</color>


</resources>
2 changes: 1 addition & 1 deletion ultron/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext.versions = [
'minSdk' : 16,
'compileSdk' : 31,
'targetSdk' : 31,
'buildTools' : '29.0.3',
'buildTools' : '33.0.1',
'release' : publishedVersion,
'code' : 2,
'recyclerview' : '1.2.1',
Expand Down
Loading

0 comments on commit 0bca22f

Please sign in to comment.