-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
581 additions
and
22 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
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
14 changes: 14 additions & 0 deletions
14
.../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,14 @@ | ||
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()) { | ||
throw 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) | ||
} |
33 changes: 33 additions & 0 deletions
33
.../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,33 @@ | ||
package com.kaspersky.components.alluresupport.visual | ||
|
||
import android.graphics.Bitmap | ||
import com.kaspersky.components.alluresupport.files.attachScreenshotToAllureReport | ||
import com.kaspersky.kaspresso.files.dirs.DirsProvider | ||
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, | ||
dirsProvider: DirsProvider, | ||
resourcesRootDirsProvider: ResourcesRootDirsProvider, | ||
) : DefaultScreenshotsComparator(visualTestParams, logger, dirsProvider, resourcesRootDirsProvider) { | ||
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() | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...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,31 @@ | ||
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) { throw 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
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,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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,5 @@ | ||
publish.artifactGroup=com.kaspersky.android-components | ||
publish.artifactName=kaspresso | ||
publish.publicationName=Kaspresso | ||
publish.bintrayRepo=Kaspresso | ||
publish.bintrayRepo=Kaspresso | ||
kaspresso.visualTestType="Compare" |
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.