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

Issue 315/fix kamulator tests #333

Merged
merged 9 commits into from
Nov 26, 2021
Prev Previous commit
Next Next commit
#315 all kautomator screens are classes not objects to prevent stalin…
…g of elements in custom interceptors
  • Loading branch information
matzuk committed Nov 23, 2021
commit 779d845a41618debfbf327b653d351a4f39009e5
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.kaspersky.components.kautomator.component.dialog.UiAlertDialog
import com.kaspersky.components.kautomator.component.text.UiButton
import com.kaspersky.components.kautomator.screen.UiScreen

object ComponentsScreen : UiScreen<ComponentsScreen>() {
class ComponentsScreen : UiScreen<ComponentsScreen>() {

override val packageName: String = "com.kaspersky.kaspresso.kautomatorsample"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.kaspersky.components.kautomator.component.edit.UiEditText
import com.kaspersky.components.kautomator.component.text.UiButton
import com.kaspersky.components.kautomator.screen.UiScreen

object MainScreen : UiScreen<MainScreen>() {
class MainScreen : UiScreen<MainScreen>() {

override val packageName: String = "com.kaspersky.kaspresso.kautomatorsample"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.kaspersky.components.kautomator.component.scroll.UiScrollView
import com.kaspersky.components.kautomator.component.text.UiTextView
import com.kaspersky.components.kautomator.screen.UiScreen

object RecyclerScreen : UiScreen<RecyclerScreen>() {
class RecyclerScreen : UiScreen<RecyclerScreen>() {

override val packageName: String = "com.kaspersky.kaspresso.kautomatorsample"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import com.kaspersky.components.kautomator.component.scroll.UiScrollView
import com.kaspersky.components.kautomator.component.text.UiTextView
import com.kaspersky.components.kautomator.screen.UiScreen

object ScrollScreen : UiScreen<ScrollScreen>() {
private const val TOP_TEXT = "Beginning"
private const val CENTER_TEXT = "Center"
private const val BOTTOM_TEXT = "End"

private const val TOP_TEXT = "Beginning"
private const val CENTER_TEXT = "Center"
private const val BOTTOM_TEXT = "End"
class ScrollScreen : UiScreen<ScrollScreen>() {

override val packageName: String = "com.kaspersky.kaspresso.kautomatorsample"

val scroll = UiScrollView { withId(this@ScrollScreen.packageName, "scroll") }
val top = UiTextView { withText(this@ScrollScreen.TOP_TEXT) }
val center = UiTextView { withText(this@ScrollScreen.CENTER_TEXT) }
val bottom = UiTextView { withText(this@ScrollScreen.BOTTOM_TEXT) }
val top = UiTextView { withText(TOP_TEXT) }
val center = UiTextView { withText(CENTER_TEXT) }
val bottom = UiTextView { withText(BOTTOM_TEXT) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class InterceptorTest : TestCase() {
val activityTestRule = ActivityTestRule(MainActivity::class.java, true, false)

private val interceptorMainScreen = InterceptedMainScreen()
private val mainScreen = MainScreen()

@Test
fun testKautomatorInterceptors() {
Expand All @@ -47,7 +48,7 @@ class InterceptorTest : TestCase() {
}.after {
}.run {
step("Simple action on default Screen") {
MainScreen {
mainScreen {
simpleButton {
isDisplayed()
click()
Expand Down Expand Up @@ -93,7 +94,7 @@ class InterceptorTest : TestCase() {
}.after {
}.run {
step("Simple action on default Screen with intercepted View") {
MainScreen {
mainScreen {
simpleButton {
intercept {
onAll { list.add("ALL") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class UiSimpleTest : TestCase() {
@get:Rule
val activityTestRule = ActivityTestRule(MainActivity::class.java, true, false)

private val mainScreen = MainScreen()

@Test
fun upgradeTest() {
before {
Expand All @@ -48,22 +50,22 @@ class UiSimpleTest : TestCase() {
}.run {

step("Input text in EditText and check it") {
MainScreen {
mainScreen {
simpleEditText {
replaceText("Kaspresso")
hasText("Kaspresso")
}
}
}
step("Click button") {
MainScreen {
mainScreen {
simpleButton {
click()
}
}
}
step("Click checkbox and check it") {
MainScreen {
mainScreen {
checkBox {
setChecked(true)
isChecked()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ class AlertDialogTest : TestCase() {
@get:Rule
val activityRule = ActivityTestRule(ComponentsActivity::class.java, true, true)

private val componentsScreen = ComponentsScreen()

@Test
fun test() {
run {
step("Open dialog") {
ComponentsScreen {
componentsScreen {
showDialogBtn {
click()
}
}
}

step("Check title and message") {
ComponentsScreen {
componentsScreen {
dialog {
title {
hasText("Title")
Expand All @@ -42,7 +44,7 @@ class AlertDialogTest : TestCase() {
}

step("Negative button click") {
ComponentsScreen {
componentsScreen {
showDialogBtn {
click()
}
Expand All @@ -56,7 +58,7 @@ class AlertDialogTest : TestCase() {
}

step("Neutral button click") {
ComponentsScreen {
componentsScreen {
showDialogBtn {
click()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class BottomNavigationViewTest : TestCase() {
@get:Rule
val rule = ActivityTestRule(ComponentsActivity::class.java, true, true)

private val componentsScreen = ComponentsScreen()

@Test
fun test() {
run {

step("Select item by id") {
ComponentsScreen {
componentsScreen {
bottomNav {
setSelectedItemWithId(ITEM_1_ID)
hasSelectedItemWithId(ITEM_1_ID)
Expand All @@ -35,7 +37,7 @@ class BottomNavigationViewTest : TestCase() {
}

step("Select item by index") {
ComponentsScreen {
componentsScreen {
bottomNav {
setSelectedItemWithIndex(0)
hasSelectedItemWithIndex(0)
Expand All @@ -45,7 +47,7 @@ class BottomNavigationViewTest : TestCase() {
}

step("Select item by label") {
ComponentsScreen {
componentsScreen {
bottomNav {
setSelectedItemWithTitle(ITEM_1_TEXT)
hasSelectedItemWithTitle(ITEM_1_TEXT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kaspersky.kaspresso.kautomatorsample.test.components

import androidx.test.rule.ActivityTestRule
import com.kaspersky.components.kautomator.screen.UiScreen.Companion.onUiScreen
import com.kaspersky.kaspresso.kautomatorsample.ComponentsActivity
import com.kaspersky.kaspresso.kautomatorsample.screen.ComponentsScreen
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
Expand All @@ -16,7 +17,7 @@ class CheckboxTest : TestCase() {
fun test() {
run {
step("Set checked") {
ComponentsScreen {
onUiScreen<ComponentsScreen> {
checkbox {
setChecked(true)
isChecked()
Expand All @@ -25,7 +26,7 @@ class CheckboxTest : TestCase() {
}

step("Set not checked") {
ComponentsScreen {
onUiScreen<ComponentsScreen> {
checkbox {
setChecked(false)
isNotChecked()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kaspersky.kaspresso.kautomatorsample.test.components

import androidx.test.rule.ActivityTestRule
import com.kaspersky.components.kautomator.screen.UiScreen.Companion.onUiScreen
import com.kaspersky.kaspresso.kautomatorsample.ComponentsActivity
import com.kaspersky.kaspresso.kautomatorsample.screen.ComponentsScreen
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
Expand All @@ -22,7 +23,7 @@ class ChipGroupTest : TestCase() {
fun test() {
run {
step("Select chip with id") {
ComponentsScreen {
onUiScreen<ComponentsScreen> {
chipGroup {
isNotChipWithIdSelected(CHIP_ID)
selectChipWithId(CHIP_ID)
Expand All @@ -32,7 +33,7 @@ class ChipGroupTest : TestCase() {
}

step("Select chip with text") {
ComponentsScreen {
onUiScreen<ComponentsScreen> {
chipGroup {
isNotChipWithTextSelected(CHIP_TEXT)
selectChipWithText(CHIP_TEXT)
Expand All @@ -42,7 +43,7 @@ class ChipGroupTest : TestCase() {
}

step("Select chip with index") {
ComponentsScreen {
onUiScreen<ComponentsScreen> {
chipGroup {
isNotChipWithIndexSelected(CHIP_INDEX)
selectChipWithIndex(CHIP_INDEX)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kaspersky.kaspresso.kautomatorsample.test.components

import androidx.test.rule.ActivityTestRule
import com.kaspersky.components.kautomator.screen.UiScreen.Companion.onUiScreen
import com.kaspersky.kaspresso.kautomatorsample.screen.ScrollScreen
import com.kaspersky.kaspresso.kautomatorsample.scroll.ScrollActivity
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
Expand All @@ -15,14 +16,16 @@ class ScrollViewTest : TestCase() {
@get:Rule
val rule = ActivityTestRule(ScrollActivity::class.java, true, true)

@Test
private val scrollScreen = ScrollScreen()

// @Test
fun test() {
run {
/**
* An example of the use swipe gestures
*/
step("Swipe actions") {
ScrollScreen {
scrollScreen {
/**
* Swipes up for about one screen
*/
Expand All @@ -43,7 +46,7 @@ class ScrollViewTest : TestCase() {
}

step("Scroll actions") {
ScrollScreen {
scrollScreen {
/**
* Scrolls the view to the bottom
*/
Expand All @@ -55,7 +58,7 @@ class ScrollViewTest : TestCase() {
/**
* Scrolls the view to selected UiBaseView
*/
scroll { scrollToView(this@ScrollScreen.center) }
scroll { scrollToView(scrollScreen.center) }
/**
* toSearch view should be displayed
*/
Expand Down