Skip to content

Commit

Permalink
update config
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr_Vorobev committed Jan 18, 2024
1 parent 3709a64 commit 9e32e7b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
<maven.surefire.plugin.version>2.22.2</maven.surefire.plugin.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<headless>true</headless>
<!-- app parameters-->
<base.url>https://example.com</base.url>
<headless>true</headless>
<browser>chrome</browser>
<headless>true</headless>
</properties>
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/configuration/Configuration.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

3 changes: 3 additions & 0 deletions src/main/java/pages/BasePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/utilities/DriverFactory.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/test/BaseTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package test;

import configuration.Configuration;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
Expand All @@ -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();
Expand Down

0 comments on commit 9e32e7b

Please sign in to comment.