Skip to content

Commit

Permalink
Replace ActivityTestRule with ActivityScenarioTestRule in Kaspresso s…
Browse files Browse the repository at this point in the history
…ample module
  • Loading branch information
sergio-sastre committed Aug 8, 2022
1 parent 2bd0241 commit 289e4cc
Show file tree
Hide file tree
Showing 45 changed files with 582 additions and 665 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.kaspersky.kaspressample.compose_tests

import android.Manifest
import androidx.test.rule.ActivityTestRule
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.rule.GrantPermissionRule
import com.kaspersky.kaspressample.MainActivity
import com.kaspersky.kaspressample.external_screens.UiComposeDialog1
Expand All @@ -21,88 +21,84 @@ class ComplexComposeTest : TestCase() {
)

@get:Rule
val activityTestRule = ActivityTestRule(MainActivity::class.java, true, false)
val activityRule = activityScenarioRule<MainActivity>()

@Test
fun test() {
before {
activityTestRule.launchActivity(null)
}.after {
}.run {
step("Open Complex compose Screen") {
MainScreen {
composeButton {
click()
}
fun test() = run {
step("Open Complex compose Screen") {
MainScreen {
composeButton {
click()
}
}
}

step("Click start button") {
ComplexComposeScreen {
startButton {
isVisible()
click()
}
step("Click start button") {
ComplexComposeScreen {
startButton {
isVisible()
click()
}
}
}

step("Handle potential unexpected behavior") {
compose {
// the first potential branch when ComplexComposeScreen.stage1Button is visible
or(ComplexComposeScreen.stage1Button) {
isVisible()
} then {
// here, there is not any special context of this lambda
// that's why we can't call ComplexComposeScreen.stage1Button's methods inside the lambda directly
step("Handle potential unexpected behavior") {
compose {
// the first potential branch when ComplexComposeScreen.stage1Button is visible
or(ComplexComposeScreen.stage1Button) {
isVisible()
} then {
// here, there is not any special context of this lambda
// that's why we can't call ComplexComposeScreen.stage1Button's methods inside the lambda directly

// if the first branch was succeed then we execute some special flow
step("Flow is over the product") {
ComplexComposeScreen {
stage1Button {
click()
}
stage2Button {
isVisible()
click()
}
// if the first branch was succeed then we execute some special flow
step("Flow is over the product") {
ComplexComposeScreen {
stage1Button {
click()
}
stage2Button {
isVisible()
click()
}
}
}
// the second potential branch when UiComposeDialog1.title is visible
// just imagine that is some unexpected system or product behavior and we cannot fix it now
or(UiComposeDialog1.title) {
isDisplayed()
} then {
// if the second branch was succeed then we execute some special flow
step("Flow is over dialogs") {
UiComposeDialog1 {
okButton {
isDisplayed()
click()
}
}
// the second potential branch when UiComposeDialog1.title is visible
// just imagine that is some unexpected system or product behavior and we cannot fix it now
or(UiComposeDialog1.title) {
isDisplayed()
} then {
// if the second branch was succeed then we execute some special flow
step("Flow is over dialogs") {
UiComposeDialog1 {
okButton {
isDisplayed()
click()
}
UiComposeDialog2 {
title {
isDisplayed()
}
okButton {
isDisplayed()
click()
}
}
UiComposeDialog2 {
title {
isDisplayed()
}
okButton {
isDisplayed()
click()
}
}
}
}
}
}

step("Click finish button") {
ComplexComposeScreen {
finishButton {
isVisible()
click()
}
step("Click finish button") {
ComplexComposeScreen {
finishButton {
isVisible()
click()
}
}
}
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.kaspersky.kaspressample.compose_tests

import android.Manifest
import androidx.test.rule.ActivityTestRule
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.rule.GrantPermissionRule
import com.kaspersky.kaspressample.MainActivity
import com.kaspersky.kaspressample.R
Expand All @@ -20,65 +20,60 @@ class SimpleComposeTest : TestCase() {
)

@get:Rule
val activityTestRule = ActivityTestRule(MainActivity::class.java, true, false)
val activityRule = activityScenarioRule<MainActivity>()

@Test
fun test() {
before {
activityTestRule.launchActivity(null)
}.after {
}.run {
step("Open Scroll View Stub Screen") {
MainScreen {
flakyButton {
click()
}
fun test() = run {
step("Open Scroll View Stub Screen") {
MainScreen {
flakyButton {
click()
}
}
}

step("Check ScrollView screen is visible") {
CommonFlakyScreen {
scrollView {
isVisible()
}
step("Check ScrollView screen is visible") {
CommonFlakyScreen {
scrollView {
isVisible()
}
}
}

step("Check btn5's text") {
CommonFlakyScreen {
compose {
or(btn5) { hasText(R.string.common_flaky_final_button) }
or(btn1) { hasText(R.string.common_flaky_final_button) }
}
step("Check btn5's text") {
CommonFlakyScreen {
compose {
or(btn5) { hasText(R.string.common_flaky_final_button) }
or(btn1) { hasText(R.string.common_flaky_final_button) }
}
}
}

step("Check tv6's text") {
CommonFlakyScreen {
compose(timeoutMs = 16_000) {
or(tv6) { hasText(R.string.common_flaky_final_textview) }
or(btn1) { hasText(R.string.common_flaky_final_textview) }
}
step("Check tv6's text") {
CommonFlakyScreen {
compose(timeoutMs = 16_000) {
or(tv6) { hasText(R.string.common_flaky_final_textview) }
or(btn1) { hasText(R.string.common_flaky_final_textview) }
}
}
}

step("Check btn5's text again and click on it") {
CommonFlakyScreen {
btn5.compose {
or {
hasText("Something wrong")
} thenContinue {
// here, the context of this lambda is a context of KButton(btn5),
// that's why we can call KButton's methods inside the lambda
click()
}
or {
hasText(R.string.common_flaky_final_button)
} thenContinue {
// here, the context of this lambda is a context of KButton(btn5),
// that's why we can call KButton's methods inside the lambda
click()
}
step("Check btn5's text again and click on it") {
CommonFlakyScreen {
btn5.compose {
or {
hasText("Something wrong")
} thenContinue {
// here, the context of this lambda is a context of KButton(btn5),
// that's why we can call KButton's methods inside the lambda
click()
}
or {
hasText(R.string.common_flaky_final_button)
} thenContinue {
// here, the context of this lambda is a context of KButton(btn5),
// that's why we can call KButton's methods inside the lambda
click()
}
}
}
Expand Down
Loading

0 comments on commit 289e4cc

Please sign in to comment.