Skip to content

Commit

Permalink
Tech fixes (#560)
Browse files Browse the repository at this point in the history
* TECH: Fix flaky test; fix typo
  • Loading branch information
Nikitae57 authored Sep 7, 2023
1 parent f402954 commit 0f0d889
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LoggingObjectWatcherInterceptor(
logger.i(
"The object: ${interaction.description}. " +
"The operation: Check=${assertion.type}(description={${assertion.description}}. " +
"Additional info: the object was founded by selector=${interaction.selector.bySelector}"
"Additional info: the object was found by selector=${interaction.selector.bySelector}"
)
}

Expand All @@ -38,7 +38,7 @@ class LoggingObjectWatcherInterceptor(
logger.i(
"The object: ${interaction.description}. " +
"The operation: Action=${action.type}(description={${action.description}}. " +
"Additional info: the object was founded by selector=${interaction.selector.bySelector}"
"Additional info: the object was found by selector=${interaction.selector.bySelector}"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package com.kaspersky.kaspressample.docloc_tests.advanced

import android.Manifest
import android.graphics.Color
import android.os.Build
import androidx.fragment.app.testing.FragmentScenario
import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.test.rule.GrantPermissionRule
import com.kaspersky.kaspressample.docloc.ScreenshotSampleFragment
import com.kaspersky.kaspressample.docloc.ScreenshotSampleView
import com.kaspersky.kaspresso.annotations.ScreenShooterTest
import com.kaspersky.kaspresso.testcases.api.testcase.DocLocScreenshotTestCase
import org.junit.Assume
import org.junit.Rule
import org.junit.Test

Expand All @@ -16,7 +19,7 @@ import org.junit.Test
* For more information see DocLoc wiki page.
*/
class AdvancedScreenshotSampleTest : DocLocScreenshotTestCase(locales = "en,ru") {
private lateinit var view: ScreenshotSampleView
private lateinit var scenario: FragmentScenario<ScreenshotSampleFragment>

@get:Rule
val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Expand All @@ -27,26 +30,27 @@ class AdvancedScreenshotSampleTest : DocLocScreenshotTestCase(locales = "en,ru")
@ScreenShooterTest
@Test
fun test() = before {
val scenario = launchFragmentInContainer<ScreenshotSampleFragment>()
scenario.onFragment {
view = getUiSafeProxy(it as ScreenshotSampleView)
}
Assume.assumeTrue("launchFragmentInContainer blocks UI manipulation while onFragment is open", Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP)
scenario = launchFragmentInContainer()
}.after {
}.run {
step("1. Launch feature screen") {
view.setCounterValue(0)
view.setBackgroundColor(Color.WHITE)
captureScreenshot("1. Startup")
}
scenario.onFragment {
val view = getUiSafeProxy(it as ScreenshotSampleView)
step("1. Launch feature screen") {
view.setCounterValue(0)
view.setBackgroundColor(Color.WHITE)
captureScreenshot("1. Startup")
}

step("2. Increase counter by 5") {
view.setCounterValue(5)
captureScreenshot("2. Value has been increased by 5")
}
step("2. Increase counter by 5") {
view.setCounterValue(5)
captureScreenshot("2. Value has been increased by 5")
}

step("3. Set red background color") {
view.setBackgroundColor(Color.RED)
captureScreenshot("3. Background has been set to red")
step("3. Set red background color") {
view.setBackgroundColor(Color.RED)
captureScreenshot("3. Background has been set to red")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package com.kaspersky.kaspressample.docloc_tests.advanced

import android.Manifest
import android.graphics.Color
import android.os.Build
import androidx.fragment.app.testing.FragmentScenario
import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.test.rule.GrantPermissionRule
import com.kaspersky.kaspressample.docloc.ScreenshotSampleFragment
import com.kaspersky.kaspressample.docloc.ScreenshotSampleView
import com.kaspersky.kaspresso.annotations.ScreenShooterTest
import com.kaspersky.kaspresso.testcases.api.testcase.DocLocScreenshotTestCase
import org.junit.Assume
import org.junit.Rule
import org.junit.Test
import java.io.File
Expand All @@ -20,7 +23,7 @@ class AdvancedScreenshotSampleTestLegacy : DocLocScreenshotTestCase(
screenshotsDirectory = File("screenshots"),
locales = "en,ru"
) {
private lateinit var view: ScreenshotSampleView
private lateinit var scenario: FragmentScenario<ScreenshotSampleFragment>

@get:Rule
val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Expand All @@ -31,26 +34,27 @@ class AdvancedScreenshotSampleTestLegacy : DocLocScreenshotTestCase(
@ScreenShooterTest
@Test
fun test() = before {
val scenario = launchFragmentInContainer<ScreenshotSampleFragment>()
scenario.onFragment {
view = getUiSafeProxy(it as ScreenshotSampleView)
}
Assume.assumeTrue("launchFragmentInContainer blocks UI manipulation while onFragment is open", Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP)
scenario = launchFragmentInContainer()
}.after {
}.run {
step("1. Launch feature screen") {
view.setCounterValue(0)
view.setBackgroundColor(Color.WHITE)
captureScreenshot("1. Startup")
}
scenario.onFragment {
val view = getUiSafeProxy(it as ScreenshotSampleView)
step("1. Launch feature screen") {
view.setCounterValue(0)
view.setBackgroundColor(Color.WHITE)
captureScreenshot("1. Startup")
}

step("2. Increase counter by 5") {
view.setCounterValue(5)
captureScreenshot("2. Value has been increased by 5")
}
step("2. Increase counter by 5") {
view.setCounterValue(5)
captureScreenshot("2. Value has been increased by 5")
}

step("3. Set red background color") {
view.setBackgroundColor(Color.RED)
captureScreenshot("3. Background has been set to red")
step("3. Set red background color") {
view.setBackgroundColor(Color.RED)
captureScreenshot("3. Background has been set to red")
}
}
}
}

0 comments on commit 0f0d889

Please sign in to comment.