Skip to content

Commit c0bf175

Browse files
author
Denys Zaiats
committed
[master] - added support for EDGE driver. Added fix for UI validator
1 parent 634be69 commit c0bf175

File tree

6 files changed

+132
-46
lines changed

6 files changed

+132
-46
lines changed

src/main/java/environment/EnvironmentFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public static boolean isInternetExplorer() {
4949
return BROWSER != null && BROWSER.toUpperCase().equals("IE");
5050
}
5151

52+
public static boolean isEDGE() {
53+
BROWSER = System.getenv(EnvironmentConstants.BROWSER) != null ? System.getenv(EnvironmentConstants.BROWSER) : System.getProperty(EnvironmentConstants.BROWSER);
54+
return BROWSER != null && BROWSER.toUpperCase().equals("EDGE");
55+
}
56+
5257
public static boolean isAndroid() {
5358
String PLATFORM = System.getenv(EnvironmentConstants.PLATFORM) != null ? System.getenv(EnvironmentConstants.PLATFORM) : System.getProperty(EnvironmentConstants.PLATFORM);
5459
return PLATFORM != null && PLATFORM.toUpperCase().equals("ANDROID");

src/main/java/util/driver/CapabilitiesFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ private static DesiredCapabilities getRemoteDriverCapabilities() {
100100
capabilities = DesiredCapabilities.safari();
101101
} else if (isInternetExplorer()) {
102102
capabilities = DesiredCapabilities.internetExplorer();
103+
} else if (isEDGE()) {
104+
capabilities = DesiredCapabilities.edge();
103105
}
104106

105107
if (getMobileDeviveEmulation() != null) {

src/main/java/util/driver/WebDriverFactory.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.openqa.selenium.WebDriver;
88
import org.openqa.selenium.chrome.ChromeDriver;
99
import org.openqa.selenium.chrome.ChromeOptions;
10+
import org.openqa.selenium.edge.EdgeDriver;
1011
import org.openqa.selenium.firefox.FirefoxDriver;
1112
import org.openqa.selenium.ie.InternetExplorerDriver;
1213
import org.openqa.selenium.phantomjs.PhantomJSDriver;
@@ -39,6 +40,30 @@ public WebDriverFactory() {
3940
remoteUrlPath = getRemoteUrlPath();
4041
}
4142

43+
private static void setChromeDriver() {
44+
Platform platform = Platform.getCurrent();
45+
String chromeBinary = "src/main/resources/drivers/chromedriver"
46+
+ (platform.toString().toUpperCase().contains("WIN") ? ".exe" : "");
47+
System.setProperty("webdriver.chrome.driver", chromeBinary);
48+
}
49+
50+
private static void setGeckoDriver() {
51+
Platform platform = Platform.getCurrent();
52+
String geckoBinary = "src/main/resources/drivers/geckodriver"
53+
+ (platform.toString().toUpperCase().contains("WIN") ? ".exe" : "");
54+
System.setProperty("webdriver.gecko.driver", geckoBinary);
55+
}
56+
57+
private static void setIEDriver() {
58+
String ieBinary = "src/main/resources/drivers/IEDriverServer.exe";
59+
System.setProperty("webdriver.ie.driver", ieBinary);
60+
}
61+
62+
private static void setEdgeDriver() {
63+
String edgeBinary = "src/main/resources/drivers/MicrosoftWebDriver.exe";
64+
System.setProperty("webdriver.edge.driver", edgeBinary);
65+
}
66+
4267
public WebDriver getDriver() {
4368
if (isMobile()) {
4469
driver = getMobileDriver();
@@ -57,7 +82,6 @@ public WebDriver getDriver() {
5782
return driver;
5883
}
5984

60-
6185
public void updateCapabilities(Map<String, Object> mapCapabilities) {
6286
CapabilitiesFactory.updateCapabilities(capabilities, mapCapabilities);
6387
}
@@ -96,6 +120,9 @@ private WebDriver getLocalWebDriver() {
96120
} else if (isInternetExplorer()) {
97121
setIEDriver();
98122
webDriver = new InternetExplorerDriver();
123+
} else if (isEDGE()) {
124+
setEdgeDriver();
125+
webDriver = new EdgeDriver();
99126
}
100127

101128
return webDriver;
@@ -114,25 +141,4 @@ private RemoteWebDriver getRemoteWebDriver() {
114141

115142
return remoteWebDriver;
116143
}
117-
118-
private static void setChromeDriver() {
119-
Platform platform = Platform.getCurrent();
120-
String chromeBinary = "src/main/resources/drivers/chromedriver"
121-
+ (platform.toString().toUpperCase().contains("WIN") ? ".exe" : "");
122-
System.setProperty("webdriver.chrome.driver", chromeBinary);
123-
}
124-
125-
private static void setGeckoDriver() {
126-
Platform platform = Platform.getCurrent();
127-
String geckoBinary = "src/main/resources/drivers/geckodriver"
128-
+ (platform.toString().toUpperCase().contains("WIN") ? ".exe" : "");
129-
System.setProperty("webdriver.gecko.driver", geckoBinary);
130-
}
131-
132-
private static void setIEDriver() {
133-
Platform platform = Platform.getCurrent();
134-
String chromeBinary = "src/main/resources/drivers/IEDriverServer"
135-
+ (platform.toString().toUpperCase().contains("WIN") ? ".exe" : "");
136-
System.setProperty("webdriver.ie.driver", chromeBinary);
137-
}
138144
}

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

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.webfirmframework.wffweb.tag.html.stylesandsemantics.Div;
1212
import com.webfirmframework.wffweb.tag.htmlwff.NoTag;
1313
import org.apache.log4j.Logger;
14+
import org.jetbrains.annotations.NotNull;
1415
import org.json.simple.JSONArray;
1516
import org.json.simple.JSONObject;
1617
import org.json.simple.parser.JSONParser;
@@ -28,9 +29,44 @@ public class HtmlReportBuilder {
2829

2930
private final Logger LOG = Logger.getLogger(HtmlReportBuilder.class);
3031

32+
public void buildReport(String reportName) throws IOException, ParseException, InterruptedException {
33+
writeReport(reportName);
34+
}
35+
3136
public void buildReport() throws IOException, ParseException, InterruptedException {
37+
writeReport("result");
38+
}
39+
40+
private void writeReport(String reportName) throws InterruptedException, IOException, ParseException {
3241
Thread.sleep(3000);
33-
Html html = new Html(null, new Style("background-color: rgb(255,250,250)")) {{
42+
43+
Html html = buildHtml();
44+
45+
long ms = System.currentTimeMillis();
46+
47+
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(TARGET_AUTOMOTION + reportName + ms + ".html"), StandardCharsets.UTF_8))) {
48+
writer.write(html.toHtmlString());
49+
} catch (IOException ex) {
50+
LOG.error("Cannot create html report: " + ex.getMessage());
51+
}
52+
53+
try {
54+
File file = new File(TARGET_AUTOMOTION + "result" + ms + ".html");
55+
if (file.getParentFile().mkdirs()) {
56+
if (file.createNewFile()) {
57+
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
58+
writer.write(html.toHtmlString());
59+
writer.close();
60+
}
61+
}
62+
} catch (IOException e) {
63+
e.printStackTrace();
64+
}
65+
}
66+
67+
@NotNull
68+
private Html buildHtml() throws IOException, ParseException {
69+
return new Html(null, new Style("background-color: rgb(255,250,250)")) {{
3470
new Head(this) {{
3571
new TitleTag(this) {{
3672
new NoTag(this, "Automotion report");
@@ -82,30 +118,11 @@ public void buildReport() throws IOException, ParseException, InterruptedExcepti
82118
new Alt("screenshot"),
83119
new Style("width: 96%; margin-left:2%"));
84120
}};
121+
122+
while (!file.delete());
85123
}
86124
}
87125
}};
88126
}};
89-
90-
long ms = System.currentTimeMillis();
91-
92-
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(TARGET_AUTOMOTION + "result" + ms + ".html"), StandardCharsets.UTF_8))) {
93-
writer.write(html.toHtmlString());
94-
} catch (IOException ex) {
95-
LOG.error("Cannot create html report: " + ex.getMessage());
96-
}
97-
98-
try {
99-
File file = new File(TARGET_AUTOMOTION + "result" + ms + ".html");
100-
if (file.getParentFile().mkdirs()) {
101-
if (file.createNewFile()) {
102-
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
103-
writer.write(html.toHtmlString());
104-
writer.close();
105-
}
106-
}
107-
} catch (IOException e) {
108-
e.printStackTrace();
109-
}
110127
}
111128
}

