Skip to content

Commit

Permalink
debug UX tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny-chung committed Nov 13, 2024
1 parent b3a5d76 commit 46671ed
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-debug-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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() }}
2 changes: 1 addition & 1 deletion .github/workflows/run-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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() }}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 46671ed

Please sign in to comment.