Skip to content

Commit

Permalink
Fix properties file reading
Browse files Browse the repository at this point in the history
  • Loading branch information
burakkaygusuz committed Oct 26, 2023
1 parent 8f65a74 commit 976412c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 74 deletions.
10 changes: 0 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@
<version>${assertj-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>${commons-beanutils.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
<version>${commons-configuration2.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
59 changes: 0 additions & 59 deletions src/main/java/io/github/burakkaygusuz/utils/ConfigurationUtil.java

This file was deleted.

34 changes: 34 additions & 0 deletions src/main/java/io/github/burakkaygusuz/utils/PropertyUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.burakkaygusuz.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertyUtil {

private static volatile PropertyUtil instance = null;
private final Properties properties;

private PropertyUtil(String fileName) {
this.properties = new Properties();
try (InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(fileName)) {
properties.load(inputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static PropertyUtil getInstance(String fileName) {
if (instance == null) {
synchronized (PropertyUtil.class) {
if (instance == null)
instance = new PropertyUtil(fileName);
}
}
return instance;
}

public String getProperty(String key) {
return properties.getProperty(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FormAuthenticationTest extends TestBase {

@Test(testName = "Login Test")
void loginTest() {
driver.get(config.getString("BASE_URL"));
driver.get(props.getProperty("BASE_URL"));
assertThat(driver.getTitle()).isEqualTo("The Internet");

final By loginPageLinkTextLocator = By.linkText("Form Authentication");
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/github/burakkaygusuz/tests/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import io.github.burakkaygusuz.config.WebDriverBuilder;
import io.github.burakkaygusuz.listeners.CustomTestListener;
import io.github.burakkaygusuz.utils.ConfigurationUtil;
import io.github.burakkaygusuz.utils.PropertyUtil;
import io.github.burakkaygusuz.webElements.WebElementService;
import org.apache.commons.configuration2.Configuration;
import org.apache.logging.log4j.ThreadContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
Expand All @@ -19,7 +18,8 @@

@Listeners({ CustomTestListener.class })
public class TestBase {
protected Configuration config = ConfigurationUtil.getInstance().getConfiguration();

protected PropertyUtil props = PropertyUtil.getInstance("config.properties");
protected WebDriver driver;
protected WebDriverWait wait;
protected WebElementService webElementService;
Expand All @@ -29,7 +29,7 @@ public class TestBase {
public void setUp(String browser) throws MalformedURLException, URISyntaxException {
ThreadContext.put("browser", browser.toUpperCase());
driver = new WebDriverBuilder(browser)
.setUrl(config.getString("GRID_URL"))
.setUrl(props.getProperty("GRID_URL"))
.enableHeadless()
.enableTracing(false)
.build();
Expand Down

0 comments on commit 976412c

Please sign in to comment.