diff --git a/pom.xml b/pom.xml index c017a7e..cd77465 100644 --- a/pom.xml +++ b/pom.xml @@ -20,8 +20,9 @@ 2.22.2 11 11 - true + https://example.com + true chrome true diff --git a/src/main/java/configuration/Configuration.java b/src/main/java/configuration/Configuration.java new file mode 100644 index 0000000..1d1143c --- /dev/null +++ b/src/main/java/configuration/Configuration.java @@ -0,0 +1,39 @@ +package configuration; + +import static java.lang.Boolean.parseBoolean; + +public class Configuration { + private static final Configuration INSTANCE = new Configuration(); + + private final String baseUrl; + private final String browser; + private final boolean headless; + + private Configuration() { + // Initialize configuration properties + this.baseUrl = getProperty("base.url", "https://example.com"); + this.browser = getProperty("browser", "chrome"); + this.headless = parseBoolean(getProperty("headless", "true")); + } + + public static Configuration getInstance() { + return INSTANCE; + } + + public String getBaseUrl() { + return baseUrl; + } + + public String getBrowser() { + return browser; + } + + public boolean isHeadless() { + return headless; + } + + private String getProperty(String propertyName, String defaultValue) { + return System.getProperty(propertyName, defaultValue); + } +} + diff --git a/src/main/java/pages/BasePage.java b/src/main/java/pages/BasePage.java index 8bb6aff..601fb64 100644 --- a/src/main/java/pages/BasePage.java +++ b/src/main/java/pages/BasePage.java @@ -2,6 +2,7 @@ import java.util.List; +import configuration.Configuration; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.PageFactory; @@ -18,6 +19,8 @@ public abstract class BasePage { public BasePage(WebDriver driver, String path) { this.driver = driver; this.path = path; + baseUrl = Configuration.getInstance() + .getBaseUrl(); PageFactory.initElements(driver, this); } diff --git a/src/main/java/utilities/DriverFactory.java b/src/main/java/utilities/DriverFactory.java index ec2f15a..d1000b5 100644 --- a/src/main/java/utilities/DriverFactory.java +++ b/src/main/java/utilities/DriverFactory.java @@ -1,5 +1,6 @@ package utilities; +import configuration.Configuration; import io.github.bonigarcia.wdm.WebDriverManager; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; @@ -25,7 +26,8 @@ public static WebDriver getDriver(String browserName) { } switch (browserName.toLowerCase()) { case CHROME: - boolean headlessMode = Boolean.parseBoolean(System.getProperty("headless", "true")); + boolean headlessMode = Configuration.getInstance() + .isHeadless(); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--no-sandbox"); chromeOptions.addArguments("--window-size=1920x1080"); diff --git a/src/test/java/test/BaseTest.java b/src/test/java/test/BaseTest.java index 01e6201..349368e 100644 --- a/src/test/java/test/BaseTest.java +++ b/src/test/java/test/BaseTest.java @@ -1,5 +1,6 @@ package test; +import configuration.Configuration; import org.openqa.selenium.WebDriver; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -11,13 +12,13 @@ public abstract class BaseTest { protected WebDriver driver; protected String baseUrl; - protected String browser = System.getProperty("browser", "chrome"); - ; @BeforeMethod public void setUp() { - baseUrl = System.getProperty("base.url", "https://example.com"); - driver = DriverFactory.getDriver(browser); + baseUrl = Configuration.getInstance() + .getBaseUrl(); + driver = DriverFactory.getDriver(Configuration.getInstance() + .getBrowser()); driver.manage() .window() .maximize();