-
Notifications
You must be signed in to change notification settings - Fork 161
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
TECH: Screenshot comparison tests #655
Merged
+642
−24
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6065dd4
TECH: Screenshot comparison tests
Nikitae57 4ac4c14
Merge branch 'master' into TECH-Screenshot-comparison
Nikitae57 708689f
TECH: lint
Nikitae57 d41ba63
Merge branch 'master' into TECH-Screenshot-comparison
Nikitae57 c62ce39
TECH: PR comments
Nikitae57 a596495
TECH: Mark failed allure screenshot assertions as FAILED instead of B…
Nikitae57 7728629
TECH: Fix destination path; add documentation
Nikitae57 35eb8c6
TECH: Fix CustomizedSimpleTest compilation
Nikitae57 09830ac
TECH: Remove unused annotation
Nikitae57 28ef5e6
TECH: Use test name as diff path
Nikitae57 71c1346
TECH: Don't crash sync if gradle property not set
Nikitae57 ddb34ad
TECH: PR comment
Nikitae57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
16 changes: 16 additions & 0 deletions
16
.../kaspersky/components/alluresupport/interceptors/testrun/VisualTestLateFailInterceptor.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,16 @@ | ||
package com.kaspersky.components.alluresupport.interceptors.testrun | ||
|
||
import com.kaspersky.components.alluresupport.results.AllureVisualTestFlag | ||
import com.kaspersky.kaspresso.device.screenshots.ScreenshotsImpl | ||
import com.kaspersky.kaspresso.interceptors.watcher.testcase.TestRunWatcherInterceptor | ||
import com.kaspersky.kaspresso.testcases.models.info.TestInfo | ||
|
||
class VisualTestLateFailInterceptor : TestRunWatcherInterceptor { | ||
override fun onAfterSectionStarted(testInfo: TestInfo) { | ||
if (AllureVisualTestFlag.shouldFailLate.get()) { | ||
// Wrap with assertion error so test would be marked as FAILED instead of BROKEN | ||
// See https://github.com/allure-framework/allure-kotlin allure-kotlin-commons/src/main/kotlin/io/qameta/allure/kotlin/util/ResultsUtils.kt | ||
throw AssertionError(ScreenshotsImpl.ScreenshotDoesntMatchException("There were failed screenshot comparisons. Check the allure report")) | ||
} | ||
} | ||
} |
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
...rt/src/main/kotlin/com/kaspersky/components/alluresupport/results/AllureVisualTestFlag.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.components.alluresupport.results | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
// TODO(Nikita Evdokimov) - Certainly there should be a better way | ||
/** | ||
* @see com.kaspersky.components.alluresupport.interceptors.testrun.VisualTestLateFailInterceptor | ||
*/ | ||
object AllureVisualTestFlag { | ||
val shouldFailLate = AtomicBoolean(false) | ||
} |
35 changes: 35 additions & 0 deletions
35
.../main/kotlin/com/kaspersky/components/alluresupport/visual/AllureScreenshotsComparator.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,35 @@ | ||
package com.kaspersky.components.alluresupport.visual | ||
|
||
import android.graphics.Bitmap | ||
import com.kaspersky.components.alluresupport.files.attachScreenshotToAllureReport | ||
import com.kaspersky.kaspresso.files.resources.ResourceFileNamesProvider | ||
import com.kaspersky.kaspresso.files.resources.ResourcesDirsProvider | ||
import com.kaspersky.kaspresso.files.resources.ResourcesRootDirsProvider | ||
import com.kaspersky.kaspresso.internal.visual.DefaultScreenshotsComparator | ||
import com.kaspersky.kaspresso.logger.Logger | ||
import com.kaspersky.kaspresso.visual.VisualTestParams | ||
import java.io.File | ||
|
||
class AllureScreenshotsComparator( | ||
visualTestParams: VisualTestParams, | ||
logger: Logger, | ||
resourcesRootDirsProvider: ResourcesRootDirsProvider, | ||
resourcesDirsProvider: ResourcesDirsProvider, | ||
resourceFileNamesProvider: ResourceFileNamesProvider, | ||
) : DefaultScreenshotsComparator(visualTestParams, logger, resourcesRootDirsProvider, resourcesDirsProvider, resourceFileNamesProvider) { | ||
override fun compare(originalScreenshot: File, newScreenshot: File): Boolean { | ||
val doScreenshotsMatch = super.compare(originalScreenshot, newScreenshot) | ||
if (!doScreenshotsMatch) { | ||
originalScreenshot.attachScreenshotToAllureReport() | ||
newScreenshot.attachScreenshotToAllureReport() | ||
} | ||
|
||
return doScreenshotsMatch | ||
} | ||
|
||
override fun processScreenshotDiff(original: Bitmap, diffPixels: IntArray, diffName: String): File { | ||
return super.processScreenshotDiff(original, diffPixels, diffName).also { | ||
it.attachScreenshotToAllureReport() | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ort/src/main/kotlin/com/kaspersky/components/alluresupport/visual/AllureVisualTestCase.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,35 @@ | ||
package com.kaspersky.components.alluresupport.visual | ||
|
||
import com.kaspersky.components.alluresupport.results.AllureVisualTestFlag | ||
import com.kaspersky.components.alluresupport.withForcedAllureSupport | ||
import com.kaspersky.kaspresso.device.screenshots.ScreenshotsImpl | ||
import com.kaspersky.kaspresso.kaspresso.Kaspresso | ||
import com.kaspersky.kaspresso.testcases.api.testcase.VisualTestCase | ||
import io.qameta.allure.kotlin.Allure | ||
import io.qameta.allure.kotlin.model.Status | ||
import io.qameta.allure.kotlin.model.StatusDetails | ||
|
||
abstract class AllureVisualTestCase( | ||
private val failEarly: Boolean = false, | ||
kaspressoBuilder: Kaspresso.Builder = Kaspresso.Builder.withForcedAllureSupport() | ||
) : VisualTestCase(kaspressoBuilder = kaspressoBuilder) { | ||
|
||
override fun assertScreenshot(tag: String, isFullWindow: Boolean) { | ||
try { | ||
device.screenshots.assert(tag, isFullWindow) | ||
} catch (ex: ScreenshotsImpl.ScreenshotDoesntMatchException) { | ||
if (failEarly) { | ||
// Wrap with assertion error so test would be marked as FAILED instead of BROKEN | ||
// See https://github.com/allure-framework/allure-kotlin allure-kotlin-commons/src/main/kotlin/io/qameta/allure/kotlin/util/ResultsUtils.kt | ||
throw AssertionError(ex) | ||
} | ||
|
||
Allure.lifecycle.updateStep { | ||
it.status = Status.FAILED | ||
it.statusDetails = StatusDetails(known = true, muted = true, message = ex.message, trace = ex.stackTraceToString()) | ||
} | ||
Allure.lifecycle.stopStep() | ||
AllureVisualTestFlag.shouldFailLate.set(true) | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
.../src/main/kotlin/com/kaspersky/components/alluresupport/visual/AllureVisualTestWatcher.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,48 @@ | ||
package com.kaspersky.components.alluresupport.visual | ||
|
||
import com.kaspersky.components.alluresupport.files.dirs.AllureDirsProvider | ||
import com.kaspersky.kaspresso.device.files.Files | ||
import com.kaspersky.kaspresso.files.resources.ResourcesRootDirsProvider | ||
import com.kaspersky.kaspresso.logger.Logger | ||
import com.kaspersky.kaspresso.visual.VisualTestParams | ||
import com.kaspersky.kaspresso.visual.VisualTestType | ||
import com.kaspersky.kaspresso.visual.VisualTestWatcher | ||
import java.io.File | ||
|
||
class AllureVisualTestWatcher( | ||
private val params: VisualTestParams, | ||
private val logger: Logger, | ||
private val dirsProvider: AllureDirsProvider, | ||
resourcesRootDirsProvider: ResourcesRootDirsProvider, | ||
private val files: Files, | ||
) : VisualTestWatcher { | ||
|
||
private val diffDir = dirsProvider.provideNew(resourcesRootDirsProvider.screenshotsDiffRootDir) | ||
private val originalScreenshotsTargetDir: File | ||
get() { | ||
val rootDir = dirsProvider.provideNewOnSdCard(File("")).absolutePath | ||
return File(rootDir, File(params.hostScreenshotsDir).name) | ||
} | ||
|
||
override fun prepare() { | ||
logger.i("Visual test run started. Parameters: $params") | ||
|
||
if (params.testType == VisualTestType.Compare) { | ||
logger.i("Pushing the screenshots unto the device...") | ||
dirsProvider.provideCleared(diffDir) | ||
|
||
// Allure stores all files in the app's private directory. We can't "adb push" directly there, | ||
// so we have to do this in 2 steps | ||
dirsProvider.provideCleared(originalScreenshotsTargetDir) | ||
val tmp = dirsProvider.provideNewOnSdCard(File("")) | ||
files.push(params.hostScreenshotsDir, tmp.absolutePath) | ||
val target = dirsProvider.provideNew(File("")).resolve(params.hostScreenshotsDir) | ||
File(tmp, params.hostScreenshotsDir).copyRecursively(target, overwrite = true) | ||
logger.i("Done pushing the screenshots unto the device") | ||
} | ||
} | ||
|
||
override fun cleanUp() { | ||
// Do nothing | ||
} | ||
} |
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 |
---|---|---|
|
@@ -32,5 +32,6 @@ configure<BaseExtension> { | |
resValues = false | ||
shaders = false | ||
viewBinding = false | ||
buildConfig = true | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
publish.artifactGroup=com.kaspersky.android-components | ||
publish.artifactName=kaspresso | ||
publish.publicationName=Kaspresso | ||
publish.bintrayRepo=Kaspresso | ||
publish.bintrayRepo=Kaspresso | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move from root folder to sample dir