-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ISSUE-646-Clean-flaky-safety-interceptor
# Conflicts: # kaspresso/src/main/kotlin/com/kaspersky/kaspresso/flakysafety/scalpel/FlakySafeInterceptorScalpel.kt # kaspresso/src/main/kotlin/com/kaspersky/kaspresso/kaspresso/Kaspresso.kt
- Loading branch information
Showing
59 changed files
with
836 additions
and
109 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
6 changes: 3 additions & 3 deletions
6
...adb-server-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/CmdCommand.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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package com.kaspersky.adbserver.commandtypes | ||
|
||
import com.kaspersky.adbserver.common.api.Command | ||
import com.kaspersky.adbserver.common.api.ComplexCommand | ||
|
||
data class CmdCommand( | ||
override val command: String, | ||
override val body: String, | ||
override val arguments: List<String> = emptyList() | ||
) : Command(command, arguments) | ||
) : ComplexCommand(body, arguments) |
8 changes: 8 additions & 0 deletions
8
...ver-command-types/src/main/java/com/kaspersky/adbserver/commandtypes/ComplexAdbCommand.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,8 @@ | ||
package com.kaspersky.adbserver.commandtypes | ||
|
||
import com.kaspersky.adbserver.common.api.ComplexCommand | ||
|
||
data class ComplexAdbCommand( | ||
override val body: String, | ||
override val arguments: List<String> = emptyList() | ||
) : ComplexCommand(body, arguments) |
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
3 changes: 3 additions & 0 deletions
3
...rver/adb-server-common/src/main/java/com/kaspersky/adbserver/common/api/ComplexCommand.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,3 @@ | ||
package com.kaspersky.adbserver.common.api | ||
|
||
abstract class ComplexCommand(override val body: String, open val arguments: List<String> = emptyList()) : Command(body) |
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
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 | ||
} | ||
} |
Binary file not shown.
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 | ||
} | ||
} |
Oops, something went wrong.