diff --git a/components/http/PreRequestScript.vue b/components/http/PreRequestScript.vue
index 43e720b19..eba289f05 100644
--- a/components/http/PreRequestScript.vue
+++ b/components/http/PreRequestScript.vue
@@ -62,8 +62,7 @@
{{ $t("helpers.pre_request_script") }}
diff --git a/components/http/Tests.vue b/components/http/Tests.vue
index 7bcd393dc..898255a56 100644
--- a/components/http/Tests.vue
+++ b/components/http/Tests.vue
@@ -62,8 +62,7 @@
{{ $t("helpers.post_request_tests") }}
diff --git a/helpers/preRequestScriptSnippets.js b/helpers/preRequestScriptSnippets.js
index a7590040f..708ac37e4 100644
--- a/helpers/preRequestScriptSnippets.js
+++ b/helpers/preRequestScriptSnippets.js
@@ -1,14 +1,21 @@
export default [
{
- name: "Status code: Status code is 200",
- script: `\n\npw.test("Status code is 200", ()=> {
- pw.expect(pw.response.statusCode).toBe(200);
-});`,
+ name: "Environment: Set an environment variable",
+ script: `\n\n// Set an environment variable
+pw.env.set("variable", "value");`,
},
{
- name: "Response body: Contains string",
- script: `\n\npw.test("Status code is 200", ()=> {
- pw.expect(pw.response.statusCode).toBe(200);
-});`,
+ name: "Environment: Set timestamp variable",
+ script: `\n\n// Set timestamp variable
+const cuttentTime = Date.now();
+pw.env.set("timestamp", cuttentTime.toString());`,
+ },
+ {
+ name: "Environment: Set random number variable",
+ script: `\n\n// Set random number variable
+const min = 1
+const max = 1000
+const randomArbitrary = Math.random() * (max - min) + min
+pw.env.set("randomNumber", randomArbitrary.toString());`,
},
]
diff --git a/helpers/testSnippets.js b/helpers/testSnippets.js
index a7590040f..9b88b9eda 100644
--- a/helpers/testSnippets.js
+++ b/helpers/testSnippets.js
@@ -1,14 +1,45 @@
export default [
{
- name: "Status code: Status code is 200",
- script: `\n\npw.test("Status code is 200", ()=> {
+ name: "Response: Status code is 200",
+ script: `\n\n// Check status code is 200
+pw.test("Status code is 200", ()=> {
pw.expect(pw.response.statusCode).toBe(200);
});`,
},
{
- name: "Response body: Contains string",
- script: `\n\npw.test("Status code is 200", ()=> {
- pw.expect(pw.response.statusCode).toBe(200);
+ name: "Response: Assert property from body",
+ script: `\n\n// Check JSON response property
+pw.test("Status code is 200", ()=> {
+ const body = pw.response.body.json();
+ pw.expect(body.property).toBe("value");
+});`,
+ },
+ {
+ name: "Status code: Status code is 2xx",
+ script: `\n\n// Check status code is 2xx
+pw.test("Status code is 2xx", ()=> {
+ pw.expect(pw.response.statusCode).toBeLevel2xx();
+});`,
+ },
+ {
+ name: "Status code: Status code is 3xx",
+ script: `\n\n// Check status code is 3xx
+pw.test("Status code is 3xx", ()=> {
+ pw.expect(pw.response.statusCode).toBeLevel3xx();
+});`,
+ },
+ {
+ name: "Status code: Status code is 4xx",
+ script: `\n\n// Check status code is 4xx
+pw.test("Status code is 4xx", ()=> {
+ pw.expect(pw.response.statusCode).toBeLevel4xx();
+});`,
+ },
+ {
+ name: "Status code: Status code is 5xx",
+ script: `\n\n// Check status code is 5xx
+pw.test("Status code is 5xx", ()=> {
+ pw.expect(pw.response.statusCode).toBeLevel5xx();
});`,
},
]
diff --git a/locales/en.json b/locales/en.json
index 4639004cd..f2aefd169 100644
--- a/locales/en.json
+++ b/locales/en.json
@@ -248,7 +248,7 @@
},
"preRequest": {
"javascript_code": "JavaScript Code",
- "learn": "Learn how to write pre-request scripts",
+ "learn": "Read documentation",
"script": "Pre-Request Script",
"snippets": "Snippets"
},
@@ -478,7 +478,7 @@
},
"test": {
"javascript_code": "JavaScript Code",
- "learn": "Learn how to write test scripts",
+ "learn": "Read documentation",
"report": "Test Report",
"results": "Test Results",
"script": "Script",