Skip to content

Commit

Permalink
config from file added
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavlo committed Jun 4, 2022
1 parent a7fb536 commit efb4f45
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main/java/com/pablojuice/framework/config/FrameworkConfig.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
package com.pablojuice.framework.config;

import com.pablojuice.framework.util.Resource;


public class FrameworkConfig {

private FrameworkConfig() {

}

public static final int WAIT_TIMEOUT = 20;
private static final Resource resources = Resource.of("framework");

public static final int WAIT_TIMEOUT = resources.getInt("elements.wait.timeout", 20);

public static final int ACTION_TIMEOUT = resources.getInt("elements.action.timeout", 5);

public static final int ACTION_TIMEOUT = 5;
public static final int ACTIONS_TRY = resources.getInt("elements.actions.try", 2);

public static final int ACTIONS_TRY = 3;
public static final boolean ELEMENT_REPORTING = resources.getBoolean("elements.reporting", false);

public static final boolean ELEMENT_REPORTING = false;
public static final boolean SCREENING = resources.getBoolean("reporting.screenshot", false);

public static final boolean SCREENING = false;
public static final boolean WAIT_REPORTING = resources.getBoolean("reporting.waits", false);

public static final boolean WAIT_REPORTING = false;
public static final int INTERVAL_MS = resources.getInt("elements.wait.interval", 0);

public static final int INTERVAL_MS = 0;
public static final int LOADING_MS = resources.getInt("elements.wait.loading", 1000);

public static final boolean LOG_VIDEO = false;
public static final boolean LOG_VIDEO = resources.getBoolean("reporting.video", false);
}
22 changes: 22 additions & 0 deletions src/main/java/com/pablojuice/framework/util/OSUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.pablojuice.framework.util;


public class OSUtil {

public enum OS {
LINUX, MACOS, WIN, OTHER
}

public static OS getOS() {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win")) {
return OS.WIN;
} else if (os.contains("nux") || os.contains("nix")) {
return OS.LINUX;
} else if (os.contains("mac")) {
return OS.MACOS;
} else {
return OS.OTHER;
}
}
}
52 changes: 52 additions & 0 deletions src/main/java/com/pablojuice/framework/util/Resource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.pablojuice.framework.util;

import java.util.ResourceBundle;

public final class Resource {
private final ResourceBundle resources;

public Resource(String name) {
this.resources = ResourceBundle.getBundle(name);
}

public static Resource of(String name) {
return new Resource(name);
}

public String get(String key) {
String result = "";
try {
result = resources.getString(key);
} catch (Exception ignored) {
}
return result;

}

public String getString(String key, String defaultValue) {
final String result = get(key);
if (result.isEmpty()) {
return defaultValue;
} else {
return result;
}
}

public boolean getBoolean(String key, boolean defaultValue) {
final String result = get(key);
if (result.isEmpty()) {
return defaultValue;
} else {
return Boolean.parseBoolean(result);
}
}

public int getInt(String key, int defaultValue) {
final String result = get(key);
if (result.isEmpty()) {
return defaultValue;
} else {
return Integer.parseInt(result);
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/pablojuice/framework/util/Variables.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.pablojuice.framework.util;

import com.pablojuice.framework.reports.Reporter;
import lombok.Getter;
import lombok.Setter;

public class Variables {

private Variables() {

}

@Setter
@Getter
public static final Reporter.Builder reporterBuilder = new Reporter.Builder();

public static String getEnvironmentVariable(String name, String defaultValue) {
String value = System.getenv(name.toUpperCase());

if (value != null && !value.isEmpty()) {
reporterBuilder.append(String.format("Get Env parameter %s; value = %s", name, value));
} else {
if (defaultValue != null) {
reporterBuilder.append(String.format("Can not get Env parameter %s; default value = %s",
name,
defaultValue));
value = defaultValue;
} else {
reporterBuilder.append(String.format("Can not get Env parameter %s; NO DEFAULT VALUE", name));
}
}
return value;
}

public static String getEnvironmentVariable(String name) {
return getEnvironmentVariable(name, null);
}
}
7 changes: 7 additions & 0 deletions src/main/resources/framework.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
elements.wait.timeout=100
elements.action.timeout=100
elements.wait.loading=2500
elements.actions.try=3
elements.reporting=false
reporting.screenshot=false
reporting.waits=false

0 comments on commit efb4f45

Please sign in to comment.