Skip to content

Commit

Permalink
ISSUE-404: update CI config, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikitae57 authored and eakurnikov committed Dec 2, 2022
1 parent 9b3ef22 commit f5c5176
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 78 deletions.
31 changes: 12 additions & 19 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
check_android_task:
name: Run Android instrumented tests
env:
SCREENSHOTS_ROOT_DIR: /data/user/0/com.kaspersky.kaspressample/files/screenshots
TUTORIAL_SCREENSHOTS_ROOT_DIR: /data/user/0/com.kaspersky.kaspresso.tutorial/files/screenshots
ALLURE_SAMPLE_RESULTS_ROOT_DIR: /data/data/com.kaspersky.kaspresso.alluresupport.sample/files/allure-results
DISPLAY: :99
only_if: $CIRRUS_PR != '' && $CIRRUS_BASE_BRANCH == 'master'

Expand Down Expand Up @@ -52,29 +49,25 @@ check_android_task:
adb shell settings put global animator_duration_scale 0.0
adb shell settings put secure spell_checker_enabled 0
adb shell settings put secure show_ime_with_hard_keyboard 1
start_logcat_background_script:
adb logcat > log.log
run_tests_script:
./gradlew connectedDebugAndroidTest
# After we do "adb root" connection is closed for a moment. So first attempt to pull screenshots usually fails
# That's why we make 5 attempts to pull folders
always:
pull_screenshots_script: |
adb root
mkdir sample_screenshots
for i in {1..5}; do adb pull $SCREENSHOTS_ROOT_DIR sample_screenshots && break || sleep 5; done
mkdir tutorial_screenshots
adb pull $TUTORIAL_SCREENSHOTS_ROOT_DIR tutorial_screenshots || true
mkdir allure_results
adb pull $ALLURE_SAMPLE_RESULTS_ROOT_DIR allure_results
stop_logcat_script:
adb logcat -c
pull_artifacts_script:
adb exec-out sh -c "cd /sdcard && tar cf - Documents" > artifacts.tar
logs_artifacts:
path: log.log
artifacts_artifacts:
path: "artifacts.tar"
sample_report_artifacts:
path: "samples/kaspresso-sample/build/reports/androidTests/connected/**/*"
kautomator_sample_report_artifacts:
path: "samples/kautomator-sample/build/reports/androidTests/connected/**/*"
tutorial_report_artifacts:
path: "tutorial/build/reports/androidTests/connected/**/*"
allure_report_artifacts:
path: "samples/kaspresso-allure-support-sample/build/reports/androidTests/connected/**/*"
sample_screenshots_artifacts:
path: "sample_screenshots/**/*"
tutorial_screenshots_artifacts:
path: "tutorial_screenshots/**/*"
allure_results_artifacts:
path: "allure_results/**/*"

Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@ class AllureSupportSanityTest : TestCase(
assertEquals("There should be 3 root steps", 3, reportJson.getJSONArray(STEPS_JSON_FIELD).length()) // 3 main steps
reportJson.getJSONArray(STEPS_JSON_FIELD).run { // validate steps
for (i in 0 until length()) {
checkStepAttachments(getJSONObject(1))
if (i == 1) {
getJSONObject(1).getJSONArray(STEPS_JSON_FIELD).run {
assertEquals("Second step should contain 2 inner steps", 2, length()) // second main step has 2 inner steps
for (j in 0 until length()) {
checkStepAttachments(getJSONObject(j))
}
}
}
checkStepAttachments(getJSONObject(i))
}
validateNestedStep(getJSONObject(1))
}
}

