Skip to content

Commit fa209b1

Browse files
authored
Merge pull request #43 from AutomateThePlanet/fixes-and-refactoring
fixes and refactorings
2 parents 1717557 + b1c05de commit fa209b1

File tree

14 files changed

+83
-67
lines changed

14 files changed

+83
-67
lines changed

bellatrix.core/src/main/java/solutions/bellatrix/core/plugins/EventListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public void addListener(Consumer<TArgs> listener) {
2424
listeners.add(listener);
2525
}
2626

27+
public void removeListener(Consumer<TArgs> listener) {
28+
listeners.remove(listener);
29+
}
30+
2731
public void broadcast(TArgs args) {
2832
if (listeners.size() > 0) {
2933
listeners.forEach(x -> x.accept(args));

bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/SingletonFactory.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,30 @@
2222
// Based on http://neutrofoton.github.io/blog/2013/08/29/generic-singleton-pattern-in-java/
2323
// Can be used inside App design pattern.
2424
@SuppressWarnings("unchecked")
25+
@UtilityClass
2526
public class SingletonFactory {
26-
private static final SingletonFactory SINGLETON_FACTORY = new SingletonFactory();
27-
28-
private final Map<Class<?>, Object> mapHolder = new HashMap<>();
29-
30-
private SingletonFactory() {
31-
}
27+
private static final ThreadLocal<Map<Class<?>, Object>> mapHolder = ThreadLocal.withInitial(HashMap::new);
3228

3329
@SneakyThrows
3430
public static <T> T getInstance(Class<T> classOf, Object... initargs) {
3531
try {
36-
if (!SINGLETON_FACTORY.mapHolder.containsKey(classOf)) {
32+
if (!mapHolder.get().containsKey(classOf)) {
3733
T obj = (T)classOf.getConstructors()[0].newInstance(initargs);
38-
SINGLETON_FACTORY.mapHolder.put(classOf, obj);
34+
register(obj);
3935
}
40-
return (T)SINGLETON_FACTORY.mapHolder.get(classOf);
36+
37+
return (T)mapHolder.get().get(classOf);
4138
} catch (Exception e) {
4239
Log.error("Failed to create instance of the object. Exception was: " + e);
4340
return null;
4441
}
4542
}
4643

4744
public static <T> void register(T instance) {
48-
SINGLETON_FACTORY.mapHolder.put(instance.getClass(), instance);
45+
mapHolder.get().put(instance.getClass(), instance);
4946
}
5047

5148
public static <T> void register(Class<?> classKey, T instance) {
52-
SINGLETON_FACTORY.mapHolder.put(classKey, instance);
49+
mapHolder.get().put(classKey, instance);
5350
}
5451
}

bellatrix.addons.visual-regression-tracker/pom.xml renamed to bellatrix.plugins.visual-regression-tracker/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<version>1.0-SNAPSHOT</version>
1010
</parent>
1111

12-
<artifactId>bellatrix.addons.visual-regression-tracker</artifactId>
12+
<artifactId>bellatrix.plugins.visual-regression-tracker</artifactId>
1313

1414
<repositories>
1515
<repository>

bellatrix.web/src/main/java/solutions/bellatrix/web/components/WebComponent.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ public String getAccessKey() {
208208
return getAttribute("accesskey");
209209
}
210210

211-
public String getStyle() {
212-
return getAttribute("style");
213-
}
214-
215211
public String getDir() {
216212
return getAttribute("dir");
217213
}
@@ -224,6 +220,7 @@ public String getHtmlClass() {
224220
return getAttribute("class");
225221
}
226222

223+
@Override
227224
public String getAttribute(String name) {
228225
return getWrappedElement().getAttribute(name);
229226
}

bellatrix.web/src/main/java/solutions/bellatrix/web/components/contracts/Component.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ public interface Component extends LayoutComponent {
2121
Class<?> getComponentClass();
2222
WebElement getWrappedElement();
2323
FindStrategy getFindStrategy();
24+
String getAttribute(String attributeName);
2425
}

bellatrix.web/src/main/java/solutions/bellatrix/web/components/contracts/ComponentStyle.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,50 +22,39 @@
2222

2323
import java.lang.reflect.InvocationTargetException;
2424
import java.lang.reflect.Method;
25+
import java.util.Objects;
2526
import java.util.function.Supplier;
2627

2728
public interface ComponentStyle extends Component {
28-
String getStyle();
29+
default String getStyle() {
30+
return getAttribute("style");
31+
}
32+
33+
default String getStyle(CssStyle style) {
34+
return getWrappedElement().getCssValue(style.toString());
35+
}
2936

30-
@SneakyThrows
3137
default void validateStyleIs(String value) {
3238
ComponentValidator.defaultValidateAttributeIs((WebComponent)this, this::getStyle, value, "style");
3339
}
3440

35-
@SneakyThrows
3641
default void validateStyleIsSet() {
3742
ComponentValidator.defaultValidateAttributeIsSet((WebComponent)this, this::getStyle, "style");
3843
}
3944

40-
@SneakyThrows
4145
default void validateStyleNotSet() {
4246
ComponentValidator.defaultValidateAttributeNotSet((WebComponent)this, this::getStyle, "style");
4347
}
4448

45-
@SneakyThrows
4649
default void validateStyleContains(String value) {
4750
ComponentValidator.defaultValidateAttributeContains((WebComponent)this, this::getStyle, value, "style");
4851
}
4952

50-
@SneakyThrows
5153
default void validateStyleNotContains(String value) {
5254
ComponentValidator.defaultValidateAttributeNotContains((WebComponent)this, this::getStyle, value, "style");
5355
}
5456

55-
default String getStyle(CssStyle style) {
56-
var script = String.format("return window.getComputedStyle(arguments[0],null).getPropertyValue('%s');", style);
57-
var result = new JavaScriptService().execute(script, (WebComponent) this);
58-
59-
return result;
60-
}
61-
62-
@SneakyThrows
6357
default void validateStyle(CssStyle style, String expectedValue) {
64-
try {
65-
Method method = ComponentValidator.class.getDeclaredMethod("defaultValidateAttributeIs", WebComponent.class, Supplier.class, java.lang.String.class, java.lang.String.class);
66-
method.invoke(SingletonFactory.getInstance(ComponentValidator.class), (WebComponent) this, (Supplier<Object>) () -> this.getStyle(style), expectedValue, java.lang.String.format("expected color should be %s", expectedValue));
67-
} catch (InvocationTargetException e) {
68-
throw e.getCause();
69-
}
58+
ComponentValidator.defaultValidateAttributeIs((WebComponent)this, () -> this.getStyle(style), expectedValue, style.toString());
7059
}
7160
}

bellatrix.web/src/main/java/solutions/bellatrix/web/components/enums/CssStyle.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,26 @@
22

33
public enum CssStyle {
44
BACKGROUND_COLOR("background-color"),
5-
COLOR("color");
5+
BORDER_COLOR("border-color"),
6+
COLOR("color"),
7+
FONT_FAMILY("font-family"),
8+
FONT_WEIGHT("font-weight"),
9+
FONT_SIZE("font-size"),
10+
TEXT_ALIGN("text-align"),
11+
VERTICAL_ALIGN("vertical-align"),
12+
LINE_HEIGHT("line-height"),
13+
LETTER_SPACING("letter-spacing"),
14+
MARGIN_TOP("margin-top"),
15+
MARGIN_BOTTOM("margin-bottom"),
16+
MARGIN_LEFT("margin-left"),
17+
MARGIN_RIGHT("margin-right"),
18+
PADDING_TOP("padding-top"),
19+
PADDING_BOTTOM("padding-bottom"),
20+
PADDING_LEFT("padding-left"),
21+
PADDING_RIGHT("padding-right"),
22+
POSITION("position"),
23+
HEIGHT("height"),
24+
WIDTH("width");
625

726
private final String style;
827

bellatrix.web/src/main/java/solutions/bellatrix/web/infrastructure/Browser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public enum Browser {
2222
FIREFOX("firefox"),
2323
FIREFOX_HEADLESS("firefox_headless"),
2424
EDGE("edge"),
25-
// EDGE_HEADLESS("edge"), // Unsupported by Selenium 3, Selenium 4 has support
25+
EDGE_HEADLESS("edge_headless"),
2626
OPERA("opera"),
2727
SAFARI("safari"),
28-
NOT_SET("not_set"),
29-
INTERNET_EXPLORER("ie");
28+
INTERNET_EXPLORER("ie"),
29+
NOT_SET("not_set");
3030

3131
private final String value;
3232

0 commit comments

Comments
 (0)