Skip to content

Commit

Permalink
Fix #113: Quarkus Playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Sep 12, 2023
1 parent 7bd33b2 commit ed888a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 58 deletions.
20 changes: 7 additions & 13 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<groupId>io.quarkiverse.playwright</groupId>
<artifactId>quarkus-playwright</artifactId>
<version>0.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.12.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.5.3</version>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -109,4 +103,4 @@
</properties>
</profile>
</profiles>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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!");
}
}

0 comments on commit ed888a7

Please sign in to comment.