1
0

web.spec.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // @ts-check
  2. const { test, expect, defineConfig } = require("@playwright/test");
  3. test("button click", async ({ page }) => {
  4. await page.goto("http://localhost:9999");
  5. // Expect the page to contain the counter text.
  6. const main = page.locator("#main");
  7. await expect(main).toContainText("hello axum! 0");
  8. // Expect the title to contain the counter text.
  9. await expect(page).toHaveTitle("hello axum! 0");
  10. // Click the increment button.
  11. let button = page.locator("button.increment-button");
  12. await button.click();
  13. // Expect the page to contain the updated counter text.
  14. await expect(main).toContainText("hello axum! 1");
  15. // Expect the title to contain the updated counter text.
  16. await expect(page).toHaveTitle("hello axum! 1");
  17. });
  18. test("svg", async ({ page }) => {
  19. await page.goto("http://localhost:9999");
  20. // Expect the page to contain the svg.
  21. const svg = page.locator("svg");
  22. // Expect the svg to contain the circle.
  23. const circle = svg.locator("circle");
  24. await expect(circle).toHaveAttribute("cx", "50");
  25. await expect(circle).toHaveAttribute("cy", "50");
  26. await expect(circle).toHaveAttribute("r", "40");
  27. await expect(circle).toHaveAttribute("stroke", "green");
  28. await expect(circle).toHaveAttribute("fill", "yellow");
  29. });
  30. test("raw attribute", async ({ page }) => {
  31. await page.goto("http://localhost:9999");
  32. // Expect the page to contain the div with the raw attribute.
  33. const div = page.locator("div.raw-attribute-div");
  34. await expect(div).toHaveAttribute("raw-attribute", "raw-attribute-value");
  35. });
  36. test("hidden attribute", async ({ page }) => {
  37. await page.goto("http://localhost:9999");
  38. // Expect the page to contain the div with the hidden attribute.
  39. const div = page.locator("div.hidden-attribute-div");
  40. await expect(div).toHaveAttribute("hidden", "true");
  41. });
  42. test("dangerous inner html", async ({ page }) => {
  43. await page.goto("http://localhost:9999");
  44. // Expect the page to contain the div with the dangerous inner html.
  45. const div = page.locator("div.dangerous-inner-html-div");
  46. await expect(div).toContainText("hello dangerous inner html");
  47. });
  48. test("input value", async ({ page }) => {
  49. await page.goto("http://localhost:9999");
  50. // Expect the page to contain the input with the value.
  51. const input = page.locator("input");
  52. await expect(input).toHaveValue("hello input");
  53. });
  54. test("style", async ({ page }) => {
  55. await page.goto("http://localhost:9999");
  56. // Expect the page to contain the div with the style.
  57. const div = page.locator("div.style-div");
  58. await expect(div).toHaveText("colored text");
  59. await expect(div).toHaveCSS("color", "rgb(255, 0, 0)");
  60. });
  61. test("eval", async ({ page }) => {
  62. await page.goto("http://localhost:9999");
  63. // Expect the page to contain the div with the eval and have no text.
  64. const div = page.locator("div.eval-result");
  65. await expect(div).toHaveText("");
  66. // Click the button to run the eval.
  67. let button = page.locator("button.eval-button");
  68. await button.click();
  69. // Check that the title changed.
  70. await expect(page).toHaveTitle("Hello from Dioxus Eval!");
  71. // Check that the div has the eval value.
  72. await expect(div).toHaveText("returned eval value");
  73. });
  74. test("prevent default", async ({ page }) => {
  75. await page.goto("http://localhost:9999");
  76. // Expect the page to contain the div with the eval and have no text.
  77. const a = page.locator("a.prevent-default");
  78. await expect(a).toHaveText("View source");
  79. // Click the <a> element to change the text
  80. await a.click();
  81. // Check that the <a> element changed.
  82. await expect(a).toHaveText("Psych!");
  83. });
  84. test("onmounted", async ({ page }) => {
  85. await page.goto("http://localhost:9999");
  86. // Expect the onmounted event to be called exactly once.
  87. const mountedDiv = page.locator("div.onmounted-div");
  88. await expect(mountedDiv).toHaveText("onmounted was called 1 times");
  89. });