Skip to content

Commit

Permalink
Add Playwrite module
Browse files Browse the repository at this point in the history
See #149
  • Loading branch information
mkutz committed Jun 7, 2022
1 parent ab2b3e2 commit 0ec00f8
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 2 deletions.
3 changes: 3 additions & 0 deletions manual/src/docs/asciidoc/chapters/09-playwrite.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= Browser Automation with Playwrite

The Playwrite Module provides the link:{javadoc-url}/selenium/org/shakespeareframework/playwrite/BrowseTheWeb.html[BrowseTheWeb Ability], which basically provides a managed https://playwright.dev/java/docs/intro[Playwrite Docs].
3 changes: 2 additions & 1 deletion manual/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ include::chapters/07-reporting.adoc[leveloffset=1]
== Additional Modules

include::chapters/08-selenium.adoc[leveloffset=2]
include::chapters/09-retrofit.adoc[leveloffset=2]
include::chapters/09-playwrite.adoc[leveloffset=2]
include::chapters/10-retrofit.adoc[leveloffset=2]

== Further Reading

Expand Down
32 changes: 32 additions & 0 deletions modules/playwrite/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins {
id 'shakespeare.module'
}

dependencies {
api project(':modules:core')

implementation 'com.microsoft.playwright:playwright:1.17.1'

testImplementation 'org.slf4j:slf4j-api:1.7.36'
testImplementation 'ch.qos.logback:logback-classic:1.2.11'

testImplementation project(':modules:testutils')

testImplementation platform('org.junit:junit-bom:5.8.2')
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

testImplementation 'org.assertj:assertj-core:3.22.0'
}

publishing {
publications {
mavenJava(MavenPublication) {
pom {
name = 'Shakespeare Playwrite'
description = 'Module for browser automation via Playwrite.'
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.shakespeareframework.playwrite;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.Playwright;
import org.shakespeareframework.Ability;

public class BrowseTheWeb implements Ability, AutoCloseable {

private static final Playwright playwright = Playwright.create();

private Browser browser;

Browser getBrowser() {
if (browser == null) {
this.browser = playwright.firefox().launch();
}
return browser;
}

@Override
public void close() {
playwright.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* The central class of the selenium package is the {@link
* org.shakespeareframework.playwrite.BrowseTheWeb} Ability.
*
* @see <a
* href="https://shakespeareframework.org/latest/manual/#_browser_automation_with_playwrite">
* Manual on "Browser Automation with Playwrite"</a>
*/
package org.shakespeareframework.playwrite;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.shakespeareframework.playwrite;

import com.microsoft.playwright.Browser;
import org.junit.jupiter.api.Test;

class BrowseTheWebTest {

@Test
void getBrowserTest1() {
var browseTheWeb = new BrowseTheWeb();
Browser browser = browseTheWeb.getBrowser();
browser.newContext().newPage().navigate("https://shakespeareframework.org");
browseTheWeb.close();
}
}
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
rootProject.name = 'shakespeare'

include 'bom'
include 'manual'
include 'modules:core'
include 'modules:selenium'
include 'modules:retrofit'
include 'modules:testutils'
include 'manual'
include 'modules:playwrite'

0 comments on commit 0ec00f8

Please sign in to comment.