Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Selcukes.yaml file for all configs #105

Merged
merged 12 commits into from
May 6, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@

@JsonIgnoreProperties(ignoreUnknown = true)
@Data
@DataFile(fileName = "selcukes.yaml", folderPath = "src/main/resources")
@DataFile(fileName = "selcukes.yaml")
public class Environment {
private String projectName;
private String env;
private String baseUrl;
private Map<String, String> excelRunner;
private Map<String, String> excel;
private Map<String, String> cucumber;
private Map<String, String> web;
private Map<String, String> windows;
private Map<String, String> mobile;
private Map<String, String> reports;
private Map<String, String> video;
private Map<String, String> notifier;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -40,8 +41,8 @@ public static Map<String, String> readAsMap(final String propertyFile) {

public static LinkedProperties getProperties(final String propertyFile) {
LinkedProperties properties = new LinkedProperties();
try {
properties.load(ConfigFactory.getStream(propertyFile));
try (InputStream stream = ConfigFactory.getStream(propertyFile)) {
properties.load(stream);
} catch (IOException e) {
throw new ConfigurationException("Could not parse property file '" + propertyFile + "'", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,50 @@
import io.github.selcukes.databind.utils.StringHelper;
import lombok.CustomLog;

import java.util.Map;
import static io.github.selcukes.commons.config.ConfigFactory.getConfig;

@CustomLog
public class SelcukesTestProperties {
public static final String EXCEL_RUNNER = "selcukes.excel.runner";
public static final String EXCEL_SUITE_NAME = "selcukes.excel.suiteName";
public static final String EXCEL_SUITE_FILE = "selcukes.excel.suiteFile";
public static final String EXTENT_REPORT = "selcukes.extent.report";
public static final String FEATURES = "selcukes.features";
public static final String GLUE = "selcukes.glue";
public static final String TAGS = "selcukes.tags";
public static final String PLUGIN = "selcukes.plugin";
public static final String EMAIL_REPORT = "selcukes.reports.emailReport";
public static final String HTML_REPORT = "selcukes.reports.htmlReport";
public static final String REPORTS_PATH = "selcukes.reports.path";
public static final String TIMESTAMP_REPORT = "selcukes.timestamp.report";
private final Map<String, String> properties;
public static final String REPORTS_FILE = "selcukes.reports.fileName";
public static final String TIMESTAMP_REPORT = "selcukes.reports.timestamp";

public SelcukesTestProperties() {
properties = PropertiesMapper
.readAsMap("selcukes.properties");
public static void setSystemProperty(String key, String value) {
if (!StringHelper.isNullOrEmpty(value)) {
System.setProperty(key, value);
}
}

public String getProperty(String propertyKey) {
public String getExcelProperty(String propertyKey) {
if (System.getProperty(propertyKey) != null)
return System.getProperty(propertyKey);
return properties.getOrDefault(propertyKey, "");
String key = propertyKey.substring(propertyKey.lastIndexOf(".") + 1);
return getConfig().getExcel().getOrDefault(key, "");
}

public String getSubstitutedProperty(String propertyKey) {
return StringHelper.interpolate(getProperty(propertyKey),
matcher -> getProperty(matcher.group(1)));
public String getCucumberProperty(String propertyKey) {
if (System.getProperty(propertyKey) != null)
return System.getProperty(propertyKey);
String key = propertyKey.substring(propertyKey.lastIndexOf(".") + 1);
return getConfig().getCucumber().getOrDefault(key, "");
}

public String getReportsProperty(String propertyKey) {
if (System.getProperty(propertyKey) != null)
return System.getProperty(propertyKey);
String key = propertyKey.substring(propertyKey.lastIndexOf(".") + 1);
return getConfig().getReports().getOrDefault(key, "");
}

public static void setSystemProperty(String key, String value) {
if (!value.isBlank()) {
System.setProperty(key, value);
}
public String getSubstitutedConfigProperty(String propertyKey) {
return StringHelper.interpolate(getCucumberProperty(propertyKey),
matcher -> getCucumberProperty(matcher.group(1)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,13 @@
import java.nio.file.Path;
import java.util.Map;

import static io.github.selcukes.commons.properties.SelcukesTestProperties.*;
import static io.github.selcukes.commons.properties.SelcukesTestProperties.FEATURES;
import static org.testng.Assert.*;

public class PropertiesTest {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final static String PROPS_FILE = "target/temp.properties";

@Test
public void loadPropertiesMapTest() {
final Map<String, String> propertiesMap = PropertiesMapper.readAsMap("selcukes.properties");
assertEquals(propertiesMap.size(), 11);
assertEquals(propertiesMap.get(EXCEL_RUNNER), "true");
assertEquals(propertiesMap.get(EXCEL_SUITE_NAME), "SMOKE");
propertiesMap.forEach((k, v) -> logger.info(() -> String.format("Key :[%s] Value :[%s]", k, v)));
}

@Test
public void createPropertyFileTest() {
Map<String, String> data = Map.of("userName", "QA",
Expand Down Expand Up @@ -77,9 +68,6 @@ public void linkedPropertiesTest() {
@Test
public void selcukesTestPropsTest() {
SelcukesTestProperties properties = new SelcukesTestProperties();
assertEquals(properties.getSubstitutedProperty(FEATURES), "Hello RB Test");
assertEquals(properties.getProperty(EXCEL_SUITE_FILE), "TestData.xlsx");
assertEquals(properties.getProperty("dummy"), "");
assertEquals(properties.getSubstitutedProperty(GLUE), "Sample of RB Test");
logger.info(() -> properties.getSubstitutedConfigProperty(FEATURES));
}
}
11 changes: 0 additions & 11 deletions selcukes-commons/src/test/resources/selcukes.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ projectName: Selcukes
env: Dev
proxy: false
baseUrl:
excelRunner:
excel:
runner:
filePath: ""
suiteName: "smoke"
cucumber:
module: google
features: src/test/resources/features/${module}
glue: io.github.selcukes.testng.tests
tags:
plugin:
web:
remote: false
browserName: CHROME
Expand All @@ -17,6 +24,10 @@ windows:
winApp-path: "C:/Program Files (x86)/Windows Application Driver/WinAppDriver.exe"
mobile:
serviceUrl: "http://127.0.0.1:4723"
reports:
emailReport: true
htmlReport: true
reportsPath:
video:
recording: false
recorderType: FFMPEG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.openqa.selenium.remote.CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR;

public class BrowserOptions {

public Capabilities getBrowserOptions(DriverType driverType, boolean isGrid) {
boolean headless = Platform.isLinux();
if (isGrid) {
Expand All @@ -55,7 +56,9 @@ public Capabilities getBrowserOptions(DriverType driverType, boolean isGrid) {
ieOptions.setCapability("enablePersistentHover", true);
return ieOptions;
default:
return new ChromeOptions().setHeadless(headless);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(headless);
return chromeOptions;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.github.selcukes.core.page.WebPage;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

public class WebTest extends GridBaseTest {
Expand All @@ -34,7 +34,7 @@ public void remoteTest() {
Assert.assertEquals(page.title(), "Google");
}

@AfterTest
@AfterMethod
void afterTest() {
DriverManager.removeDriver();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ web:
remote: true
browserName: CHROME
headLess: true
serviceUrl: "http://localhost:"
serviceUrl: "http://127.0.0.1:"
windows:
serviceUrl: "http://127.0.0.1:4723"
winApp-path: "C:/Program Files (x86)/Windows Application Driver/WinAppDriver.exe"
winApp-path: "C:/Program Files/Windows Application Driver/WinAppDriver.exe"
app: "C:\\Windows\\System32\\notepad.exe"
mobile:
serviceUrl: "http://127.0.0.1:4723"
app: "ApiDemos-debug.apk"
video:
recording: false
recorderType: FFMPEG
ffmpegPath:
ffmpegPath: D:\\MyProject\support\video\ffmpeg\bin\
watermarkStatus: false
notifier:
notification: false
type: slack
webhook-token: WEBHOOKXXXX
api-token: APIXXXX
channel: selcukes
authorIcon: https://avatars0.githubusercontent.com/u/2510294?s=400&u=5d6412ba1dd13052992ff66317ae28d007a971d3&v=4
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ExcelSuiteListener implements ISuiteListener {
@Override
public void onStart(ISuite suite) {
SelcukesTestProperties testProperties = new SelcukesTestProperties();
if (!testProperties.getProperty(SelcukesTestProperties.EXCEL_RUNNER).equalsIgnoreCase("false"))
if (!testProperties.getExcelProperty(SelcukesTestProperties.EXCEL_RUNNER).equalsIgnoreCase("false"))
ExcelUtils.initTestRunner();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public class ExcelUtils {
private static final Map<String, List<List<String>>> allSheetsDataMap = new LinkedHashMap<>();
private static Map<String, List<List<String>>> allSheetsMap = new LinkedHashMap<>();
public static final List<String> runScenarios = new ArrayList<>();
private static final String TEST_SUITE_RUNNER_SHEET = ConfigFactory.getConfig().getExcelRunner().get("suiteName");
private static final String TEST_SUITE_RUNNER_SHEET = ConfigFactory.getConfig().getExcel().get("suiteName");
private static final List<String> IGNORE_SHEETS = new ArrayList<>(
Arrays.asList("Master", "Smoke", "Regression", "StaticData"));

public static void initTestRunner() {
ExcelReader excelReader = new ExcelReader(
ConfigFactory.getConfig().getExcelRunner().get("fileName"));
ConfigFactory.getConfig().getExcel().get("fileName"));

// Store all sheets data
allSheetsMap = excelReader.getAllSheets().stream()
Expand Down
30 changes: 0 additions & 30 deletions selcukes-excel-runner/src/main/resources/selcukes.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions selcukes-excel-runner/src/test/resources/selcukes.properties

This file was deleted.

22 changes: 22 additions & 0 deletions selcukes-excel-runner/src/test/resources/selcukes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Selcukes Environment Properties
---
projectName: Selcukes
env: Dev
proxy: false
baseUrl:
excel:
runner: true
fileName: "TestData.xlsx"
suiteName: "Smoke"
cucumber:
module:
features: src/test/resources/features
glue: io.github.selcukes.excel.steps
tags:
plugin:
reports:
emailReport: true
htmlReport: true
path: target
fileName: TestReport
timestamp: false
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static Object getProperty(String key) {
}

private static class ExtentReportsLoader {
private static final String THUMBNAIL_REPORT = "selcukes.extent.thumbnail";
private static final String TIMESTAMP_REPORT = "selcukes.timestamp.report";
private static final String THUMBNAIL_REPORT = "selcukes.reports.thumbnail";
private static final String TIMESTAMP_REPORT = "selcukes.reports.timestamp";
private static final ExtentReports INSTANCE = new ExtentReports();
private static final String[] DEFAULT_SETUP_PATH = new String[]{"extent.properties",
"com/aventstack/adapter/extent.properties"};
Expand Down

This file was deleted.

18 changes: 18 additions & 0 deletions selcukes-extent-reports/src/test/resources/selcukes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Selcukes Environment Properties
---
projectName: Selcukes
env: Dev
proxy: false
baseUrl:
cucumber:
module:
features: src/test/resources/
glue: io.github.selcukes.extent.report.tests.steps
tags:
plugin:
reports:
emailReport: true
htmlReport: true
path: target
fileName: TestReport
timestamp: false
5 changes: 0 additions & 5 deletions selcukes-junit/src/test/resources/selcukes.properties

This file was deleted.

Loading