Skip to content

Commit

Permalink
Add Playwright support
Browse files Browse the repository at this point in the history
  • Loading branch information
tombrunet committed Sep 6, 2024
1 parent 75552a4 commit 881454d
Show file tree
Hide file tree
Showing 6 changed files with 634 additions and 35 deletions.
38 changes: 36 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ jobs:
###############################################################################
# Java test
####
java-accessibility-checker-test:
java-accessibility-checker-selenium-test:
runs-on: ubuntu-22.04

strategy:
Expand Down Expand Up @@ -392,7 +392,41 @@ jobs:
- run: sleep 10
working-directory: rule-server/dist
- name: Test package
run: mvn --batch-mode test
run: mvn --batch-mode test -Dtest="AccessibilityCheckerSeleniumTest"
working-directory: java-accessibility-checker
env:
chromedriverpath: ${{ steps.setup-chrome.outputs.chromedriver-path }}
chromebinpath: ${{ steps.setup-chrome.outputs.chrome-path }}

java-accessibility-checker-playwright-test:
runs-on: ubuntu-22.04

strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v4
with:
distribution: 'semeru' # See 'Supported distributions' for available options
java-version: '17'
- name: Latest Chrome
uses: browser-actions/setup-chrome@v1
with:
chrome-version: latest
install-chromedriver: true
id: setup-chrome
- run: npm install
working-directory: rule-server
- run: npm run build
working-directory: rule-server
- run: node main.js &
working-directory: rule-server/dist
- run: sleep 10
working-directory: rule-server/dist
- name: Test package
run: mvn --batch-mode test -Dtest="AccessibilityCheckerPlaywrightTest"
working-directory: java-accessibility-checker
env:
chromedriverpath: ${{ steps.setup-chrome.outputs.chromedriver-path }}
Expand Down
45 changes: 27 additions & 18 deletions java-accessibility-checker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>xxxx</version>
<version>5.11.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -51,14 +51,14 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>xxxx</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<!-- <dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>xxxx</version>
<version>5.11.0</version>
<scope>test</scope>
</dependency> -->
<!-- Optionally: parameterized tests support -->
Expand All @@ -70,26 +70,42 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>xxxx</version>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>xxxx</version>
<version>1.7.14</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>xxxx</version>
<version>4.23.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.46.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>com/ibm/able/equalaccess/enginecontext/**</exclude>
</excludes>
</configuration>
</plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>xxxx</version>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -102,7 +118,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>xxxx</version>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -123,7 +139,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>xxxx</version>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -136,7 +152,7 @@
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>xxxx</version>
<version>0.5.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
Expand All @@ -145,14 +161,7 @@
</plugins>

</build>
<!--
<distributionManagement>
<repository>
<id>central</id>
<name>Central Repository OSSRH</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement> -->

<developers>
<developer>
<name>Tom Brunet</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static IEngineContext getEngineContext(Object contentContext) {
if (contentContext == null) {
engineContext = new EngineContextLocal();
}
// See if this is Selenium and we can load it
if (engineContext == null
&& Misc.classIsAvailable("org.openqa.selenium.WebDriver"))
{
Expand All @@ -56,6 +57,30 @@ public static IEngineContext getEngineContext(Object contentContext) {
} catch (InvocationTargetException e) {
}
}
// See if this is Playwright and we can load it
if (engineContext == null
&& Misc.classIsAvailable("com.microsoft.playwright.Page"))
{
if (!Misc.classIsAvailable("com.ibm.able.equalaccess.enginecontext.playwright.EngineContextPlaywright")) {
System.err.println("Attempted scan with Page, but com.ibm.able.equalaccess.enginecontext.playwright.EngineContextPlaywright could not be loaded");
throw new ACError("Attempted scan with Page, but com.ibm.able.equalaccess.enginecontext.playwright.EngineContextPlaywright could not be loaded");
}
try {
Class<?> playwrightPageClass = Class.forName("com.microsoft.playwright.Page");
if (playwrightPageClass.isAssignableFrom(contentContext.getClass())) {
// We have a webdriver, use EngineContextSelenium to instantiate it
Class<?> ecClass = Class.forName("com.ibm.able.equalaccess.enginecontext.playwright.EngineContextPlaywright");
engineContext = (IEngineContext) ecClass.getConstructor(playwrightPageClass).newInstance(contentContext);
}
} catch (ClassNotFoundException e) {
} catch (NoSuchMethodException e) {
} catch (SecurityException e) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
}
}
if (engineContext != null) {
engineContext.loadEngine();
} else {
Expand Down
Loading

0 comments on commit 881454d

Please sign in to comment.