You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2026/01/12 07:49:57 UTC

(myfaces-tobago) branch main updated: test(playwright): migrate general tests

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/main by this push:
     new c658e9158e test(playwright): migrate general tests
c658e9158e is described below

commit c658e9158ea3327f728542ffd3b250e9a64dec87
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Sat Jan 10 22:40:43 2026 +0100

    test(playwright): migrate general tests
    
    Migrate the general tests:
    * duplicate id
    * test ???
    * If there is a tobago-header it must be a tobago-footer
    
    Jasmine test removed.
---
 .../src/main/webapp/script/tobago-test.js          | 35 ----------
 .../tobago/example/demo/integration/BasicTest.java | 56 ---------------
 .../src/test/typescript/misc/General.test.ts       | 79 ++++++++++++++++++++++
 3 files changed, 79 insertions(+), 91 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-test.js b/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-test.js
index 45ac85daa0..91a729b426 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/script/tobago-test.js
@@ -77,38 +77,3 @@ beforeEach(function (done) {
   test.do(() => expect("waiting for testframe is done").toBe("waiting for testframe is done"));
   test.start();
 });
-
-describe("general", function () {
-  it("duplicate id", function () {
-    let duplicateIds = getDuplicateIds();
-
-    function getDuplicateIds() {
-      let duplicateIds = [];
-      let iFrame = document.getElementById("page:testframe").contentWindow.document.querySelectorAll("[id]");
-      iFrame.forEach(element => {
-        let sameIdElements = document.getElementById("page:testframe").contentWindow.document
-            .querySelectorAll("[id='" + element.id + "']");
-        if (sameIdElements.length > 1) {
-          duplicateIds.push(element.id);
-        }
-      });
-      return duplicateIds;
-    }
-
-    expect(duplicateIds.length).toBe(0, "duplicate id is from: " + duplicateIds);
-  });
-
-  it("test '???", function () {
-    let result = querySelectorFn("html")().textContent;
-
-    expect(result.indexOf("???")).toBeLessThanOrEqual(-1, "There must no '???' on the site.");
-  });
-
-  it("If there is a tobago-header it must be a tobago-footer", function () {
-    const header = querySelectorFn("tobago-page > form > tobago-header")();
-    const footer = querySelectorFn("tobago-page > form > tobago-footer")();
-    const headerExist = header != null;
-    const footerExist = footer != null;
-    expect(headerExist).toBe(footerExist);
-  });
-});
diff --git a/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/integration/BasicTest.java b/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/integration/BasicTest.java
index c80beeee32..0e4310d4db 100644
--- a/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/integration/BasicTest.java
+++ b/tobago-example/tobago-example-demo/src/test/java/org/apache/myfaces/tobago/example/demo/integration/BasicTest.java
@@ -22,29 +22,19 @@
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.MethodSource;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testcontainers.junit.jupiter.Testcontainers;
 
-import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.lang.invoke.MethodHandles;
 import java.net.MalformedURLException;
 import java.net.URLEncoder;
 import java.net.UnknownHostException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.time.LocalTime;
-import java.util.LinkedList;
 import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 @Testcontainers
 class BasicTest extends FrontendBase {
@@ -99,50 +89,4 @@ void verify404Test() throws MalformedURLException, UnknownHostException, Unsuppo
       }
     }
   }
-
-  /**
-   * Call every page without a specific *.test.js and run general tests (duplicate id, 404, exception, ...).
-   */
-  @ParameterizedTest
-  @MethodSource("basicTestProvider")
-  void basicTest(String path, int testNumber, int testSize)
-      throws MalformedURLException, UnknownHostException, UnsupportedEncodingException {
-
-    final String timeLeft = getTimeLeft(startTime, testSize, testNumber);
-    LOG.info("(" + testNumber + "/" + testSize + " | time left: " + timeLeft + ") - path: " + path);
-
-    final String base = path.substring(0, path.length() - 6);
-    final String url = getTomcatUrl() + "/test.xhtml?base=" + URLEncoder.encode(base, "UTF-8") + "&basicTest=true";
-
-    WebDriver webDriver = getWebDriver();
-    webDriver.get(url);
-
-    List<WebElement> results = getJasmineResults(webDriver, path);
-    parseJasmineResults(results, path);
-  }
-
-  private static Stream<Arguments> basicTestProvider() throws IOException {
-    final List<String> paths = Files.walk(Paths.get("src/main/webapp/content/"))
-        .filter(Files::isRegularFile)
-        .map(Path::toString)
-        .filter(s -> s.endsWith(".xhtml"))
-        .filter(s -> !s.contains("/x-"))
-        .map(s -> s.substring("src/main/webapp/".length()))
-        .sorted()
-        .collect(Collectors.toList());
-
-    for (String standardTestPath : getStandardTestPaths()) {
-      paths.remove(standardTestPath); // already tested by standard test
-    }
-
-    final int testSize = paths.size();
-
-    int testNumber = 1;
-    List<Arguments> arguments = new LinkedList<>();
-    for (String path : paths) {
-      arguments.add(Arguments.of(path, testNumber, testSize));
-      testNumber++;
-    }
-    return arguments.stream();
-  }
 }
diff --git a/tobago-example/tobago-example-demo/src/test/typescript/misc/General.test.ts b/tobago-example/tobago-example-demo/src/test/typescript/misc/General.test.ts
new file mode 100644
index 0000000000..715335d062
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/test/typescript/misc/General.test.ts
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import {expect, test} from "@playwright/test";
+import * as fs from "node:fs";
+import * as path from "node:path";
+
+const webappDir = path.join(__dirname, "../../../main/webapp");
+const contentDir = path.join(webappDir, "content");
+
+function getUrls(webappDir: string, contentDir: string): string[] {
+  const urls: string[] = [];
+  const entries = fs.readdirSync(contentDir, {withFileTypes: true, recursive: true});
+  entries.forEach((entry) => {
+    if (entry.isFile()) {
+      const entryName = entry.name.toLowerCase();
+      if (entryName.endsWith(".xhtml") && !entryName.startsWith("x-")
+          && entryName !== "root_dummy.xhtml") {
+        urls.push(path.sep + path.relative(webappDir, entry.parentPath) + path.sep + entry.name);
+      }
+    }
+  });
+  return urls;
+}
+
+for (const url of getUrls(webappDir, contentDir)) {
+  test.describe(`General tests for ${url}`, () => {
+
+    test.beforeEach(async ({page}, testInfo) => {
+      await page.goto(url);
+    });
+
+    test("Duplicate ID", async ({page}) => {
+      const duplicateIds = await page.evaluate(() => {
+        const ids = Array.from(document.querySelectorAll("[id]")).map(el => el.id);
+        const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index);
+        return Array.from(new Set(duplicates));
+      });
+
+      expect(duplicateIds, `Found duplicate IDs on ${url}: ${duplicateIds.join(", ")}`).toHaveLength(0);
+    });
+
+    test("test '???", async ({page}) => {
+      const textContent = await page.evaluate(() => {
+        return document.querySelector("html").textContent;
+      });
+
+      expect(textContent.indexOf("???"), "There must no '???' on " + url).toBeLessThanOrEqual(-1);
+    });
+
+    test("If there is a tobago-header it must be a tobago-footer", async ({page}) => {
+      const headerExists = await page.evaluate(() => {
+        return document.querySelector("tobago-page > form > tobago-header") !== null;
+      });
+
+      const footerExists = await page.evaluate(() => {
+        return document.querySelector("tobago-page > form > tobago-footer") !== null;
+      });
+
+      expect(headerExists).toBe(footerExists);
+    });
+  });
+}