Skip to content

Commit 36f3c4b

Browse files
Merge pull request #119 from aquality-automation/breaking/add-visualization
[Feature] [Breaking] Visualization
2 parents 683fbcb + 0ca9590 commit 36f3c4b

File tree

22 files changed

+140
-46
lines changed

22 files changed

+140
-46
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ downloads
55
# Log file
66
*.log
77

8+
# Visualization files
9+
visualDumps/
10+
811
# BlueJ files
912
*.ctxt
1013

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Alternatively, you can follow the steps below:
2222
<dependency>
2323
<groupId>com.github.aquality-automation</groupId>
2424
<artifactId>aquality-selenium</artifactId>
25-
<version>3.x.x</version>
25+
<version>4.x.x</version>
2626
</dependency>
2727
```
2828

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.aquality-automation</groupId>
88
<artifactId>aquality-selenium</artifactId>
9-
<version>3.2.1</version>
9+
<version>4.0.0</version>
1010
<packaging>jar</packaging>
1111
<name>Aquality Selenium</name>
1212
<description>Library around Selenium WebDriver</description>
@@ -81,19 +81,19 @@
8181
<dependency>
8282
<groupId>com.github.aquality-automation</groupId>
8383
<artifactId>aquality-selenium-core</artifactId>
84-
<version>2.0.6</version>
84+
<version>3.0.0</version>
8585
</dependency>
8686

8787
<dependency>
8888
<groupId>io.github.bonigarcia</groupId>
8989
<artifactId>webdrivermanager</artifactId>
90-
<version>5.3.1</version>
90+
<version>5.3.2</version>
9191
</dependency>
9292

9393
<dependency>
9494
<groupId>com.fasterxml.jackson.core</groupId>
9595
<artifactId>jackson-databind</artifactId>
96-
<version>2.14.1</version>
96+
<version>2.14.2</version>
9797
</dependency>
9898

9999
<dependency>

src/main/java/aquality/selenium/configuration/Configuration.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import aquality.selenium.core.configurations.IElementCacheConfiguration;
44
import aquality.selenium.core.configurations.ILoggerConfiguration;
55
import aquality.selenium.core.configurations.IRetryConfiguration;
6+
import aquality.selenium.core.configurations.IVisualizationConfiguration;
67
import com.google.inject.Inject;
78

89
public class Configuration implements IConfiguration {
@@ -12,16 +13,18 @@ public class Configuration implements IConfiguration {
1213
private final IBrowserProfile browserProfile;
1314
private final ILoggerConfiguration loggerConfiguration;
1415
private final IElementCacheConfiguration elementCacheConfiguration;
16+
private final IVisualizationConfiguration visualizationConfiguration;
1517

1618
@Inject
1719
public Configuration(ITimeoutConfiguration timeoutConfiguration, IRetryConfiguration retryConfiguration,
1820
IBrowserProfile browserProfile, ILoggerConfiguration loggerConfiguration,
19-
IElementCacheConfiguration elementCacheConfiguration) {
21+
IElementCacheConfiguration elementCacheConfiguration, IVisualizationConfiguration visualizationConfiguration) {
2022
this.timeoutConfiguration = timeoutConfiguration;
2123
this.retryConfiguration = retryConfiguration;
2224
this.browserProfile = browserProfile;
2325
this.loggerConfiguration = loggerConfiguration;
2426
this.elementCacheConfiguration = elementCacheConfiguration;
27+
this.visualizationConfiguration = visualizationConfiguration;
2528
}
2629

2730
@Override
@@ -48,4 +51,9 @@ public ILoggerConfiguration getLoggerConfiguration() {
4851
public IElementCacheConfiguration getElementCacheConfiguration() {
4952
return elementCacheConfiguration;
5053
}
54+
55+
@Override
56+
public IVisualizationConfiguration getVisualizationConfiguration() {
57+
return visualizationConfiguration;
58+
}
5159
}

src/main/java/aquality/selenium/configuration/IConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import aquality.selenium.core.configurations.IElementCacheConfiguration;
44
import aquality.selenium.core.configurations.ILoggerConfiguration;
55
import aquality.selenium.core.configurations.IRetryConfiguration;
6+
import aquality.selenium.core.configurations.IVisualizationConfiguration;
67

78
/**
89
* Describes tool configuration.
@@ -43,4 +44,11 @@ public interface IConfiguration {
4344
* @return Configuration of element caching.
4445
*/
4546
IElementCacheConfiguration getElementCacheConfiguration();
47+
48+
/**
49+
* Gets configuration of VisualStateProvider and Dump manager.
50+
*
51+
* @return Visualization configuration.
52+
*/
53+
IVisualizationConfiguration getVisualizationConfiguration();
4654
}

src/main/java/aquality/selenium/configuration/TimeoutConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private enum TIMEOUT {
3737
SCRIPT("timeoutScript"),
3838
PAGE_LOAD("timeoutPageLoad");
3939

40-
private String key;
40+
private final String key;
4141

4242
TIMEOUT(String key) {
4343
this.key = key;

src/main/java/aquality/selenium/configuration/driversettings/ChromeSettings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ private void setChromeArgs(ChromeOptions options) {
4242
for (String arg : getBrowserStartArguments()) {
4343
options.addArguments(arg);
4444
}
45+
// workaround for Selenium issue https://github.com/SeleniumHQ/selenium/issues/11750
46+
final String allowOriginsArgument = "--remote-allow-origins=*";
47+
if (!getBrowserStartArguments().contains(allowOriginsArgument)) {
48+
options.addArguments(allowOriginsArgument);
49+
}
4550
}
4651

4752
@Override

src/main/java/aquality/selenium/elements/Element.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import aquality.selenium.core.localization.ILocalizationManager;
1313
import aquality.selenium.core.localization.ILocalizedLogger;
1414
import aquality.selenium.core.utilities.IElementActionRetrier;
15+
import aquality.selenium.core.visualization.IImageComparator;
1516
import aquality.selenium.core.waitings.IConditionalWait;
1617
import aquality.selenium.elements.actions.JsActions;
1718
import aquality.selenium.elements.actions.MouseActions;
@@ -64,6 +65,11 @@ void setElementFinder(IElementFinder elementFinder) {
6465
this.elementFinder = elementFinder;
6566
}
6667

68+
@Override
69+
protected IImageComparator getImageComparator() {
70+
return AqualityServices.get(IImageComparator.class);
71+
}
72+
6773
@Override
6874
protected IElementCacheConfiguration getElementCacheConfiguration() {
6975
return AqualityServices.get(IElementCacheConfiguration.class);
@@ -79,6 +85,7 @@ protected ILocalizedLogger getLocalizedLogger() {
7985
return AqualityServices.getLocalizedLogger();
8086
}
8187

88+
@Override
8289
protected ILocalizationManager getLocalizationManager() {
8390
return AqualityServices.get(ILocalizationManager.class);
8491
}

src/main/java/aquality/selenium/elements/ElementStateProvider.java

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

33
import aquality.selenium.core.elements.DefaultElementStateProvider;
44
import aquality.selenium.core.elements.interfaces.IElementFinder;
5-
import aquality.selenium.core.elements.interfaces.ILogElementState;
5+
import aquality.selenium.core.logging.ILogElementState;
66
import aquality.selenium.core.waitings.IConditionalWait;
77
import org.openqa.selenium.By;
88
import org.openqa.selenium.WebElement;

src/main/java/aquality/selenium/elements/ElementType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ public enum ElementType {
1111
RADIOBUTTON(IRadioButton.class),
1212
TEXTBOX(ITextBox.class);
1313

14-
private Class<? extends IElement> clazz;
14+
private final Class<? extends IElement> clazz;
1515

1616
<T extends IElement> ElementType(Class<T> clazz){
1717
this.clazz = clazz;
1818
}
1919

2020
public <T extends IElement> Class<T> getClazz() {
21+
//noinspection unchecked
2122
return (Class<T>) clazz;
2223
}
2324
}

src/main/java/aquality/selenium/forms/Form.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package aquality.selenium.forms;
22

33
import aquality.selenium.browser.AqualityServices;
4+
import aquality.selenium.core.configurations.IVisualizationConfiguration;
45
import aquality.selenium.core.elements.interfaces.IElementStateProvider;
56
import aquality.selenium.core.localization.ILocalizedLogger;
7+
import aquality.selenium.elements.interfaces.IElement;
68
import aquality.selenium.elements.interfaces.IElementFactory;
79
import aquality.selenium.elements.interfaces.ILabel;
810
import org.openqa.selenium.By;
9-
import org.openqa.selenium.Dimension;
11+
12+
import java.awt.*;
1013

1114
/**
1215
* Defines base class for any UI form.
1316
*/
14-
public abstract class Form {
17+
public abstract class Form extends aquality.selenium.core.forms.Form<IElement> {
18+
/**
19+
* Label of form element defined by its locator and name.
20+
*/
21+
private final ILabel formLabel;
1522
/**
1623
* Locator for specified form
1724
*/
@@ -25,8 +32,10 @@ public abstract class Form {
2532
* Constructor with parameters
2633
*/
2734
protected Form(By locator, String name) {
35+
super(IElement.class);
2836
this.locator = locator;
2937
this.name = name;
38+
formLabel = getElementFactory().getLabel(locator, name);
3039
}
3140

3241
/**
@@ -55,18 +64,6 @@ public IElementStateProvider state() {
5564
return getFormLabel().state();
5665
}
5766

58-
/**
59-
* @deprecated This method will be removed in the future release. Use state().waitForDisplayed() if needed.
60-
* Return form state for form locator, waiting for the form to be displayed.
61-
*
62-
* @return True - form is opened,
63-
* False - form is not opened
64-
*/
65-
@Deprecated
66-
public boolean isDisplayed() {
67-
return state().waitForDisplayed();
68-
}
69-
7067
/**
7168
* Scroll form without scrolling entire page
7269
*
@@ -83,7 +80,7 @@ public void scrollBy(int x, int y) {
8380
* @return Size of the form element.
8481
*/
8582
public Dimension getSize() {
86-
return getFormLabel().getElement().getSize();
83+
return getFormLabel().visual().getSize();
8784
}
8885

8986

@@ -94,7 +91,7 @@ public Dimension getSize() {
9491
* @return Label of form element.
9592
*/
9693
protected ILabel getFormLabel() {
97-
return getElementFactory().getLabel(locator, name);
94+
return formLabel;
9895
}
9996

10097
/**
@@ -111,7 +108,18 @@ protected IElementFactory getElementFactory() {
111108
*
112109
* @return instance of localized logger.
113110
*/
114-
protected ILocalizedLogger getLogger() {
111+
@Override
112+
protected ILocalizedLogger getLocalizedLogger() {
115113
return AqualityServices.getLocalizedLogger();
116114
}
115+
116+
/**
117+
* Visualization configuration used by dump().
118+
*
119+
* @return instance of visualization configuration.
120+
*/
121+
@Override
122+
protected IVisualizationConfiguration getVisualizationConfiguration() {
123+
return AqualityServices.getConfiguration().getVisualizationConfiguration();
124+
}
117125
}

src/main/resources/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,13 @@
120120
},
121121
"elementCache": {
122122
"isEnabled": false
123+
},
124+
"visualization": {
125+
"imageExtension": "png",
126+
"maxFullFileNameLength": 255,
127+
"defaultThreshold": 0.012,
128+
"comparisonWidth": 16,
129+
"comparisonHeight": 16,
130+
"pathToDumps": "./src/test/resources/visualDumps/"
123131
}
124132
}

src/test/java/aquality/selenium/logger/LoggerTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class LoggerTests {
3333
private File appenderFile;
3434

3535
@BeforeMethod
36-
private void addMessagesAppender() throws IOException {
36+
private void addMessagesAppender() {
3737
appenderFile = getRandomAppenderFile();
3838
appender = getFileAppender(appenderFile);
3939
appender.start();
@@ -160,14 +160,13 @@ public void testErrorMessageShouldBeDisplayedAccordingToLogLevel() throws IOExce
160160
assertTrue(isFileContainsText(appenderFile, testMessage));
161161
}
162162

163-
private Appender getFileAppender(File file) throws IOException {
164-
Layout layout = PatternLayout.newBuilder().withPattern("%m%n").build();
165-
FileAppender fileAppender = FileAppender.newBuilder().setName("test")
163+
private Appender getFileAppender(File file) {
164+
Layout<String> layout = PatternLayout.newBuilder().withPattern("%m%n").build();
165+
return FileAppender.newBuilder().setName("test")
166166
.setLayout(layout)
167167
.withFileName(file.getPath())
168168
.withAppend(true)
169169
.build();
170-
return fileAppender;
171170
}
172171

173172
private boolean isFileContainsText(File file, String line) throws IOException {

src/test/java/automationpractice/forms/ProductListForm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public ProductListForm() {
2525
}
2626

2727
public List<ILabel> getProductContainerLabels(){
28-
return getElementFactory().findElements(By.xpath(XPATH_PRODUCT_CONTAINER), ElementType.LABEL, ElementsCount.MORE_THEN_ZERO, ElementState.DISPLAYED);
28+
return getElementFactory().findElements(By.xpath(XPATH_PRODUCT_CONTAINER), ElementType.LABEL, ElementsCount.MORE_THAN_ZERO, ElementState.DISPLAYED);
2929
}
3030

3131
private ILabel getLblFirstProduct(){

src/test/java/automationpractice/forms/YourPersonalInfoForm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void setFirstName(String firstName){
3535
}
3636

3737
public Integer getNumOfDays(){
38-
List<ILabel> lblDays = getElementFactory().findElements(By.xpath(XPATH_SELECT_DAYS), ElementType.LABEL, ElementsCount.MORE_THEN_ZERO, ElementState.EXISTS_IN_ANY_STATE);
38+
List<ILabel> lblDays = getElementFactory().findElements(By.xpath(XPATH_SELECT_DAYS), ElementType.LABEL, ElementsCount.MORE_THAN_ZERO, ElementState.EXISTS_IN_ANY_STATE);
3939
return lblDays.size();
4040
}
4141

src/test/java/tests/integration/BrowserTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void testShouldBePossibleToScrollWindowBy(){
184184
WelcomeForm scrollForm = new WelcomeForm();
185185
getBrowser().goTo(scrollForm.getUrl());
186186
int initialY = scrollForm.getFormPointInViewPort().getY();
187-
int formHeight = scrollForm.getSize().getHeight();
187+
int formHeight = (int) scrollForm.getSize().getHeight();
188188
getBrowser().scrollWindowBy(0, formHeight);
189189
Assert.assertEquals(initialY - scrollForm.getFormPointInViewPort().getY(), formHeight);
190190
}

src/test/java/tests/integration/ElementTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void testCheckBox() {
8383
navigate(TheInternetPage.CHECKBOXES);
8484
String checkboxLocator = "//input[@type='checkbox']";
8585
List<ICheckBox> checkBoxes = elementFactory.findElements(By.xpath(checkboxLocator), ICheckBox.class,
86-
ElementsCount.MORE_THEN_ZERO, ElementState.DISPLAYED);
86+
ElementsCount.MORE_THAN_ZERO, ElementState.DISPLAYED);
8787
ICheckBox checkBox1 = checkBoxes.get(0);
8888
ICheckBox checkBox2 = checkBoxes.get(1);
8989
boolean stateFirst = checkBox1.isChecked();
@@ -108,7 +108,7 @@ public void testCheckBoxJsActions() {
108108
navigate(TheInternetPage.CHECKBOXES);
109109
String checkboxLocator = "//input[@type='checkbox']";
110110
List<ICheckBox> checkBoxes = elementFactory.findElements(By.xpath(checkboxLocator), ICheckBox.class,
111-
ElementsCount.MORE_THEN_ZERO, ElementState.DISPLAYED);
111+
ElementsCount.MORE_THAN_ZERO, ElementState.DISPLAYED);
112112
ICheckBox checkBox1 = checkBoxes.get(0);
113113
ICheckBox checkBox2 = checkBoxes.get(1);
114114
boolean stateFirst = checkBox1.getJsActions().isChecked();

src/test/java/tests/integration/HiddenElementsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ public void testHiddenElementExist() {
4747

4848
@Test(dataProvider = "getHiddenElementListProviders")
4949
public void testHiddenElementsExist(Function<ElementsCount, List<ILabel>> elementsListProvider) {
50-
List<ILabel> listElements = elementsListProvider.apply(ElementsCount.MORE_THEN_ZERO);
50+
List<ILabel> listElements = elementsListProvider.apply(ElementsCount.MORE_THAN_ZERO);
5151
Assert.assertFalse(listElements.isEmpty());
5252
Assert.assertTrue(listElements.stream().allMatch(el -> el.state().isExist()));
5353
}
5454

5555
@Test(dataProvider = "getHiddenElementListProviders")
5656
public void testHiddenElementsNotDisplayed(Function<ElementsCount, List<ILabel>> elementsListProvider) {
57-
List<ILabel> listElements = elementsListProvider.apply(ElementsCount.MORE_THEN_ZERO);
57+
List<ILabel> listElements = elementsListProvider.apply(ElementsCount.MORE_THAN_ZERO);
5858
Assert.assertFalse(listElements.isEmpty());
5959
Assert.assertTrue(listElements.stream().noneMatch(el -> el.state().isDisplayed()));
6060
}

0 commit comments

Comments
 (0)