diff --git a/.github/workflows/run-debug-test.yaml b/.github/workflows/run-debug-test.yaml index 5774189e..5cfd2bb1 100644 --- a/.github/workflows/run-debug-test.yaml +++ b/.github/workflows/run-debug-test.yaml @@ -33,5 +33,5 @@ jobs: - uses: actions/upload-artifact@v3 with: name: ux-test-error_${{ matrix.os }} - path: ux-and-transport-test/test-error.png + path: ux-and-transport-test/test-error-screenshot if: ${{ always() }} diff --git a/.github/workflows/run-test.yaml b/.github/workflows/run-test.yaml index 759c31a3..7115fed0 100644 --- a/.github/workflows/run-test.yaml +++ b/.github/workflows/run-test.yaml @@ -37,5 +37,5 @@ jobs: - uses: actions/upload-artifact@v3 with: name: ux-test-error_${{ matrix.os }} - path: ux-and-transport-test/test-error.png + path: ux-and-transport-test/test-error-screenshot if: ${{ always() }} diff --git a/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/GrpcRequestResponseTest.kt b/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/GrpcRequestResponseTest.kt index c655b7a3..91109de8 100644 --- a/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/GrpcRequestResponseTest.kt +++ b/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/GrpcRequestResponseTest.kt @@ -256,7 +256,14 @@ class GrpcRequestResponseTest(testName: String, isSsl: Boolean, isMTls: Boolean) { "data": ${it + 100} } - """.trimIndent(), getResponseBody()) + """.trimIndent(), + try { + getResponseBody() + } catch (e: AssertionError) { + captureScreenToFile("bidirectionalStreaming") + throw e + } + ) assertStatus("Communicating") } completeRequest() diff --git a/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/RequestResponseTestUtil.kt b/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/RequestResponseTestUtil.kt index 3f5b6812..563d208e 100644 --- a/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/RequestResponseTestUtil.kt +++ b/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/RequestResponseTestUtil.kt @@ -467,7 +467,7 @@ suspend fun DesktopComposeUiTest.createEnvironmentInEnvDialog(name: String) { } catch (e: ComposeTimeoutException) { // val screenshot = captureToImage().asSkiaBitmap().toBufferedImage().toImage() // File("test-error.png").writeBytes(screenshot.encodeToData(EncodedImageFormat.PNG)!!.bytes) - captureScreenToFile() + captureScreenToFile("createEnvironmentInEnvDialog") throw e } @@ -1245,7 +1245,9 @@ fun SemanticsNodeInteraction.performTextInput(host: ComposeUiTest, s: String) { } } -fun captureScreenToFile() { +fun captureScreenToFile(filename: String) { val image = Robot().createScreenCapture(Rectangle(Toolkit.getDefaultToolkit().screenSize)) - File("test-error.png").writeBytes(image.toImage().encodeToData(EncodedImageFormat.PNG)!!.bytes) + val parent = File("test-error-screenshot") + .also { it.mkdirs() } + File(parent, "$filename.png").writeBytes(image.toImage().encodeToData(EncodedImageFormat.PNG)!!.bytes) } diff --git a/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/WebSocketRequestResponseTest.kt b/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/WebSocketRequestResponseTest.kt index 84bc73a7..043972d5 100644 --- a/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/WebSocketRequestResponseTest.kt +++ b/ux-and-transport-test/src/test/kotlin/com/sunnychung/application/multiplatform/hellohttp/test/WebSocketRequestResponseTest.kt @@ -2,6 +2,7 @@ package com.sunnychung.application.multiplatform.hellohttp.test +import androidx.compose.ui.test.ComposeTimeoutException import androidx.compose.ui.test.ComposeUiTest import androidx.compose.ui.test.DesktopComposeUiTest import androidx.compose.ui.test.ExperimentalTestApi @@ -69,23 +70,32 @@ class WebSocketRequestResponseTest(testName: String, isSsl: Boolean, isMTls: Boo @Test fun sendAndReceivePayloads() = runTest { val request = createAndFireWebSocketRequest(environment = environment) + wait(500.milliseconds()) assertHttpStatus() - sendPayload("abc", isCreatePayloadExample = false) - waitUntil(400.milliseconds().millis) { getResponseBody() == "Hello abc" } - sendPayload("defg\nhi") - waitUntil(400.milliseconds().millis) { getResponseBody() == "Hello defg\nhi" } - sendPayload("中文字") - waitUntil(400.milliseconds().millis) { getResponseBody() == "Hello 中文字" } - sendPayload("Yeah 😎🍣✌🏽!!") - waitUntil(400.milliseconds().millis) { getResponseBody() == "Hello Yeah \uD83D\uDE0E\uD83C\uDF63✌\uD83C\uDFFD!!" } - - sendPayload("!echo") - waitUntil(400.milliseconds().millis) { getResponseBody() != "Hello Yeah \uD83D\uDE0E\uD83C\uDF63✌\uD83C\uDFFD!!" } - verifyEchoResponse(request, getResponseBody()!!) - - sendPayload("aaaaa") - waitUntil(400.milliseconds().millis) { getResponseBody() == "Hello aaaaa" } + try { + sendPayload("abc", isCreatePayloadExample = false) + waitUntil(400.milliseconds().millis) { getResponseBody() == "Hello abc" } + sendPayload("defg\nhi") + waitUntil(400.milliseconds().millis) { getResponseBody() == "Hello defg\nhi" } + sendPayload("中文字") + waitUntil(400.milliseconds().millis) { getResponseBody() == "Hello 中文字" } + sendPayload("Yeah 😎🍣✌🏽!!") + waitUntil(400.milliseconds().millis) { getResponseBody() == "Hello Yeah \uD83D\uDE0E\uD83C\uDF63✌\uD83C\uDFFD!!" } + + sendPayload("!echo") + waitUntil(400.milliseconds().millis) { getResponseBody() != "Hello Yeah \uD83D\uDE0E\uD83C\uDF63✌\uD83C\uDFFD!!" } + verifyEchoResponse(request, getResponseBody()!!) + + sendPayload("aaaaa") + waitUntil(400.milliseconds().millis) { getResponseBody() == "Hello aaaaa" } + } catch (e: AssertionError) { + captureScreenToFile("sendAndReceivePayloads") + throw e + } catch (e: ComposeTimeoutException) { + captureScreenToFile("sendAndReceivePayloads") + throw e + } disconnect() }