src/main/java/util/validator/ResponsiveUIValidator.java

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public ResponsiveUIValidator findElements(List<WebElement> elements) {
8484
rootElements = elements;
8585
pageWidth = driver.manage().window().getSize().getWidth();
8686
pageHeight = driver.manage().window().getSize().getHeight();
87+
rootElement = rootElements.get(0);
8788
return this;
8889
}
8990

@@ -375,6 +376,13 @@ public ResponsiveUIValidator alignedAsGrid(int horizontalGridSize, int verticalG
375376
return this;
376377
}
377378

379+
@Override
380+
public ResponsiveUIValidator areNotOverlappedWithEachOther() {
381+
validateElementsAreNotOverlapped(rootElements);
382+
return this;
383+
}
384+
385+
378386
@Override
379387
public ResponsiveUIValidator drawMap() {
380388
withReport = true;
@@ -453,6 +461,15 @@ public void generateReport() {
453461
}
454462
}
455463

464+
@Override
465+
public void generateReport(String name) {
466+
try {
467+
new HtmlReportBuilder().buildReport(name);
468+
} catch (IOException | ParseException | InterruptedException e) {
469+
e.printStackTrace();
470+
}
471+
}
472+
456473
private void drawScreenshot() {
457474
g = img.createGraphics();
458475

@@ -488,6 +505,19 @@ private void drawScreenshot() {
488505
}
489506
}
490507