private fun validateNestedStep(stepJSONObject: JSONObject) {
stepJSONObject.getJSONArray(STEPS_JSON_FIELD).run {
assertEquals("Second step should contain 2 inner steps", 2, length()) // second main step has 2 inner steps
for (j in 0 until length()) {
checkStepAttachments(getJSONObject(j))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ class DocLocSanityTest : DocLocScreenshotTestCase(

return getScreenshotsRootDir().resolve(locale).resolve(SCREENSHOTS_SUBDIR)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
package com.kaspersky.kaspresso.kautomatorsample.test

import android.Manifest
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.rule.GrantPermissionRule
import com.kaspersky.components.kautomator.KautomatorConfigurator
import com.kaspersky.components.kautomator.component.text.UiButton
import com.kaspersky.components.kautomator.screen.UiScreen
import com.kaspersky.kaspresso.interceptors.behaviorkautomator.impl.elementloader.ElementLoaderObjectBehaviorInterceptor
import com.kaspersky.kaspresso.interceptors.behaviorkautomator.impl.flakysafety.FlakySafeObjectBehaviorInterceptor
import com.kaspersky.kaspresso.kaspresso.Kaspresso
import com.kaspersky.kaspresso.kautomatorsample.MainActivity
import com.kaspersky.kaspresso.kautomatorsample.screen.MainScreen
import com.kaspersky.kaspresso.logger.UiTestLogger
import com.kaspersky.kaspresso.params.ElementLoaderParams
import com.kaspersky.kaspresso.params.FlakySafetyParams
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import org.junit.Assert.assertEquals
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test

private lateinit var testElementLoaderParams: ElementLoaderParams
private lateinit var testFlakySafetyParams: FlakySafetyParams
private lateinit var logger: UiTestLogger

/**
* The test demonstrating and checking work of interceptors concept in Kautomator
*/
class InterceptorTest : TestCase() {

@get:Rule
val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
)
class InterceptorTest : TestCase(kaspressoBuilder = Kaspresso.Builder.simple().apply {
testElementLoaderParams = elementLoaderParams
testFlakySafetyParams = flakySafetyParams
logger = testLogger
}) {

@get:Rule
val activityRule = activityScenarioRule<MainActivity>()

private val interceptorMainScreen = InterceptedMainScreen()
private val objectBehaviorInterceptors = listOf(
ElementLoaderObjectBehaviorInterceptor(testLogger, testElementLoaderParams),
FlakySafeObjectBehaviorInterceptor(testFlakySafetyParams, testLogger)
)

@Test
fun testKautomatorInterceptors() {
Expand All @@ -37,9 +48,32 @@ class InterceptorTest : TestCase() {
KautomatorConfigurator {
intercept {
onUiInteraction {
onAll { list.add("ALL") }
onCheck { _, _ -> list.add("CHECK") }
onPerform { _, _ -> list.add("PERFORM") }
onAll {
list.add("ALL")
}
onCheck { interaction, assertion ->
objectBehaviorInterceptors.fold(
initial = {
interaction.check(assertion)
},
operation = { acc, objectBehaviorInterceptor ->
{ objectBehaviorInterceptor.interceptCheck(interaction, assertion, acc) }
}
).invoke()
list.add("CHECK")
}
onPerform { interaction, action ->
objectBehaviorInterceptors.fold(
initial = {
interaction.perform(action)
},
operation = {
acc, objectBehaviorInterceptor ->
{ objectBehaviorInterceptor.interceptPerform(interaction, action, acc) }
}
).invoke()
list.add("PERFORM")
}
}
}
}
Expand Down Expand Up @@ -88,8 +122,29 @@ class InterceptorTest : TestCase() {
simpleButton {
intercept {
onAll { list.add("ALL") }
onCheck { _, _ -> list.add("CHECK") }
onPerform { _, _ -> list.add("PERFORM") }
onCheck { interaction, assertion ->
objectBehaviorInterceptors.fold(
initial = {
interaction.check(assertion)
},
operation = { acc, objectBehaviorInterceptor ->
{ objectBehaviorInterceptor.interceptCheck(interaction, assertion, acc) }
}
).invoke()
list.add("CHECK")
}
onPerform { interaction, action ->
objectBehaviorInterceptors.fold(
initial = {
interaction.perform(action)
},
operation = {
acc, objectBehaviorInterceptor ->
{ objectBehaviorInterceptor.interceptPerform(interaction, action, acc) }
}
).invoke()
list.add("PERFORM")
}
}

isDisplayed()
Expand All @@ -113,8 +168,29 @@ class InterceptorTest : TestCase() {
intercept {
onUiInteraction {
onAll { list.add("ALL_KAUTOMATOR") }
onCheck { _, _ -> list.add("CHECK_KAUTOMATOR") }
onPerform { _, _ -> list.add("PERFORM_KAUTOMATOR") }
onCheck { interaction, assertion ->
objectBehaviorInterceptors.fold(
initial = {
interaction.check(assertion)
},
operation = { acc, objectBehaviorInterceptor ->
{ objectBehaviorInterceptor.interceptCheck(interaction, assertion, acc) }
}
).invoke()
list.add("CHECK_KAUTOMATOR")
}
onPerform { interaction, action ->
objectBehaviorInterceptors.fold(
initial = {
interaction.perform(action)
},
operation = {
acc, objectBehaviorInterceptor ->
{ objectBehaviorInterceptor.interceptPerform(interaction, action, acc) }
}
).invoke()
list.add("PERFORM_KAUTOMATOR")
}
}
}
}
Expand Down Expand Up @@ -149,6 +225,7 @@ class InterceptorTest : TestCase() {
}
}

@Ignore("Previous interceptors are overridden when KautomatorConfigurator is used, so are default flaky safety interceptors, so this test may fail")
@Test
fun testOverridingInterceptors() {
val list = mutableListOf<String>()
Expand Down Expand Up @@ -204,12 +281,38 @@ class InterceptorTest : TestCase() {
val screenList = mutableListOf<String>()
val simpleButton = UiButton { withId(this@InterceptedMainScreen.packageName, "button") }

private val objectBehaviorInterceptors = listOf(
ElementLoaderObjectBehaviorInterceptor(logger, testElementLoaderParams),
FlakySafeObjectBehaviorInterceptor(testFlakySafetyParams, logger)
)

init {
intercept {
onUiInteraction {
onAll { screenList.add("ALL") }
onCheck { _, _ -> screenList.add("CHECK") }
onPerform { _, _ -> screenList.add("PERFORM") }
onCheck { interaction, assertion ->
objectBehaviorInterceptors.fold(
initial = {
interaction.check(assertion)
},
operation = { acc, objectBehaviorInterceptor ->
{ objectBehaviorInterceptor.interceptCheck(interaction, assertion, acc) }
}
).invoke()
screenList.add("CHECK")
}
onPerform { interaction, action ->
objectBehaviorInterceptors.fold(
initial = {
interaction.perform(action)
},
operation = {
acc, objectBehaviorInterceptor ->
{ objectBehaviorInterceptor.interceptPerform(interaction, action, acc) }
}
).invoke()
screenList.add("PERFORM")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.kaspersky.kaspresso.kautomatorsample.test

import android.Manifest
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.rule.GrantPermissionRule
import com.kaspersky.components.kautomator.KautomatorConfigurator
import com.kaspersky.kaspresso.kautomatorsample.MainActivity

import com.kaspersky.kaspresso.kautomatorsample.screen.MainScreen
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import org.junit.Rule
Expand All @@ -17,39 +13,12 @@ import org.junit.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 upgradeTest() {
before {
KautomatorConfigurator {
intercept {
onUiInteraction {
onCheck { uiInteraction, uiAssert ->
// reFindUiObject() is called to update elements in MainScreen that could stale because MainScreen is Object.
// Usually, Kautomator interceptors handle such cases. But here, we define our own Interceptors for Kautomator,
// that's why there is a risk to catch an Exception. All of this forces us to put reFindUiObject() manually.
uiInteraction.reFindUiObject()
testLogger.i("KautomatorIntercept", "interaction=$uiInteraction, assertion=$uiAssert")
uiInteraction.check(uiAssert)
}
onPerform { uiInteraction, uiAction ->
// reFindUiObject() is called to update elements in MainScreen that could stale because MainScreen is Object.
// Usually, Kautomator interceptors handle such cases. But here, we define our own Interceptors for Kautomator,
// that's why there is a risk to catch an Exception. All of this forces us to put reFindUiObject() manually.
uiInteraction.reFindUiObject()
testLogger.i("KautomatorIntercept", "interaction=$uiInteraction, action=$uiAction")
}
}
}
}
}.after {
}.run {

Expand Down

0 comments on commit f5c5176

Please sign in to comment.