Sudarshan | Added Tasks to run E2E and MockServerTests
This commit is contained in:
@@ -39,8 +39,10 @@ WORKDIR $WORK_DIR
|
||||
RUN echo ${RELEASE_STORE_FILE} | base64 -d >> app/navi-release-key.jks
|
||||
|
||||
RUN bash -c " \
|
||||
if [ $FLAVOR = TEST ] ; then \
|
||||
./gradlew clean -Pannotation="com.naviappmockserver.MockServerTest" executeMockServerDebugTestsOnBrowserstack; \
|
||||
if [ $FLAVOR = MOCKSERVERTEST ] ; then \
|
||||
./gradlew clean executeMockServerTests; \
|
||||
if [ $FLAVOR = E2ETEST ] ; then \
|
||||
./gradlew clean :app:testDevDebugUnitTest --tests com.naviapp.CleanupCustomers -PtestType="e2e" executeE2ETests; \
|
||||
\
|
||||
elif [ $FLAVOR = DEV ] ; then \
|
||||
./gradlew clean \
|
||||
|
||||
19
app/BrowserStackConfig.json
Normal file
19
app/BrowserStackConfig.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"e2e": {
|
||||
"devices": ["Google Pixel-8.0"],
|
||||
"app": "APPURL",
|
||||
"deviceLogs": true,
|
||||
"networkLogs": true,
|
||||
"testSuite": "TESTURL",
|
||||
"annotation": ["com.naviapp.E2ETest"]
|
||||
},
|
||||
"mockServer": {
|
||||
"devices": ["Google Pixel-8.0"],
|
||||
"app": "APPURL",
|
||||
"deviceLogs": true,
|
||||
"networkLogs": true,
|
||||
"testSuite": "TESTURL",
|
||||
"annotation": ["com.naviappmockserver.MockServerTest1"],
|
||||
"allowDeviceMockServer": true
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"devices": ["Google Pixel-8.0"],
|
||||
"app": "APPURL",
|
||||
"deviceLogs": true,
|
||||
"networkLogs": true,
|
||||
"testSuite": "TESTURL",
|
||||
"annotation": ["com.naviapp.E2ETest"]
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import groovy.json.JsonSlurper
|
||||
import groovy.json.JsonBuilder
|
||||
|
||||
import java.time.Duration
|
||||
|
||||
plugins {
|
||||
id('com.android.application')
|
||||
id('kotlin-android')
|
||||
@@ -278,10 +280,14 @@ task executeTestsOnBrowserStack {
|
||||
doLast {
|
||||
def jsonParser = new JsonSlurper()
|
||||
|
||||
def apk = testType == "e2e" ? devDebugApk : mockServerDebugApk
|
||||
def testSuite = testType == "e2e" ? devTestApk : mockServerTestApk
|
||||
def configuration = testType == "e2e" ? "e2e" : "mockServer"
|
||||
|
||||
// Upload App
|
||||
def appUrl = new ByteArrayOutputStream().withStream { outputStream ->
|
||||
exec {
|
||||
executable "/bin/sh" args "-c", "curl -u ${bsAuth} -X POST ${bsAppUpload} -F \"file=@${devDebugApk}\" "
|
||||
executable "/bin/sh" args "-c", "curl -u ${bsAuth} -X POST ${bsAppUpload} -F \"file=@${apk}\" "
|
||||
standardOutput = outputStream
|
||||
}
|
||||
|
||||
@@ -291,7 +297,7 @@ task executeTestsOnBrowserStack {
|
||||
// Upload Test-Suite
|
||||
def testUrl = new ByteArrayOutputStream().withStream { outputStream ->
|
||||
exec {
|
||||
executable "/bin/sh" args "-c", "curl -u ${bsAuth} -X POST ${bsTestUpload} -F \"file=@${devTestApk}\" "
|
||||
executable "/bin/sh" args "-c", "curl -u ${bsAuth} -X POST ${bsTestUpload} -F \"file=@${testSuite}\" "
|
||||
standardOutput = outputStream
|
||||
}
|
||||
|
||||
@@ -301,10 +307,13 @@ task executeTestsOnBrowserStack {
|
||||
println("AppUrl: " + appUrl)
|
||||
println("TestUrl: " + testUrl)
|
||||
|
||||
def config = jsonParser.parseText(file(bsE2EConfig).text)
|
||||
def config = jsonParser.parseText(file(bsDeviceConfig).text)[configuration]
|
||||
def device = config.devices[0]
|
||||
println(config)
|
||||
config.app = appUrl
|
||||
config.testSuite = testUrl
|
||||
|
||||
// Execute Tests
|
||||
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}"
|
||||
@@ -322,8 +331,9 @@ task executeTestsOnBrowserStack {
|
||||
// Poll For Test Results
|
||||
def streamOutput = new ByteArrayOutputStream()
|
||||
def status = ""
|
||||
def pollingTimeout = System.currentTimeMillis() + (180 * 1000)
|
||||
def pollingTimeout = System.currentTimeMillis() + Duration.ofMinutes(40).toMillis()
|
||||
|
||||
sleep(60000)
|
||||
while (status != "done" && System.currentTimeMillis() <= pollingTimeout) {
|
||||
exec {
|
||||
executable "/bin/sh" args "-c", "curl -u ${bsAuth} -X GET \"${bsBuilds}${buildId}\""
|
||||
@@ -333,19 +343,31 @@ task executeTestsOnBrowserStack {
|
||||
status = jsonParser.parseText(streamOutput.toString()).status
|
||||
println("Status: " + status)
|
||||
if (status != "done") {
|
||||
sleep(60000)
|
||||
sleep(Duration.ofMinutes(5).toMillis())
|
||||
streamOutput = new ByteArrayOutputStream()
|
||||
}
|
||||
|
||||
if(status == "error") throw GradleException("Error executing Tests")
|
||||
}
|
||||
|
||||
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)
|
||||
def testStatus = buildStatus.devices["${device}"].test_status
|
||||
if(testStatus == null) throw GradleException("Error getting Test Status. Test Status is null")
|
||||
def failedCount = testStatus.FAILED
|
||||
|
||||
if (failedCount > 0) {
|
||||
throw new GradleException(test_status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task executeE2ETests(dependsOn: ['assembleDevDebug', 'assembleDevDebugAndroidTest', 'executeTestsOnBrowserStack'])
|
||||
task executeMockServerTests(dependsOn: ['assembleMockServerDebug', 'assembleMockServerDebugAndroidTest', 'executeTestsOnBrowserStack'])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -21,12 +21,16 @@ android.enableJetifier=true
|
||||
kotlin.code.style=official
|
||||
org.gradle.daemon=true
|
||||
org.gradle.parallel=true
|
||||
annotation=""
|
||||
|
||||
testType=""
|
||||
devDebugApk=build/outputs/apk/dev/debug/app-dev-debug.apk
|
||||
devTestApk=build/outputs/apk/androidTest/dev/debug/app-dev-debug-androidTest.apk
|
||||
mockServerDebugApk=build/outputs/apk/mockServer/debug/app-mockServer-debug.apk
|
||||
mockServerTestApk=build/outputs/apk/androidTest/mockServer/debug/app-mockServer-debug-androidTest.apk
|
||||
|
||||
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
|
||||
bsDeviceConfig=BrowserStackConfig.json
|
||||
Reference in New Issue
Block a user