Sudarshan | WIP: BrowserStack Gradle task
This commit is contained in:
8
app/BrowserStackE2EConfig.json
Normal file
8
app/BrowserStackE2EConfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"devices": ["Google Pixel-8.0"],
|
||||
"app": "APPURL",
|
||||
"deviceLogs": true,
|
||||
"networkLogs": true,
|
||||
"testSuite": "TESTURL",
|
||||
"annotation": ["com.naviapp.E2ETest"]
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import groovy.json.JsonSlurper
|
||||
import groovy.json.JsonBuilder
|
||||
|
||||
plugins {
|
||||
id('com.android.application')
|
||||
id('kotlin-android')
|
||||
@@ -6,7 +9,6 @@ plugins {
|
||||
id('maven')
|
||||
id('com.google.firebase.crashlytics')
|
||||
id('com.google.gms.google-services')
|
||||
id("com.browserstack.gradle")
|
||||
}
|
||||
|
||||
def VERSION_NAME = "1.0.8"
|
||||
@@ -272,12 +274,78 @@ dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.71"
|
||||
}
|
||||
|
||||
browserStackConfig {
|
||||
username = "sudarshangs1"
|
||||
accessKey = "oaYqM81qEjMTwpAaipiQ"
|
||||
devices = ['Google Pixel 3-9.0']
|
||||
annotations = ["${annotation}"]
|
||||
allowDeviceMockServer = "true"
|
||||
task executeTestsOnBrowserStack {
|
||||
doLast {
|
||||
def jsonParser = new JsonSlurper()
|
||||
|
||||
// Upload App
|
||||
def appUrl = new ByteArrayOutputStream().withStream { outputStream ->
|
||||
exec {
|
||||
executable "/bin/sh" args "-c", "curl -u ${bsAuth} -X POST ${bsAppUpload} -F \"file=@${devDebugApk}\" "
|
||||
standardOutput = outputStream
|
||||
}
|
||||
|
||||
jsonParser.parseText(outputStream.toString()).app_url
|
||||
}
|
||||
|
||||
// Upload Test-Suite
|
||||
def testUrl = new ByteArrayOutputStream().withStream { outputStream ->
|
||||
exec {
|
||||
executable "/bin/sh" args "-c", "curl -u ${bsAuth} -X POST ${bsTestUpload} -F \"file=@${devTestApk}\" "
|
||||
standardOutput = outputStream
|
||||
}
|
||||
|
||||
jsonParser.parseText(outputStream.toString()).test_url
|
||||
}
|
||||
|
||||
println("AppUrl: " + appUrl)
|
||||
println("TestUrl: " + testUrl)
|
||||
|
||||
def config = jsonParser.parseText(file(bsE2EConfig).text)
|
||||
config.app = appUrl
|
||||
config.testSuite = testUrl
|
||||
|
||||
def buildId = new ByteArrayOutputStream().withStream { outputStream ->
|
||||
def configString = new JsonBuilder(config).toPrettyString().replace("\"", "\\\"")
|
||||
def executionUrl = "curl -X POST ${bsExecute} -d \\ \"${configString}\" -H \"Content-Type: application/json\" -u ${bsAuth}"
|
||||
|
||||
exec {
|
||||
executable "/bin/sh" args "-c", "${executionUrl} "
|
||||
standardOutput = outputStream
|
||||
}
|
||||
|
||||
jsonParser.parseText(outputStream.toString()).build_id
|
||||
}
|
||||
|
||||
println("Build-ID: " + buildId)
|
||||
|
||||
// Poll For Test Results
|
||||
def streamOutput = new ByteArrayOutputStream()
|
||||
def status = ""
|
||||
def pollingTimeout = System.currentTimeMillis() + (180 * 1000)
|
||||
|
||||
while (status != "done" && System.currentTimeMillis() <= pollingTimeout) {
|
||||
exec {
|
||||
executable "/bin/sh" args "-c", "curl -u ${bsAuth} -X GET \"${bsBuilds}${buildId}\""
|
||||
standardOutput = streamOutput
|
||||
}
|
||||
|
||||
status = jsonParser.parseText(streamOutput.toString()).status
|
||||
println("Status: " + status)
|
||||
if (status != "done") {
|
||||
sleep(60000)
|
||||
streamOutput = new ByteArrayOutputStream()
|
||||
}
|
||||
}
|
||||
|
||||
def buildStatus = jsonParser.parseText(streamOutput.toString())
|
||||
def device = config.devices[0]
|
||||
println(buildStatus.devices["${device}"].test_status)
|
||||
|
||||
if(buildStatus.devices["${device}"].test_status.FAILED > 0) {
|
||||
throw new GradleException(buildStatus.devices.test_status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ buildscript {
|
||||
|
||||
// Add the Crashlytics Gradle plugin.
|
||||
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta04'
|
||||
classpath "gradle.plugin.com.browserstack.gradle:browserstack-gradle-plugin:2.3.3"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,4 +21,12 @@ android.enableJetifier=true
|
||||
kotlin.code.style=official
|
||||
org.gradle.daemon=true
|
||||
org.gradle.parallel=true
|
||||
annotation=""
|
||||
annotation=""
|
||||
bsAuth="sudarshangs1:oaYqM81qEjMTwpAaipiQ"
|
||||
bsBuilds="https://api-cloud.browserstack.com/app-automate/espresso/builds/"
|
||||
bsAppUpload="https://api-cloud.browserstack.com/app-automate/upload"
|
||||
bsTestUpload="https://api-cloud.browserstack.com/app-automate/espresso/test-suite"
|
||||
bsExecute="https://api-cloud.browserstack.com/app-automate/espresso/build"
|
||||
devDebugApk=build/outputs/apk/dev/debug/app-dev-debug.apk
|
||||
devTestApk=build/outputs/apk/androidTest/dev/debug/app-dev-debug-androidTest.apk
|
||||
bsE2EConfig=BrowserStackE2EConfig.json
|
||||
Reference in New Issue
Block a user