@@ -60,6 +60,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
6060 fun startRequest (lines : Lines ){
6161 when {
6262 format.isJavaOrKotlin() -> lines.append(" given()" )
63+ format.isPlaywright() -> lines.append(" -64 HttpWsTestCaseWriter.kt- " )
6364 format.isJavaScript() -> lines.append(" await superagent" )
6465 format.isCsharp() -> lines.append(" await Client" )
6566 format.isPython() -> lines.append(" requests \\ " )
@@ -103,6 +104,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
103104 when {
104105 format.isKotlin() -> lines.append(" val $resVarName : ValidatableResponse = " )
105106 format.isJava() -> lines.append(" ValidatableResponse $resVarName = " )
107+ format.isPlaywright() -> lines.append(" -108 HttpWsTestCaseWriter.kt- " )
106108 format.isJavaScript() -> lines.append(" const $resVarName = " )
107109 format.isPython() -> lines.append(" $resVarName = " )
108110 format.isCsharp() -> lines.append(" var $resVarName = " )
@@ -111,6 +113,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
111113
112114 when {
113115 format.isJavaOrKotlin() -> lines.append(" given()" )
116+ format.isPlaywright() -> lines.append(" -117 HttpWsTestCaseWriter.kt- " )
114117 format.isJavaScript() -> lines.append(" await superagent" )
115118 format.isCsharp() -> lines.append(" await Client" )
116119 format.isPython() -> lines.append(" requests \\ " )
@@ -186,6 +189,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
186189 protected fun openAcceptHeader (): String {
187190 return when {
188191 format.isJavaOrKotlin() -> " .accept("
192+ format.isPlaywright() -> " -193 HttpWsTestCaseWriter.kt- "
189193 format.isJavaScript() -> " .set('Accept', "
190194 format.isCsharp() -> " Client.DefaultRequestHeaders.Add(\" Accept\" , "
191195 format.isPython() -> " headers['Accept'] = "
@@ -227,6 +231,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
227231
228232 val set = when {
229233 format.isJavaOrKotlin() -> " header"
234+ format.isPlaywright() -> " -235 HttpWsTestCaseWriter.kt- "
230235 format.isJavaScript() -> " set"
231236 format.isPython() -> " headers = {}"
232237 else -> throw IllegalArgumentException (" Not supported format: $format " )
@@ -276,6 +281,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
276281 } else {
277282 when {
278283 format.isJavaOrKotlin() -> lines.add(" .cookies(${CookieWriter .cookiesName(elc)} )" )
284+ format.isPlaywright() -> lines.add(" -285 HttpWsTestCaseWriter.kt- " )
279285 format.isJavaScript() -> lines.add(" .set('Cookie', ${CookieWriter .cookiesName(elc)} )" )
280286 // Python cookies are set alongside the headers and body when performing the request
281287 }
@@ -303,7 +309,17 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
303309 val code = res.getStatusCode()
304310
305311 when {
306- format.isJavaScript() -> {
312+
313+ format.isJavaScript() && format.isPlaywright() -> { // This need a re-write!
314+ val statusAssert = " - 314 - HttpWsTestCaseWriter.kt- "
315+ if (res.getFlakyStatusCode() == null ){
316+ lines.add(statusAssert)
317+ }else {
318+ lines.addSingleCommentLine(flakyInfo(" Status Code" , code.toString(), res.getFlakyStatusCode().toString()))
319+ lines.addSingleCommentLine(statusAssert)
320+ }
321+ }
322+ format.isJavaScript() && ! format.isPlaywright()-> {
307323 val statusAssert = " expect($responseVariableName .status).toBe($code );"
308324 if (res.getFlakyStatusCode() == null ){
309325 lines.add(statusAssert)
@@ -436,8 +452,10 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
436452 lines.addStatement(" val $varName = System.currentTimeMillis()" )
437453 } else if (format.isPython()) {
438454 lines.addStatement(" $varName = time.perf_counter() * 1000" )
455+ } else if (format.isPlaywright()) {
456+ lines.addStatement(" -456 HttpWsTestCaseWriter.kt- " )
439457 } else if (format.isJavaScript()) {
440- lines.addStatement(" $varName = performance.now()" ) // just for test!!!
458+ lines.addStatement(" $varName = performance.now()" )
441459 }
442460 lines.addEmpty(1 )
443461
@@ -455,6 +473,8 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
455473 lines.addStatement(" val $finalVarName = System.currentTimeMillis() - $varName " )
456474 } else if (format.isPython()) {
457475 lines.addStatement(" $finalVarName = (time.perf_counter() * 1000) - $varName " )
476+ } else if (format.isPlaywright()) {
477+ lines.addStatement(" -477 HttpWsTestCaseWriter.kt- " )
458478 } else if (format.isJavaScript()) {
459479 lines.addStatement(" $finalVarName = performance.now() - $varName " )
460480 }
@@ -466,6 +486,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
466486 lines.addSingleCommentLine(" Note: SQL Injection vulnerability detected in this call. Expected response time (sqliInjectedSleepDurationMs) should be greater than ${config.sqliInjectedSleepDurationMs} ms." )
467487 when {
468488 format.isJavaOrKotlin() -> lines.addStatement(" assertTrue($finalVarName > ${config.sqliInjectedSleepDurationMs} )" )
489+ format.isPlaywright() -> lines.addStatement(" -489 HttpWsTestCaseWriter.kt- " )
469490 format.isJavaScript() -> lines.addStatement(" expect($finalVarName ).toBeGreaterThan(${config.sqliInjectedSleepDurationMs} )" )
470491 format.isPython() -> lines.addStatement(" assert $finalVarName > ${config.sqliInjectedSleepDurationMs} " )
471492 else -> {}
@@ -474,6 +495,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
474495 lines.addSingleCommentLine(" Note: No SQL Injection vulnerability detected in this call. Expected response time (sqliBaselineMaxResponseTimeMs) should be less than ${config.sqliBaselineMaxResponseTimeMs} ms." )
475496 when {
476497 format.isJavaOrKotlin() -> lines.addStatement(" assertTrue($finalVarName < ${config.sqliBaselineMaxResponseTimeMs} )" )
498+ format.isPlaywright() -> lines.addStatement(" -498 HttpWsTestCaseWriter.kt- " )
477499 format.isJavaScript() -> lines.addStatement(" expect($finalVarName ).toBeLessThan(${config.sqliBaselineMaxResponseTimeMs} )" )
478500 format.isPython() -> lines.addStatement(" assert $finalVarName < ${config.sqliBaselineMaxResponseTimeMs} " )
479501 else -> {}
@@ -513,6 +535,15 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
513535 lines.append(getAcceptHeader(call, res))
514536 handleHeaders(call, lines)
515537 handleBody(call, lines)
538+ if (format.isPlaywright()) { // This needs to be checked!
539+ lines.append(" -539 HttpWsTestCaseWriter.kt- " )
540+ } else {
541+ // in SuperAgent, verb must be first
542+ handleVerbEndpoint(baseUrlOfSut, call, lines)
543+ lines.append(getAcceptHeader(call, res))
544+ handleHeaders(call, lines)
545+ handleBody(call, lines)
546+ }
516547 }
517548
518549 format.isCsharp() -> {
@@ -540,6 +571,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
540571 fun sendBodyCommand (): String {
541572 return when {
542573 format.isJavaOrKotlin() -> " body"
574+ format.isPlaywright() -> " - 574 - HttpWsTestCaseWriter.kt"
543575 format.isJavaScript() -> " send"
544576 format.isCsharp() -> " "
545577 format.isPython() -> " "
@@ -562,6 +594,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
562594
563595 when {
564596 format.isJavaOrKotlin() -> lines.add(" .contentType(\" ${bodyParam.contentType()} \" )" )
597+ format.isPlaywright() -> lines.add(" - 597 - HttpWsTestCaseWriter.kt- " )
565598 format.isJavaScript() -> lines.add(" .set('Content-Type','${bodyParam.contentType()} ')" )
566599 format.isPython() -> lines.add(" headers[\" content-type\" ] = \" ${bodyParam.contentType()} \" " )
567600 }
@@ -809,6 +842,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
809842
810843 val instruction = when {
811844 format.isJavaOrKotlin() -> " .contentType(\" $bodyTypeSimplified \" )"
845+ format.isPlaywright() -> " - 845 - HttpWsTestCaseWriter.kt - "
812846 format.isJavaScript() ->
813847 " expect($responseVariableName .header[\" content-type\" ].startsWith(\" $bodyTypeSimplified \" )).toBe(true);"
814848
@@ -874,12 +908,19 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
874908
875909 protected fun handleLastLine (call : HttpWsAction , res : HttpWsCallResult , lines : Lines , resVarName : String ) {
876910
877- if (format.isJavaScript ()) {
911+ if (format.isPlaywright ()) {
878912 /*
879913 This is to deal with very weird behavior in SuperAgent that crashes the tests
880914 for status codes different from 2xx...
881915 so, here we make it passes as long as a status was present
882916 */
917+ lines.add(" - 917 - HttpWsTestCaseWriter.kt - " )
918+
919+ } else if (format.isJavaScript()) {
920+ /*
921+ This is to deal with very weird behavior in SuperAgent that crashes the tests
922+ for status codes different from 2xx...
923+ */
883924 lines.add(" .ok(res => res.status)" )
884925 }
885926
@@ -931,6 +972,7 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
931972
932973 return when {
933974 format.isPython() -> " str($resVarName .json()${JsonUtils .fromPointerToDictionaryAccess(jsonPointer)} )"
975+ format.isPlaywright() -> " - 975 - HttpWsTestCaseWriter.kt - "
934976 format.isJavaScript() -> " $resVarName .body.$jsonPath .toString()"
935977 format.isJavaOrKotlin() -> " $resVarName .extract().body().path$extraTypeInfo (\" $jsonPath \" ).toString()"
936978 else -> throw IllegalStateException (" Unsupported format $format " )
0 commit comments