testSnippets.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. export default [
  2. {
  3. name: "Environment: Set an environment variable",
  4. script: `\n\n// Set an environment variable
  5. pw.env.set("variable", "value");`,
  6. },
  7. {
  8. name: "Response: Status code is 200",
  9. script: `\n\n// Check status code is 200
  10. pw.test("Status code is 200", ()=> {
  11. pw.expect(pw.response.status).toBe(200);
  12. });`,
  13. },
  14. {
  15. name: "Response: Assert property from body",
  16. script: `\n\n// Check JSON response property
  17. pw.test("Check JSON response property", ()=> {
  18. pw.expect(pw.response.body.method).toBe("GET");
  19. });`,
  20. },
  21. {
  22. name: "Status code: Status code is 2xx",
  23. script: `\n\n// Check status code is 2xx
  24. pw.test("Status code is 2xx", ()=> {
  25. pw.expect(pw.response.status).toBeLevel2xx();
  26. });`,
  27. },
  28. {
  29. name: "Status code: Status code is 3xx",
  30. script: `\n\n// Check status code is 3xx
  31. pw.test("Status code is 3xx", ()=> {
  32. pw.expect(pw.response.status).toBeLevel3xx();
  33. });`,
  34. },
  35. {
  36. name: "Status code: Status code is 4xx",
  37. script: `\n\n// Check status code is 4xx
  38. pw.test("Status code is 4xx", ()=> {
  39. pw.expect(pw.response.status).toBeLevel4xx();
  40. });`,
  41. },
  42. {
  43. name: "Status code: Status code is 5xx",
  44. script: `\n\n// Check status code is 5xx
  45. pw.test("Status code is 5xx", ()=> {
  46. pw.expect(pw.response.status).toBeLevel5xx();
  47. });`,
  48. },
  49. ]