-
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.
Issue 554 automatic artifacts pulling (#558)
* ISSUE-554: Pulling artifacts after tests * ISSUE-554: Added sample * ISSUE-554: Updated doc * ISSUE-554: Lint * ISSUE-554: PR comments * ISSUE-554: Fix compose test
- Loading branch information
Showing
11 changed files
with
205 additions
and
5 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
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
48 changes: 48 additions & 0 deletions
48
...n/com/kaspersky/kaspresso/internal/runlisteners/artifactspull/ArtifactsPullRunListener.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.kaspresso.internal.runlisteners.artifactspull | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.kaspersky.kaspresso.device.files.Files | ||
import com.kaspersky.kaspresso.files.dirs.DefaultDirsProvider | ||
import com.kaspersky.kaspresso.files.dirs.DirsProvider | ||
import com.kaspersky.kaspresso.instrumental.InstrumentalDependencyProviderFactory | ||
import com.kaspersky.kaspresso.kaspresso.Kaspresso | ||
import com.kaspersky.kaspresso.logger.Logger | ||
import com.kaspersky.kaspresso.params.ArtifactsPullParams | ||
import com.kaspersky.kaspresso.runner.listener.KaspressoRunListener | ||
import org.junit.runner.Result | ||
import java.io.File | ||
|
||
class ArtifactsPullRunListener( | ||
private val params: ArtifactsPullParams, | ||
private val dirsProvider: DirsProvider = DefaultDirsProvider(InstrumentalDependencyProviderFactory().getComponentProvider<Kaspresso>(InstrumentationRegistry.getInstrumentation())), | ||
private val files: Files, | ||
private val logger: Logger | ||
) : KaspressoRunListener { | ||
override fun testRunFinished(result: Result) { | ||
if (!params.enabled) return | ||
|
||
val rootDir = dirsProvider.provideNew(File("")) | ||
val filesInRootDir = rootDir.listFiles() | ||
if (filesInRootDir.isNullOrEmpty()) { | ||
logger.d("After test artifacts pulling abort: found no files to move") | ||
return | ||
} | ||
|
||
logger.d("After test artifacts pulling started. Root dir=${rootDir.absolutePath}; artifacts regex=${params.artifactsRegex}; destination path=${params.destinationPath}") | ||
filesInRootDir.forEach { file -> | ||
try { | ||
if (file.name.matches(params.artifactsRegex)) { | ||
val fullFilePath = File(rootDir, file.name) | ||
files.pull( | ||
devicePath = fullFilePath.absolutePath, | ||
serverPath = params.destinationPath | ||
) | ||
} | ||
} catch (ex: Throwable) { | ||
logger.e("Failed to move file $file due to exception") | ||
logger.e(ex.stackTraceToString()) | ||
} | ||
} | ||
logger.d("After test artifacts pulling finished") | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
kaspresso/src/main/kotlin/com/kaspersky/kaspresso/params/ArtifactsPullParams.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,18 @@ | ||
package com.kaspersky.kaspresso.params | ||
|
||
data class ArtifactsPullParams( | ||
/** | ||
* Relative path. Absolute one depends on the working directory from which ADB server was started | ||
*/ | ||
val destinationPath: String = ".", | ||
|
||
/** | ||
* Artifacts would be pulled if it's name fits regex | ||
*/ | ||
val artifactsRegex: Regex = "(screenshots)|(video)|(logcat)|(view_hierarchy)".toRegex(), | ||
|
||
/** | ||
* Whether Kaspresso should pull the artifacts after a test run. Needs an ADB server to work | ||
*/ | ||
val enabled: Boolean = 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
75 changes: 75 additions & 0 deletions
75
.../androidTest/kotlin/com/kaspersky/kaspressample/artifacts_pulling/ArtifactsPullingTest.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,75 @@ | ||
package com.kaspersky.kaspressample.artifacts_pulling | ||
|
||
import android.Manifest | ||
import androidx.test.ext.junit.rules.activityScenarioRule | ||
import androidx.test.rule.GrantPermissionRule | ||
import com.kaspersky.kaspressample.MainActivity | ||
import com.kaspersky.kaspressample.R | ||
import com.kaspersky.kaspressample.screen.MainScreen | ||
import com.kaspersky.kaspressample.screen.SimpleScreen | ||
import com.kaspersky.kaspressample.simple_tests.CheckEditScenario | ||
import com.kaspersky.kaspresso.kaspresso.Kaspresso | ||
import com.kaspersky.kaspresso.params.ArtifactsPullParams | ||
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
/** | ||
* After test completes screenshots directory would be pulled into provided destination path ob the host machine | ||
*/ | ||
class ArtifactsPullingTest : TestCase(kaspressoBuilder = Kaspresso.Builder.simple { | ||
artifactsPullParams = ArtifactsPullParams(artifactsRegex = Regex("screenshots"), destinationPath = "../../output/artifacts") | ||
}) { | ||
|
||
@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 test() = run { | ||
step("Open Simple Screen") { | ||
testLogger.i("I am testLogger") | ||
device.screenshots.take("Additional_screenshot") | ||
MainScreen { | ||
simpleButton { | ||
isVisible() | ||
click() | ||
} | ||
} | ||
} | ||
|
||
step("Click button_1 and check button_2") { | ||
SimpleScreen { | ||
button1 { | ||
click() | ||
} | ||
button2 { | ||
isVisible() | ||
} | ||
} | ||
} | ||
|
||
step("Click button_2 and check edit") { | ||
SimpleScreen { | ||
button2 { | ||
click() | ||
} | ||
edit { | ||
flakySafely(timeoutMs = 7000) { isVisible() } | ||
hasText(R.string.simple_fragment_text_edittext) | ||
} | ||
} | ||
} | ||
|
||
step("Check all possibilities of edit") { | ||
scenario( | ||
CheckEditScenario() | ||
) | ||
} | ||
} | ||
} |
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