Skip to content

Commit 7bb408b

Browse files
committed
Testing if the git tests passes with initial id of possible changes
1 parent eb534e7 commit 7bb408b

3 files changed

Lines changed: 67 additions & 14 deletions

File tree

core/src/main/kotlin/org/evomaster/core/output/OutputFormat.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum class OutputFormat {
1818
KOTLIN_JUNIT_4,
1919
KOTLIN_JUNIT_5,
2020
JS_JEST,
21+
JS_JEST_PLAYWRIGHT, // Testing new playwright imp
2122
//CSHARP_XUNIT, //no longer supported, but there is still legacy code not removed
2223
PYTHON_UNITTEST
2324
;
@@ -34,6 +35,8 @@ enum class OutputFormat {
3435

3536
fun isJUnit4() = this.name.endsWith("junit_4", true)
3637

38+
fun isPlaywright() = this.name.endsWith("_playwright", true) // Testing new playwright imp
39+
3740
fun isJUnit() = this.name.contains("_junit_", true)
3841

3942
@Deprecated("No longer supported")

core/src/main/kotlin/org/evomaster/core/output/service/HttpWsTestCaseWriter.kt

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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")

core/src/main/kotlin/org/evomaster/core/output/service/TestSuiteWriter.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -532,17 +532,24 @@ class TestSuiteWriter {
532532
}
533533

534534
if (format.isJavaScript()) {
535-
lines.add("const superagent = require(\"superagent\");")
535+
if (format.isPlaywright()) {
536+
lines.add(" - 536 - TestSuiteWriter.kt)")
537+
} else {
538+
lines.add("const superagent = require(\"superagent\");")
539+
}
536540

537541
val jsUtils = JsLoader::class.java.getResource("/$javascriptUtilsFilename").readText()
538542
saveToDisk(jsUtils, Paths.get(config.outputFolder, javascriptUtilsFilename))
539543
lines.add("const $jsImport = require(\"./$javascriptUtilsFilename\");")
544+
lines.add(" - 544 - TestSuiteWriter.kt - What about this const EM thing?. Do we need it?")
540545

541546
if (controllerName != null) {
542547
lines.add("const $controllerName = require(\"${config.jsControllerPath}\");")
548+
lines.add(" - 548 - TestSuiteWriter.kt - What about controllerName. Do we need it?")
543549
}
544550
if (config.testTimeout > 0) {
545551
lines.add("jest.setTimeout(${config.testTimeout * 1000});")
552+
lines.add(" - 552 - TestSuiteWriter.kt - Do we need the jest.setTimeout line above?")
546553
}
547554
}
548555

@@ -727,7 +734,7 @@ class TestSuiteWriter {
727734
lines.add("private lateinit var $driver : RemoteWebDriver")
728735
}
729736

730-
} else if (config.outputFormat.isJavaScript()) {
737+
} else if (config.outputFormat.isJavaScript()) { // Leave as is for Playwright?
731738

732739
if (!config.blackBox || config.bbExperiments) {
733740
lines.add("const $controller = new $controllerName();")
@@ -784,13 +791,14 @@ class TestSuiteWriter {
784791
lines.add("@JvmStatic")
785792
lines.add("fun initClass()")
786793
}
794+
format.isPlaywright() -> lines.add("- 794 - TestSuiteWriter.kt")
787795
format.isJavaScript() -> lines.add("beforeAll( async () =>")
788796
}
789797

790798
lines.block {
791799
if (!config.blackBox) {
792800
when {
793-
config.outputFormat.isJavaScript() -> {
801+
config.outputFormat.isJavaScript() -> { // Add something for playwright white box testing!
794802
addStatement("await $controller.setupForGeneratedTest()", lines)
795803
addStatement("$baseUrlOfSut = await $controller.startSut()", lines)
796804
}
@@ -816,7 +824,7 @@ class TestSuiteWriter {
816824

817825
when {
818826
format.isJavaOrKotlin() -> addStatement("assertNotNull(baseUrlOfSut)", lines)
819-
format.isJavaScript() -> addStatement("expect(baseUrlOfSut).toBeTruthy()", lines)
827+
format.isJavaScript() -> addStatement("expect(baseUrlOfSut).toBeTruthy()", lines) // Add something for playwright white box testing!
820828
}
821829
}
822830

@@ -917,7 +925,7 @@ class TestSuiteWriter {
917925
}
918926

919927
if (format.isJavaScript()) {
920-
lines.append(");")
928+
lines.append(");") // End statement of blocks. Valid for playwright too
921929
}
922930
}
923931

@@ -939,14 +947,14 @@ class TestSuiteWriter {
939947
lines.add("@JvmStatic")
940948
lines.add("fun tearDown()")
941949
}
942-
format.isJavaScript() -> lines.add("afterAll( async () =>")
950+
format.isJavaScript() -> lines.add("afterAll( async () =>") // white box part?
943951
}
944952

945953
if (!format.isCsharp()) {
946954
lines.block {
947955
when {
948956
format.isJavaScript() -> {
949-
addStatement("await $controller.stopSut()", lines)
957+
addStatement("await $controller.stopSut()", lines) // white box part?
950958
}
951959
else -> {
952960
addStatement("$controller.stopSut()", lines)
@@ -971,7 +979,7 @@ class TestSuiteWriter {
971979
}
972980

973981
if (format.isJavaScript()) {
974-
lines.append(");")
982+
lines.append(");") // white box part?
975983
}
976984
}
977985

@@ -992,15 +1000,15 @@ class TestSuiteWriter {
9921000
format.isKotlin() -> {
9931001
lines.add("fun initTest()")
9941002
}
995-
format.isJavaScript() -> lines.add("beforeEach(async () => ")
1003+
format.isJavaScript() -> lines.add("beforeEach(async () => ") // white box part?
9961004
//for C# we are actually setting up the constructor for the test class
9971005
format.isCsharp() -> lines.add("public ${name.getClassName()} ($fixtureClass fixture)")
9981006
}
9991007

10001008

10011009
lines.block {
10021010

1003-
if (format.isJavaScript()) {
1011+
if (format.isJavaScript()) { // white box part?
10041012
//TODO add resetDatabase
10051013
addStatement("await $controller.resetStateOfSUT()", lines)
10061014
} else if (format.isJavaOrKotlin()) {
@@ -1040,7 +1048,7 @@ class TestSuiteWriter {
10401048
}
10411049

10421050
if (format.isJavaScript()) {
1043-
lines.append(");")
1051+
lines.append(");") // white box part?
10441052
}
10451053
}
10461054

0 commit comments

Comments
 (0)