508+
private void validateElementsAreNotOverlapped(List<WebElement> rootElements) {
509+
for (WebElement el1 : rootElements) {
510+
for (WebElement el2 : rootElements) {
511+
if (!el1.equals(el2)) {
512+
if (elementsAreOverlapped(el1, el2)) {
513+
putJsonDetailsWithElement("Elements are overlapped", el1);
514+
break;
515+
}
516+
}
517+
}
518+
}
519+
}
520+
491521
private void validateGridAlignment(int horizontalGridSize, int verticalGridSize) {
492522
List<WebElement> row = new ArrayList<>();
493523
for (int i = 0; i < rootElements.size(); i++) {
@@ -730,10 +760,32 @@ private void validateLeftElement(WebElement leftElement) {
730760
private boolean elementsAreOverlapped(WebElement elementOverlapWith) {
731761
Point elLoc = elementOverlapWith.getLocation();
732762
Dimension elSize = elementOverlapWith.getSize();
733-
return (xRoot > elLoc.x && yRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
763+
return ((xRoot > elLoc.x && yRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
764+
|| (xRoot + widthRoot > elLoc.x && yRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
765+
|| (xRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot + heightRoot < elLoc.y + elSize.height)
766+
|| (xRoot + widthRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot + widthRoot < elLoc.y + elSize.height)) ||
767+
((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
768+
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
769+
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
770+
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot));
771+
}
772+
773+
private boolean elementsAreOverlapped(WebElement rootElement, WebElement elementOverlapWith) {
774+
Point elLoc = elementOverlapWith.getLocation();
775+
Dimension elSize = elementOverlapWith.getSize();
776+
int xRoot = rootElement.getLocation().x;
777+
int yRoot = rootElement.getLocation().y;
778+
int widthRoot = rootElement.getSize().width;
779+
int heightRoot = rootElement.getSize().height;
780+
781+
return ((xRoot > elLoc.x && yRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
734782
|| (xRoot + widthRoot > elLoc.x && yRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot < elLoc.y + elSize.height)
735783
|| (xRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot < elLoc.x + elSize.width && yRoot + heightRoot < elLoc.y + elSize.height)
736-
|| (xRoot + widthRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot + widthRoot < elLoc.y + elSize.height);
784+
|| (xRoot + widthRoot > elLoc.x && yRoot + heightRoot > elLoc.y && xRoot + widthRoot < elLoc.x + elSize.width && yRoot + widthRoot < elLoc.y + elSize.height)) ||
785+
((elLoc.x > xRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot)
786+
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot)
787+
|| (elLoc.x > xRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot && elLoc.y + elSize.height < yRoot + heightRoot)
788+
|| (elLoc.x > xRoot + widthRoot && elLoc.y > yRoot + heightRoot && elLoc.x + elSize.width < xRoot + widthRoot && elLoc.y + elSize.height < yRoot + widthRoot));
737789
}
738790

739791
private boolean elementsHasEqualLeftRightOffset(boolean isLeft, WebElement elementToCompare) {

src/main/java/util/validator/Validator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,14 @@ interface Validator {
8989

9090
ResponsiveUIValidator alignedAsGrid(int horizontalGridSize, int verticalGridSize);
9191

92+
ResponsiveUIValidator areNotOverlappedWithEachOther();
93+
9294
ResponsiveUIValidator drawMap();
9395

9496
boolean validate();
9597

9698
void generateReport();
9799

100+
void generateReport(String name);
101+
98102
}

0 commit comments

Comments
 (0)