Skip to content

Commit 072cd20

Browse files
authored
Merge pull request #12 from ITArray/1.4.2
[1.4.2] - refactoring and re-sctructure of UIValidator classes.
2 parents 3ffc3d5 + e6252df commit 072cd20

11 files changed

+490
-485
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.itarray</groupId>
88
<artifactId>automotion</artifactId>
9-
<version>1.4.1</version>
9+
<version>1.4.2</version>
1010
<name>Automotion</name>
1111
<description>Library for automation testing</description>
1212
<url>https://www.itarray.net</url>

src/main/java/util/driver/MobileHelper.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ private void getAdbPath(){
8686
private static OSType getOperatingSystemType() {
8787
if (detectedOS == null) {
8888
String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
89-
if ((OS.indexOf("mac") >= 0) || (OS.indexOf("darwin") >= 0)) {
89+
if ((OS.contains("mac")) || (OS.contains("darwin"))) {
9090
detectedOS = OSType.MacOS;
91-
} else if (OS.indexOf("win") >= 0) {
91+
} else if (OS.contains("win")) {
9292
detectedOS = OSType.Windows;
93-
} else if (OS.indexOf("nux") >= 0) {
93+
} else if (OS.contains("nux")) {
9494
detectedOS = OSType.Linux;
9595
} else {
9696
detectedOS = OSType.Other;

src/main/java/util/general/HtmlReportBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private Html buildHtml() throws IOException, ParseException {
109109
String numE = (String) reason.get(MESSAGE);
110110

111111
new Li(this) {{
112-
new NoTag(this, numE.toString());
112+
new NoTag(this, numE);
113113
}};
114114
}
115115
}};

src/main/java/util/general/SystemHelper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static boolean isRetinaDisplay() {
1717
if (field != null) {
1818
field.setAccessible(true);
1919
Object scale = field.get(graphicsDevice);
20-
if (scale instanceof Integer && ((Integer) scale).intValue() == 2) {
20+
if (scale instanceof Integer && (Integer) scale == 2) {
2121
isRetina = true;
2222
}
2323
}
@@ -60,6 +60,6 @@ public static String hexStringToARGB(String hexARGB) throws IllegalArgumentExcep
6060
public static boolean isAutomotionFolderExists(){
6161
File file = new File(TARGET_AUTOMOTION_JSON);
6262

63-
return file != null && file.exists() && file.isDirectory() && file.list().length > 0;
63+
return file.exists() && file.isDirectory() && file.list() != null && file.list().length > 0;
6464
}
6565
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package util.validator;
2+
3+
public interface ChunkValidator {
4+
5+
ResponsiveUIChunkValidator alignedAsGrid(int horizontalGridSize);
6+
7+
ResponsiveUIChunkValidator alignedAsGrid(int horizontalGridSize, int verticalGridSize);
8+
9+
ResponsiveUIChunkValidator areNotOverlappedWithEachOther();
10+
11+
ResponsiveUIChunkValidator withSameSize();
12+
13+
}

src/main/java/util/validator/LanguageChecker.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,16 @@ public static boolean isCorrectLanguageOnThePage(WebDriver driver, String lang)
6666
if (bodyTextLength >= (i + textBlockLength)) {
6767
tempString = bodyText.substring(i, i + textBlockLength);
6868
try {
69-
String detectedLanguage = getRecognisedLanguage(tempString).get().getLanguage();
70-
71-
if (!detectedLanguage.toLowerCase().equals(lang.toLowerCase())) {
72-
LOG.info("\n!!! - Piece of text without translation: \n" + tempString + "\nExpected language is \"" + lang + "\"\n");
73-
LOG.info("\n!!! Current URL is " + driver.getCurrentUrl() + "\n- !!!");
74-
LOG.info(String.format("\n!!! Characters are between %s and %s from %s full amount of characters \n", i, i + textBlockLength, bodyTextLength));
75-
isCorrectLang = false;
76-
break;
69+
if (getRecognisedLanguage(tempString).isPresent()) {
70+
String detectedLanguage = getRecognisedLanguage(tempString).get().getLanguage();
71+
72+
if (!detectedLanguage.toLowerCase().equals(lang.toLowerCase())) {
73+
LOG.info("\n!!! - Piece of text without translation: \n" + tempString + "\nExpected language is \"" + lang + "\"\n");
74+
LOG.info("\n!!! Current URL is " + driver.getCurrentUrl() + "\n- !!!");
75+
LOG.info(String.format("\n!!! Characters are between %s and %s from %s full amount of characters \n", i, i + textBlockLength, bodyTextLength));
76+
isCorrectLang = false;
77+
break;
78+
}
7779
}
7880
} catch (Exception e) {
7981
LOG.info("\n!!! - Impossible to recognise the language of this piece of text: \n" + tempString + "\nExpected language is \"" + lang + "\"\n");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package util.validator;
2+
3+
import org.openqa.selenium.WebDriver;
4+
import org.openqa.selenium.WebElement;
5+
6+
import java.util.List;
7+
8+
public class ResponsiveUIChunkValidator extends ResponsiveUIValidator implements ChunkValidator {
9+
10+
ResponsiveUIChunkValidator(WebDriver driver, List<WebElement> elements) {
11+
super(driver);
12+
rootElements = elements;
13+
pageWidth = driver.manage().window().getSize().getWidth();
14+
pageHeight = driver.manage().window().getSize().getHeight();
15+
rootElement = rootElements.get(0);
16+
startTime = System.currentTimeMillis();
17+
}
18+
19+
@Override
20+
public ResponsiveUIChunkValidator alignedAsGrid(int horizontalGridSize) {
21+
validateGridAlignment(horizontalGridSize, 0);
22+
return this;
23+
}
24+
25+
@Override
26+
public ResponsiveUIChunkValidator alignedAsGrid(int horizontalGridSize, int verticalGridSize) {
27+
validateGridAlignment(horizontalGridSize, verticalGridSize);
28+
return this;
29+
}
30+
31+
@Override
32+
public ResponsiveUIChunkValidator areNotOverlappedWithEachOther() {
33+
validateElementsAreNotOverlapped(rootElements);
34+
return this;
35+
}
36+
37+
@Override
38+
public ResponsiveUIChunkValidator withSameSize() {
39+
validateSameSize(rootElements);
40+
return this;
41+
}
42+
}

0 commit comments

Comments
 (0)