Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.applications;
- import com.microsoft.playwright.*;
- import com.example.config.ConfigurationManager;
- import org.junit.jupiter.api.AfterEach;
- import org.junit.jupiter.api.BeforeEach;
- public abstract class BaseTest {
- protected Playwright playwright;
- protected Browser browser;
- protected Page page;
- @BeforeEach
- void setUp() {
- playwright = Playwright.create();
- String browserType = System.getProperty("browserType", "chromium");
- BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions().setHeadless(false);
- // Check if SSL errors should be ignored from properties file
- boolean ignoreSSL = Boolean.parseBoolean(ConfigurationManager.getProperty("ignoreSSLErrors"));
- switch (browserType) {
- case "firefox":
- browser = playwright.firefox().launch(launchOptions);
- break;
- case "webkit":
- browser = playwright.webkit().launch(launchOptions);
- break;
- case "chromium": // default
- default:
- browser = playwright.chromium().launch(launchOptions);
- }
- Browser.NewContextOptions contextOptions = new Browser.NewContextOptions().setIgnoreHTTPSErrors(ignoreSSL);
- BrowserContext context = browser.newContext(contextOptions); // Create the browser context
- page = context.newPage(); // Create a new page
- page.navigate(getAppUrl()); // Navigate to the application URL
- }
- protected abstract String getAppUrl();
- @AfterEach
- void tearDown() {
- if (page != null) {
- page.close();
- }
- if (browser != null) {
- browser.close();
- }
- if (playwright != null) {
- playwright.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement