-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #319 from KasperskyLab/issue-318/kamulator_tests_i…
…n_tutorial #318. kamulator tests for tutorial
- Loading branch information
Showing
7 changed files
with
144 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...src/androidTest/kotlin/com/kaspersky/kaspresso/tutorial/kautomator_screen/UiMainScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.kaspersky.kaspresso.tutorial.kautomator_screen | ||
|
||
import com.kaspersky.components.kautomator.component.text.UiButton | ||
import com.kaspersky.components.kautomator.screen.UiScreen | ||
|
||
object UiMainScreen : UiScreen<UiMainScreen>() { | ||
|
||
override val packageName: String = "com.kaspersky.kaspresso.tutorial" | ||
|
||
val simpleButton = UiButton { withId(this@UiMainScreen.packageName, "activity_main_simple_sample_button") } | ||
} |
14 changes: 14 additions & 0 deletions
14
...c/androidTest/kotlin/com/kaspersky/kaspresso/tutorial/kautomator_screen/UiSimpleScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.kaspersky.kaspresso.tutorial.kautomator_screen | ||
|
||
import com.kaspersky.components.kautomator.component.edit.UiEditText | ||
import com.kaspersky.components.kautomator.component.text.UiButton | ||
import com.kaspersky.components.kautomator.screen.UiScreen | ||
|
||
object UiSimpleScreen : UiScreen<UiSimpleScreen>() { | ||
|
||
override val packageName: String = "com.kaspersky.kaspresso.tutorial" | ||
|
||
val button1 = UiButton { withId(this@UiSimpleScreen.packageName, "button_1") } | ||
val button2 = UiButton { withId(this@UiSimpleScreen.packageName, "button_2") } | ||
val edit = UiEditText { withId(this@UiSimpleScreen.packageName, "edit") } | ||
} |
31 changes: 31 additions & 0 deletions
31
...ndroidTest/kotlin/com/kaspersky/kaspresso/tutorial/kautomator_test/UiCheckEditScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.kaspersky.kaspresso.tutorial.kautomator_test | ||
|
||
import com.kaspersky.kaspresso.testcases.api.scenario.BaseScenario | ||
import com.kaspersky.kaspresso.testcases.core.testcontext.TestContext | ||
import com.kaspersky.kaspresso.tutorial.kautomator_screen.UiSimpleScreen | ||
|
||
class UiCheckEditScenario<ScenarioData> : BaseScenario<ScenarioData>() { | ||
|
||
override val steps: TestContext<ScenarioData>.() -> Unit = { | ||
|
||
step("Change the text in edit and check it") { | ||
UiSimpleScreen { | ||
edit { | ||
clearText() | ||
typeText("111") | ||
hasText("111") | ||
} | ||
} | ||
} | ||
|
||
step("Change the text in edit and check it. Second check") { | ||
UiSimpleScreen { | ||
edit { | ||
clearText() | ||
typeText("222") | ||
hasText("222") | ||
} | ||
} | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...l/src/androidTest/kotlin/com/kaspersky/kaspresso/tutorial/kautomator_test/UiSimpleTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.kaspersky.kaspresso.tutorial.kautomator_test | ||
|
||
import android.Manifest | ||
import androidx.test.ext.junit.rules.activityScenarioRule | ||
import androidx.test.rule.GrantPermissionRule | ||
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase | ||
import com.kaspersky.kaspresso.tutorial.MainActivity | ||
import com.kaspersky.kaspresso.tutorial.R | ||
import com.kaspersky.kaspresso.tutorial.kautomator_screen.UiMainScreen | ||
import com.kaspersky.kaspresso.tutorial.kautomator_screen.UiSimpleScreen | ||
import io.github.kakaocup.kakao.common.utilities.getResourceString | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
/** | ||
* In this example you can see a test tuned by default Kaspresso configuration. | ||
* When you start the test you can see output of default Kaspresso interceptors: | ||
* - a lot of useful logs | ||
* - failure handling | ||
* - screenshots in the device | ||
* Also you can see the test DSL simplifying the writing of any test | ||
*/ | ||
class UiSimpleTest : TestCase() { | ||
|
||
@get:Rule | ||
val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant( | ||
Manifest.permission.WRITE_EXTERNAL_STORAGE, | ||
Manifest.permission.READ_EXTERNAL_STORAGE | ||
) | ||
|
||
@get:Rule | ||
val activityRule = activityScenarioRule<MainActivity>() | ||
|
||
@Test | ||
fun test() = | ||
before { | ||
testLogger.i("Before section") | ||
}.after { | ||
testLogger.i("After section") | ||
}.run { | ||
step("Open Simple Screen") { | ||
testLogger.i("Main section") | ||
device.screenshots.take("Additional_screenshot") | ||
|
||
UiMainScreen { | ||
simpleButton { | ||
isDisplayed() | ||
click() | ||
} | ||
} | ||
} | ||
|
||
step("Click button_1 and check button_2") { | ||
UiSimpleScreen { | ||
button1 { | ||
click() | ||
} | ||
button2 { | ||
isDisplayed() | ||
} | ||
} | ||
} | ||
|
||
step("Click button_2 and check edit") { | ||
UiSimpleScreen { | ||
button2 { | ||
click() | ||
} | ||
edit { | ||
flakySafely(timeoutMs = 7000) { isDisplayed() } | ||
hasText(getResourceString(R.string.simple_fragment_text_edittext)) | ||
} | ||
} | ||
} | ||
|
||
step("Check all possibilities of edit") { | ||
scenario( | ||
UiCheckEditScenario() | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters