Skip to content

Commit

Permalink
Merge pull request #12 from ITArray/1.4.2
Browse files Browse the repository at this point in the history
[1.4.2] - refactoring and re-sctructure of UIValidator classes.
  • Loading branch information
dzaiats authored Dec 7, 2016
2 parents 3ffc3d5 + e6252df commit 072cd20
Show file tree
Hide file tree
Showing 11 changed files with 490 additions and 485 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.itarray</groupId>
<artifactId>automotion</artifactId>
<version>1.4.1</version>
<version>1.4.2</version>
<name>Automotion</name>
<description>Library for automation testing</description>
<url>https://www.itarray.net</url>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/util/driver/MobileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ private void getAdbPath(){
private static OSType getOperatingSystemType() {
if (detectedOS == null) {
String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((OS.indexOf("mac") >= 0) || (OS.indexOf("darwin") >= 0)) {
if ((OS.contains("mac")) || (OS.contains("darwin"))) {
detectedOS = OSType.MacOS;
} else if (OS.indexOf("win") >= 0) {
} else if (OS.contains("win")) {
detectedOS = OSType.Windows;
} else if (OS.indexOf("nux") >= 0) {
} else if (OS.contains("nux")) {
detectedOS = OSType.Linux;
} else {
detectedOS = OSType.Other;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/util/general/HtmlReportBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private Html buildHtml() throws IOException, ParseException {
String numE = (String) reason.get(MESSAGE);

new Li(this) {{
new NoTag(this, numE.toString());
new NoTag(this, numE);
}};
}
}};
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/util/general/SystemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static boolean isRetinaDisplay() {
if (field != null) {
field.setAccessible(true);
Object scale = field.get(graphicsDevice);
if (scale instanceof Integer && ((Integer) scale).intValue() == 2) {
if (scale instanceof Integer && (Integer) scale == 2) {
isRetina = true;
}
}
Expand Down Expand Up @@ -60,6 +60,6 @@ public static String hexStringToARGB(String hexARGB) throws IllegalArgumentExcep
public static boolean isAutomotionFolderExists(){
File file = new File(TARGET_AUTOMOTION_JSON);

return file != null && file.exists() && file.isDirectory() && file.list().length > 0;
return file.exists() && file.isDirectory() && file.list() != null && file.list().length > 0;
}
}
13 changes: 13 additions & 0 deletions src/main/java/util/validator/ChunkValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package util.validator;

public interface ChunkValidator {

ResponsiveUIChunkValidator alignedAsGrid(int horizontalGridSize);

ResponsiveUIChunkValidator alignedAsGrid(int horizontalGridSize, int verticalGridSize);

ResponsiveUIChunkValidator areNotOverlappedWithEachOther();

ResponsiveUIChunkValidator withSameSize();

}
18 changes: 10 additions & 8 deletions src/main/java/util/validator/LanguageChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ public static boolean isCorrectLanguageOnThePage(WebDriver driver, String lang)
if (bodyTextLength >= (i + textBlockLength)) {
tempString = bodyText.substring(i, i + textBlockLength);
try {
String detectedLanguage = getRecognisedLanguage(tempString).get().getLanguage();

if (!detectedLanguage.toLowerCase().equals(lang.toLowerCase())) {
LOG.info("\n!!! - Piece of text without translation: \n" + tempString + "\nExpected language is \"" + lang + "\"\n");
LOG.info("\n!!! Current URL is " + driver.getCurrentUrl() + "\n- !!!");
LOG.info(String.format("\n!!! Characters are between %s and %s from %s full amount of characters \n", i, i + textBlockLength, bodyTextLength));
isCorrectLang = false;
break;
if (getRecognisedLanguage(tempString).isPresent()) {
String detectedLanguage = getRecognisedLanguage(tempString).get().getLanguage();

if (!detectedLanguage.toLowerCase().equals(lang.toLowerCase())) {
LOG.info("\n!!! - Piece of text without translation: \n" + tempString + "\nExpected language is \"" + lang + "\"\n");
LOG.info("\n!!! Current URL is " + driver.getCurrentUrl() + "\n- !!!");
LOG.info(String.format("\n!!! Characters are between %s and %s from %s full amount of characters \n", i, i + textBlockLength, bodyTextLength));
isCorrectLang = false;
break;
}
}
} catch (Exception e) {
LOG.info("\n!!! - Impossible to recognise the language of this piece of text: \n" + tempString + "\nExpected language is \"" + lang + "\"\n");
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/util/validator/ResponsiveUIChunkValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package util.validator;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.List;

public class ResponsiveUIChunkValidator extends ResponsiveUIValidator implements ChunkValidator {

ResponsiveUIChunkValidator(WebDriver driver, List<WebElement> elements) {
super(driver);
rootElements = elements;
pageWidth = driver.manage().window().getSize().getWidth();
pageHeight = driver.manage().window().getSize().getHeight();
rootElement = rootElements.get(0);
startTime = System.currentTimeMillis();
}

@Override
public ResponsiveUIChunkValidator alignedAsGrid(int horizontalGridSize) {
validateGridAlignment(horizontalGridSize, 0);
return this;
}

@Override
public ResponsiveUIChunkValidator alignedAsGrid(int horizontalGridSize, int verticalGridSize) {
validateGridAlignment(horizontalGridSize, verticalGridSize);
return this;
}

@Override
public ResponsiveUIChunkValidator areNotOverlappedWithEachOther() {
validateElementsAreNotOverlapped(rootElements);
return this;
}

@Override
public ResponsiveUIChunkValidator withSameSize() {
validateSameSize(rootElements);
return this;
}
}
Loading

0 comments on commit 072cd20

Please sign in to comment.