Skip to content

Commit f3b0786

Browse files
authored
Extracted configurations (#21)
* extracted ISettingsFile and added tests * added documentation for ISettingsFile * extracted ILoggerConfiguration * extracted ITimeoutConfiguration * extracted IRetryConfiguration * renamed one test * added empty end line and updated com.fasterxml.jackson.core to 2.10.2 * renamed constants to upper case * removed redundant method from ISettingsFile * fixed naming and added empty line at the end of files * fixed naming and added empty line at the end of files * fixed naming and added empty line at the end of files * merged with master and added test for CustomSettingsFile * fix for the tests * merge and small refactoring of tests * merge from master * merge from master * extracted IElementCacheConfiguration * merge and test fix * removed SupportedLanguaged and added default language if configuration is absent * register configuration as singleton * fixed comments * moved SettingsFileUtil to ISettingsFile
1 parent d482135 commit f3b0786

25 files changed

+495
-25
lines changed

src/main/java/aquality/selenium/core/application/AqualityModule.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import aquality.selenium.core.logging.Logger;
44
import aquality.selenium.core.utilities.ISettingsFile;
55
import aquality.selenium.core.utilities.JsonSettingsFile;
6+
import aquality.selenium.core.configurations.*;
67
import com.google.inject.AbstractModule;
78
import com.google.inject.Provider;
9+
import com.google.inject.Singleton;
810

911
/**
1012
* Describes all dependencies which is registered for the project.
@@ -25,6 +27,10 @@ protected void configure() {
2527
bind(IApplication.class).toProvider(applicationProvider);
2628
bind(ISettingsFile.class).toInstance(getSettings());
2729
bind(Logger.class).toInstance(Logger.getInstance());
30+
bind(ILoggerConfiguration.class).to(LoggerConfiguration.class).in(Singleton.class);
31+
bind(ITimeoutConfiguration.class).to(TimeoutConfiguration.class).in(Singleton.class);
32+
bind(IRetryConfiguration.class).to(RetryConfiguration.class).in(Singleton.class);
33+
bind(IElementCacheConfiguration.class).to(ElementCacheConfiguration.class).in(Singleton.class);
2834
}
2935

3036
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package aquality.selenium.core.configurations;
2+
3+
import aquality.selenium.core.utilities.ISettingsFile;
4+
import com.google.inject.Inject;
5+
6+
public class ElementCacheConfiguration implements IElementCacheConfiguration{
7+
8+
private static final String IS_ENABLED_PATH = "/elementCache/isEnabled";
9+
private boolean isEnabled;
10+
11+
@Inject
12+
public ElementCacheConfiguration(ISettingsFile settingsFile){
13+
isEnabled = settingsFile.isValuePresent(IS_ENABLED_PATH) && Boolean.valueOf(settingsFile.getValue(IS_ENABLED_PATH).toString());
14+
}
15+
16+
@Override
17+
public boolean isEnabled() {
18+
return isEnabled;
19+
}
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package aquality.selenium.core.configurations;
2+
3+
/**
4+
* Provides element's cache configuration.
5+
*/
6+
public interface IElementCacheConfiguration {
7+
8+
/**
9+
* @return Is element caching allowed or not.
10+
*/
11+
boolean isEnabled();
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package aquality.selenium.core.configurations;
2+
3+
/**
4+
* Describes logger configuration.
5+
*/
6+
public interface ILoggerConfiguration {
7+
8+
/**
9+
* Gets language used inside the library for logging.
10+
* @return language used for logging.
11+
*/
12+
String getLanguage();
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package aquality.selenium.core.configurations;
2+
3+
/**
4+
* Describes retry configuration.
5+
*/
6+
public interface IRetryConfiguration {
7+
8+
/**
9+
* Gets the number of attempts during retry.
10+
*
11+
* @return Number of retry attempts.
12+
*/
13+
int getNumber();
14+
15+
/**
16+
* Gets the polling interval used in retry.
17+
*
18+
* @return Polling interval for retry.
19+
*/
20+
long getPollingInterval();
21+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package aquality.selenium.core.configurations;
2+
3+
/**
4+
* Provides timeouts configuration.
5+
*/
6+
public interface ITimeoutConfiguration {
7+
8+
/**
9+
* Gets WedDriver ImplicitWait timeout.
10+
*
11+
* @return ImplicitWait timeout.
12+
*/
13+
long getImplicit();
14+
15+
/**
16+
* Gets default ConditionalWait timeout.
17+
*
18+
* @return ConditionalWait timeout.
19+
*/
20+
long getCondition();
21+
22+
/**
23+
* Gets ConditionalWait polling interval.
24+
*
25+
* @return polling interval.
26+
*/
27+
long getPollingInterval();
28+
29+
/**
30+
* Gets Command timeout.
31+
*
32+
* @return Command timeout.
33+
*/
34+
long getCommand();
35+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package aquality.selenium.core.configurations;
2+
3+
import aquality.selenium.core.utilities.ISettingsFile;
4+
import com.google.inject.Inject;
5+
6+
public class LoggerConfiguration implements ILoggerConfiguration {
7+
8+
private static final String DEFAULT_LANGUAGE = "en";
9+
private final ISettingsFile settingsFile;
10+
11+
@Inject
12+
public LoggerConfiguration(ISettingsFile settingsFile){
13+
this.settingsFile = settingsFile;
14+
}
15+
16+
@Override
17+
public String getLanguage() {
18+
return settingsFile.getValueOrDefault("/logger/language", DEFAULT_LANGUAGE).toString();
19+
}
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package aquality.selenium.core.configurations;
2+
3+
import aquality.selenium.core.utilities.ISettingsFile;
4+
import com.google.inject.Inject;
5+
6+
public class RetryConfiguration implements IRetryConfiguration {
7+
private final int number;
8+
private final long pollingInterval;
9+
10+
@Inject
11+
public RetryConfiguration(ISettingsFile settingsFile) {
12+
this.number = Integer.parseInt(settingsFile.getValue("/retry/number").toString());
13+
this.pollingInterval = Long.parseLong(settingsFile.getValue("/retry/pollingInterval").toString());
14+
}
15+
16+
@Override
17+
public int getNumber() {
18+
return number;
19+
}
20+
21+
@Override
22+
public long getPollingInterval() {
23+
return pollingInterval;
24+
}
25+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package aquality.selenium.core.configurations;
2+
3+
import aquality.selenium.core.utilities.ISettingsFile;
4+
import com.google.inject.Inject;
5+
6+
public class TimeoutConfiguration implements ITimeoutConfiguration{
7+
8+
private final ISettingsFile settingsFile;
9+
private final long condition;
10+
private final long pollInterval;
11+
private final long implicit;
12+
private final long command;
13+
14+
@Inject
15+
public TimeoutConfiguration(ISettingsFile settingsFile) {
16+
this.settingsFile = settingsFile;
17+
condition = getTimeout(TIMEOUT.CONDITION);
18+
pollInterval = getTimeout(TIMEOUT.POLL_INTERVAL);
19+
implicit = getTimeout(TIMEOUT.IMPLICIT);
20+
command = getTimeout(TIMEOUT.COMMAND);
21+
}
22+
23+
private long getTimeout(TIMEOUT timeout){
24+
return Long.valueOf(settingsFile.getValue(timeout.getKey()).toString());
25+
}
26+
27+
public long getImplicit(){
28+
return implicit;
29+
}
30+
31+
public long getCondition(){
32+
return condition;
33+
}
34+
35+
public long getPollingInterval(){
36+
return pollInterval;
37+
}
38+
39+
public long getCommand(){
40+
return command;
41+
}
42+
43+
private enum TIMEOUT {
44+
IMPLICIT("/timeouts/timeoutImplicit"),
45+
CONDITION("/timeouts/timeoutCondition"),
46+
POLL_INTERVAL("/timeouts/timeoutPollingInterval"),
47+
COMMAND("/timeouts/timeoutCommand");
48+
49+
private String key;
50+
TIMEOUT(String key){
51+
this.key = key;
52+
}
53+
54+
private String getKey(){
55+
return key;
56+
}
57+
}
58+
}

src/main/java/aquality/selenium/core/utilities/ISettingsFile.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,15 @@ public interface ISettingsFile {
3939
* @return True if exists, false otherwise.
4040
*/
4141
boolean isValuePresent(String path);
42+
43+
/**
44+
* Gets value from settings file or default value.
45+
*
46+
* @param path Path to the values. Depending on file format, it can be jsonPath, xpath etc.
47+
* @param defaultValue will be returned if there is no value by path in settings file.
48+
* @return Value from settings file or default value.
49+
*/
50+
default Object getValueOrDefault(String path, Object defaultValue) {
51+
return this.isValuePresent(path) ? this.getValue(path) : defaultValue;
52+
}
4253
}

0 commit comments

Comments
 (0)