Last active
February 2, 2022 14:04
-
-
Save OLibutzki/90b75a9479c8425e0df26a6ec4c4e6ad to your computer and use it in GitHub Desktop.
Demonstrates how to run Playwright Java in conjunction with Testcontainers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS com.microsoft.playwright:playwright:1.18.0 | |
//DEPS org.testcontainers:testcontainers:1.16.3 | |
//DEPS org.slf4j:slf4j-nop:1.7.35 | |
import static java.lang.System.out; | |
import org.testcontainers.containers.GenericContainer; | |
import org.testcontainers.containers.wait.strategy.Wait; | |
import org.testcontainers.utility.DockerImageName; | |
import com.microsoft.playwright.Browser; | |
import com.microsoft.playwright.Page; | |
import com.microsoft.playwright.Playwright; | |
public class PlaywrightWithTestcontainers { | |
public static void main( final String... args ) { | |
try ( GenericContainer<?> chrome = new GenericContainer<>( DockerImageName.parse( "browserless/chrome:latest" ) ); | |
Playwright playwright = Playwright.create( ) ) { | |
chrome.withExposedPorts( 3000 ).waitingFor( Wait.forHttp( "/" ) ).start( ); | |
Browser browser = playwright.chromium( ).connect( "ws://" + chrome.getHost( ) + ":" + chrome.getFirstMappedPort( ) + "/playwright" ); | |
try ( Page page = browser.newPage( ) ) { | |
page.navigate( "http://playwright.dev" ); | |
out.println( page.title( ) ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment