Skip to content

Commit 158e195

Browse files
author
May Kristin Ugelstad
committed
Add Playwright library to core-tests/e2e-tests/spring/spring-rest-bb/javascript and hopefully fix playwright syntax error.
1 parent 8234fc3 commit 158e195

6 files changed

Lines changed: 112 additions & 17 deletions

File tree

core-tests/e2e-tests/spring/spring-rest-bb/javascript/package-lock.json

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core-tests/e2e-tests/spring/spring-rest-bb/javascript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"author": "EvoMaster Team",
77
"license": "LGPL-3.0-only",
88
"devDependencies": {
9+
"@playwright/test": "^1.59.1",
910
"jest": "29.7.0",
1011
"superagent": "9.0.2",
1112
"supertest": "7.0.0",

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,6 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
333333
lines.addSingleCommentLine(statusAssert)
334334
}
335335
lines.addEmpty()
336-
lines.add("const body = await $responseVariableName.json();")
337-
lines.add(" = body;")
338-
lines.addEmpty()
339336
}
340337

341338
format.isJavaScript() && !format.isPlaywright() -> {
@@ -551,18 +548,19 @@ abstract class HttpWsTestCaseWriter : ApiTestCaseWriter() {
551548
lines.indent(2)
552549
if (format.isPlaywright()) {
553550
handleVerbEndpoint(baseUrlOfSut, call, lines)
551+
lines.replaceInCurrent(Regex("\\)$"), "")
554552
lines.append(", {")
555553
lines.addEmpty()
556554
lines.indented {
557555
lines.add("headers: {")
558556
lines.indented {
559-
lines.add("${openAcceptHeader()}${getAcceptHeader(call, res)}")
557+
lines.add(getAcceptHeader(call, res))
560558
handleHeaders(call, lines)
561559
}
562560
lines.add("},")
563561
handleBody(call, lines, dtoVar)
564562
}
565-
lines.add("}")
563+
lines.add("})")
566564
} else {
567565
//in SuperAgent, verb must be first
568566
handleVerbEndpoint(baseUrlOfSut, call, lines)

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,18 @@ class RestTestCaseWriter : HttpWsTestCaseWriter {
221221
val call = _call as RestCallAction
222222
val verb = call.verb.name.lowercase()
223223

224-
if (format.isCsharp()) {
225-
lines.append(".${StringUtils.capitalization(verb)}Async(")
226-
} else if (format.isPlaywright()) {
227-
lines.add("request.$verb(")
228-
} else {
229-
if (verb == "trace" && format.isJavaOrKotlin()) {
230-
//currently, RestAssured does not have a trace() method
231-
lines.add(".request(io.restassured.http.Method.TRACE, ")
232-
} else {
233-
lines.add(".$verb(")
224+
when {
225+
format.isPlaywright() -> {
226+
lines.add("request.$verb(")
227+
}
228+
format.isCsharp() -> lines.append(".${StringUtils.capitalization(verb)}Async(")
229+
else -> {
230+
if (verb == "trace" && format.isJavaOrKotlin()) {
231+
//currently, RestAssured does not have a trace() method
232+
lines.add(".request(io.restassured.http.Method.TRACE, ")
233+
} else {
234+
lines.add(".$verb(")
235+
}
234236
}
235237
}
236238

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ class TestSuiteWriter {
787787
lines.add("fun initClass()")
788788
}
789789
format.isJavaScript() && !format.isPlaywright()-> lines.add("beforeAll( async () =>")
790-
format.isJavaScript() && format.isPlaywright() -> lines.add("test.beforeAll(async ({ request }) =>")
790+
format.isJavaScript() && format.isPlaywright() -> lines.add("(async ({ request }) =>")
791791
}
792792

793793
lines.block {

docs/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ There are 3 types of options:
3939
|`configPath`| __String__. File path for file with configuration settings. Supported formats are YAML and TOML. When EvoMaster starts, it will read such file and import all configurations from it. *Constraints*: `regex .*\.(yml\|yaml\|toml)`. *Default value*: `em.yaml`.|
4040
|`outputFilePrefix`| __String__. The name prefix of generated file(s) with the test cases, without file type extension. In JVM languages, if the name contains '.', folders will be created to represent the given package structure. Also, in JVM languages, should not use '-' in the file name, as not valid symbol for class identifiers. This prefix be combined with the outputFileSuffix to combined the final name. As EvoMaster can split the generated tests among different files, each will get a label, and the names will be in the form prefix+label+suffix. *Constraints*: `regex [-a-zA-Z$_][-0-9a-zA-Z$_]*(.[-a-zA-Z$_][-0-9a-zA-Z$_]*)*`. *Default value*: `EvoMaster`.|
4141
|`outputFileSuffix`| __String__. The name suffix for the generated file(s), to be added before the file type extension. As EvoMaster can split the generated tests among different files, each will get a label, and the names will be in the form prefix+label+suffix. *Constraints*: `regex [-a-zA-Z$_][-0-9a-zA-Z$_]*(.[-a-zA-Z$_][-0-9a-zA-Z$_]*)*`. *Default value*: `Test`.|
42-
|`outputFormat`| __Enum__. Specify in which format the tests should be outputted. If left on `DEFAULT`, for white-box testing then the value specified in the _EvoMaster Driver_ will be used. On the other hand, for black-box testing it will default to a predefined type (e.g., Python). *Valid values*: `DEFAULT, JAVA_JUNIT_5, JAVA_JUNIT_4, KOTLIN_JUNIT_4, KOTLIN_JUNIT_5, JS_JEST, PYTHON_UNITTEST`. *Default value*: `DEFAULT`.|
42+
|`outputFormat`| __Enum__. Specify in which format the tests should be outputted. If left on `DEFAULT`, for white-box testing then the value specified in the _EvoMaster Driver_ will be used. On the other hand, for black-box testing it will default to a predefined type (e.g., Python). *Valid values*: `DEFAULT, JAVA_JUNIT_5, JAVA_JUNIT_4, KOTLIN_JUNIT_4, KOTLIN_JUNIT_5, JS_JEST, JS_JEST_PLAYWRIGHT, PYTHON_UNITTEST`. *Default value*: `DEFAULT`.|
4343
|`testTimeout`| __Int__. Enforce timeout (in seconds) in the generated tests. This feature might not be supported in all frameworks. If 0 or negative, the timeout is not applied. *Default value*: `60`.|
4444
|`blackBox`| __Boolean__. Use EvoMaster in black-box mode. This does not require an EvoMaster Driver up and running. However, you will need to provide further option to specify how to connect to the SUT. *Default value*: `false`.|
4545
|`bbSwaggerUrl`| __String__. When in black-box mode for REST APIs, specify the URL of where the OpenAPI/Swagger schema can be downloaded from. If the schema is on the local machine, you can use a URL starting with 'file://'. If the given URL is neither starting with 'file' nor 'http', then it will be treated as a local file path. *Default value*: `""`.|

0 commit comments

Comments
 (0)