From e5010fbd4f21bf5f5b9f66c44e7bd2426b3268c5 Mon Sep 17 00:00:00 2001 From: Sudarshan GS Date: Fri, 15 May 2020 12:38:09 +0530 Subject: [PATCH] Sudarshan | Added Tasks to run E2E and MockServerTests --- Dockerfile | 6 ++++-- app/BrowserStackConfig.json | 19 +++++++++++++++++ app/BrowserStackE2EConfig.json | 8 ------- app/build.gradle | 38 +++++++++++++++++++++++++++------- gradle.properties | 12 +++++++---- 5 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 app/BrowserStackConfig.json delete mode 100644 app/BrowserStackE2EConfig.json diff --git a/Dockerfile b/Dockerfile index fc71d78da7..04e25ab086 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ diff --git a/app/BrowserStackConfig.json b/app/BrowserStackConfig.json new file mode 100644 index 0000000000..35ea785970 --- /dev/null +++ b/app/BrowserStackConfig.json @@ -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 + } +} \ No newline at end of file diff --git a/app/BrowserStackE2EConfig.json b/app/BrowserStackE2EConfig.json deleted file mode 100644 index 4ab2160dfd..0000000000 --- a/app/BrowserStackE2EConfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "devices": ["Google Pixel-8.0"], - "app": "APPURL", - "deviceLogs": true, - "networkLogs": true, - "testSuite": "TESTURL", - "annotation": ["com.naviapp.E2ETest"] -} \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 6bbc2feb0f..7e3cf1a826 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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']) + + + + + diff --git a/gradle.properties b/gradle.properties index 6bf9ee2c3e..3ece377799 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 \ No newline at end of file +bsDeviceConfig=BrowserStackConfig.json \ No newline at end of file