From ed888a7a347d9a0c2435b487cf040c921f84b92b Mon Sep 17 00:00:00 2001 From: melloware Date: Tue, 12 Sep 2023 16:15:02 -0400 Subject: [PATCH] Fix #113: Quarkus Playwright --- integration-tests/pom.xml | 20 ++---- .../omnifaces/it/OmnifacesResourceTest.java | 68 +++++++------------ 2 files changed, 30 insertions(+), 58 deletions(-) diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 8c20e7d..146297a 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -29,21 +29,15 @@ test - org.assertj - assertj-core - 3.24.2 + io.quarkiverse.playwright + quarkus-playwright + 0.0.1 test - org.seleniumhq.selenium - selenium-java - 4.12.1 - test - - - io.github.bonigarcia - webdrivermanager - 5.5.3 + org.assertj + assertj-core + 3.24.2 test @@ -109,4 +103,4 @@ - + \ No newline at end of file diff --git a/integration-tests/src/test/java/io/quarkiverse/omnifaces/it/OmnifacesResourceTest.java b/integration-tests/src/test/java/io/quarkiverse/omnifaces/it/OmnifacesResourceTest.java index d0a95a1..f992330 100644 --- a/integration-tests/src/test/java/io/quarkiverse/omnifaces/it/OmnifacesResourceTest.java +++ b/integration-tests/src/test/java/io/quarkiverse/omnifaces/it/OmnifacesResourceTest.java @@ -3,65 +3,43 @@ import static org.assertj.core.api.Assertions.assertThat; import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.PageLoadStrategy; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; -import io.github.bonigarcia.wdm.WebDriverManager; +import com.microsoft.playwright.BrowserContext; +import com.microsoft.playwright.Locator; +import com.microsoft.playwright.Page; +import com.microsoft.playwright.Response; + +import io.quarkiverse.playwright.InjectPlaywright; +import io.quarkiverse.playwright.WithPlaywright; import io.quarkus.test.common.http.TestHTTPResource; import io.quarkus.test.junit.QuarkusTest; @QuarkusTest +@WithPlaywright public class OmnifacesResourceTest { - @TestHTTPResource - URL url; + @InjectPlaywright + BrowserContext context; - static WebDriver driver; + @TestHTTPResource("/index.xhtml") + URL index; - @BeforeAll - public static void initWebClient() { - WebDriverManager.chromedriver().setup(); - } + @Test + public void shouldOpenIndexPage() throws Exception { + final Page page = context.newPage(); + Response response = page.navigate(index.toString()); + Assertions.assertEquals("OK", response.statusText()); - @BeforeEach - void setup() { - ChromeOptions chromeOptions = new ChromeOptions(); - chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL); - chromeOptions.addArguments("--headless=new"); - chromeOptions.addArguments("--remote-allow-origins=*"); - Map chromePrefs = new HashMap<>(); - chromePrefs.put("download.prompt_for_download", false); - chromePrefs.put("download.directory_upgrade", true); - chromePrefs.put("safebrowsing.enabled", true); - chromePrefs.put("profile.default_content_settings.popups", 0); - chromePrefs.put("download.default_directory", System.getProperty("java.io.tmpdir")); - chromeOptions.setExperimentalOption("prefs", chromePrefs); - driver = new ChromeDriver(chromeOptions); + page.waitForLoadState(); - } + String title = page.title(); + Assertions.assertEquals("Quarkiverse OmniFaces", title); - @AfterAll - public static void closeWebClient() { - driver.quit(); - } - - @Test - public void shouldOpenIndexPage() throws Exception { - driver.get(url + "/index.xhtml"); - assertThat(driver.getTitle()).isEqualTo("Quarkiverse OmniFaces"); - final WebElement message = driver.findElement(By.id("message")); + Locator message = page.locator("#message"); assertThat(message).isNotNull(); - assertThat(message.getText()).isEqualTo("Hello from OmniFaces ViewScope!"); + assertThat(message.innerText()).isEqualTo("Hello from OmniFaces ViewScope!"); } }