-
Notifications
You must be signed in to change notification settings - Fork 153
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
Issue 554 automatic artifacts pulling #558
Merged
AzamatCherchesov
merged 6 commits into
master
from
ISSUE-554-Automatic-artifacts-pulling
Aug 23, 2023
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
597b9de
ISSUE-554: Pulling artifacts after tests
Nikitae57 6c93462
ISSUE-554: Added sample
Nikitae57 eb4927b
ISSUE-554: Updated doc
Nikitae57 ba824c3
ISSUE-554: Lint
Nikitae57 bcde13d
ISSUE-554: PR comments
Nikitae57 35cba19
ISSUE-554: Fix compose test
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
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( | ||
/** | ||
* Whether Kaspresso should pull the artifacts after a test run. Needs an ADB server to work | ||
*/ | ||
val enabled: Boolean = false, | ||
|
||
/** | ||
* 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() | ||
) |
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
72 changes: 72 additions & 0 deletions
72
.../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,72 @@ | ||
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 | ||
|
||
class ArtifactsPullingTest : TestCase(kaspressoBuilder = Kaspresso.Builder.simple { | ||
artifactsPullParams = ArtifactsPullParams(enabled = true, artifactsRegex = Regex("screenshots")) | ||
}) { | ||
|
||
@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() | ||
) | ||
} | ||
} | ||
} |
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.
in samples maybe it is better to use all params, to show full scenario usage.