Skip to content

Commit 18b6f5b

Browse files
committed
Merge pull request #34 from robertgates55/electron-issue
Updates to correctly support native Electron applications
2 parents 6648f28 + 6c2b609 commit 18b6f5b

File tree

6 files changed

+63
-47
lines changed

6 files changed

+63
-47
lines changed

src/main/java/com/frameworkium/config/DriverSetup.java

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class DriverSetup {
1616
/**
1717
* List of supported drivers
1818
*/
19-
private enum SupportedBrowsers {
19+
public enum SupportedBrowsers {
2020
FIREFOX,CHROME,OPERA,IE,PHANTOMJS,SAFARI,ELECTRON
2121
}
2222

src/main/java/com/frameworkium/config/DriverType.java

100644100755
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package com.frameworkium.config;
22

3-
import static com.frameworkium.config.DriverSetup.useRemoteDriver;
4-
import static com.frameworkium.config.SystemProperty.APP_PATH;
5-
import static com.frameworkium.config.SystemProperty.GRID_URL;
6-
import static com.frameworkium.config.SystemProperty.MAXIMISE;
7-
import static com.frameworkium.config.SystemProperty.PROXY;
8-
3+
import com.frameworkium.capture.ScreenshotCapture;
4+
import com.frameworkium.listeners.CaptureListener;
5+
import com.frameworkium.listeners.EventListener;
96
import org.apache.logging.log4j.LogManager;
107
import org.apache.logging.log4j.Logger;
118
import org.openqa.selenium.Proxy;
@@ -14,9 +11,8 @@
1411
import org.openqa.selenium.remote.CapabilityType;
1512
import org.openqa.selenium.remote.DesiredCapabilities;
1613

17-
import com.frameworkium.capture.ScreenshotCapture;
18-
import com.frameworkium.listeners.CaptureListener;
19-
import com.frameworkium.listeners.EventListener;
14+
import static com.frameworkium.config.DriverSetup.useRemoteDriver;
15+
import static com.frameworkium.config.SystemProperty.*;
2016

2117
public abstract class DriverType {
2218

@@ -134,7 +130,7 @@ public void maximiseBrowserWindow() {
134130
* Method to tear down the driver object, can be overridden
135131
*/
136132
public void tearDownDriver() {
137-
this.webDriverWrapper.getWrappedDriver().quit();
133+
this.webDriverWrapper.quit();
138134
}
139135

140136
/**

src/main/java/com/frameworkium/config/drivers/ElectronImpl.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111
import java.util.Map;
1212

1313
import static com.frameworkium.config.SystemProperty.APP_PATH;
14-
import static com.frameworkium.config.SystemProperty.GRID_URL;
1514

1615
public class ElectronImpl extends DriverType {
1716

1817
private static URL remoteURL;
1918

19+
static {
20+
try {
21+
remoteURL = new URL("http://localhost:9515");
22+
} catch (MalformedURLException e) {
23+
e.printStackTrace();
24+
}
25+
}
26+
2027
@Override
2128
public DesiredCapabilities getDesiredCapabilities() {
2229
Map<String, String> chromeOptions = new HashMap<>();
@@ -25,17 +32,6 @@ public DesiredCapabilities getDesiredCapabilities() {
2532
} else {
2633
chromeOptions.put("binary", APP_PATH.getValue());
2734
}
28-
try {
29-
if (GRID_URL.isSpecified()) {
30-
remoteURL = new URL(GRID_URL.getValue());
31-
}
32-
else {
33-
remoteURL = new URL("http://localhost:9515");
34-
}
35-
}
36-
catch(MalformedURLException e) {
37-
throw new RuntimeException(e);
38-
}
3935
DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
4036
desiredCapabilities.setCapability("browserName", "chrome");
4137
desiredCapabilities.setCapability("chromeOptions", chromeOptions);
@@ -44,6 +40,6 @@ public DesiredCapabilities getDesiredCapabilities() {
4440

4541
@Override
4642
public WebDriver getWebDriverObject(DesiredCapabilities capabilities) {
47-
return new RemoteWebDriver(remoteURL ,capabilities);
43+
return new RemoteWebDriver(remoteURL, capabilities);
4844
}
4945
}

src/main/java/com/frameworkium/listeners/ScreenshotListener.java

100644100755
Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.frameworkium.listeners;
22

3-
import java.io.File;
4-
import java.io.FileOutputStream;
5-
import java.io.IOException;
6-
3+
import com.frameworkium.config.DriverSetup.SupportedBrowsers;
4+
import com.frameworkium.config.SystemProperty;
75
import com.frameworkium.config.WebDriverWrapper;
6+
import com.frameworkium.tests.internal.BaseTest;
87
import org.apache.logging.log4j.LogManager;
98
import org.apache.logging.log4j.Logger;
109
import org.openqa.selenium.OutputType;
@@ -13,11 +12,14 @@
1312
import org.openqa.selenium.remote.Augmenter;
1413
import org.testng.ITestResult;
1514
import org.testng.TestListenerAdapter;
16-
1715
import ru.yandex.qatools.allure.annotations.Attachment;
1816

19-
import com.frameworkium.config.SystemProperty;
20-
import com.frameworkium.tests.internal.BaseTest;
17+
import java.io.File;
18+
import java.io.FileOutputStream;
19+
import java.io.IOException;
20+
21+
import static com.frameworkium.config.SystemProperty.BROWSER;
22+
import static com.frameworkium.config.DriverSetup.SupportedBrowsers.ELECTRON;
2123

2224
public class ScreenshotListener extends TestListenerAdapter {
2325

@@ -85,13 +87,27 @@ private void takeScreenshot(String testName) {
8587
}
8688
}
8789

90+
/**
91+
* Are screenshots supported by the browser type being used
92+
*
93+
* @return boolean - true/false to whether screenshots are supported
94+
*/
95+
private boolean isScreenshotSupported() {
96+
if (BROWSER.isSpecified()) {
97+
return !SupportedBrowsers.valueOf(BROWSER.getValue().toUpperCase()).equals(ELECTRON);
98+
}
99+
else {
100+
return false;
101+
}
102+
}
103+
88104
@Override
89105
public void onTestFailure(ITestResult failingTest) {
90-
takeScreenshot(failingTest.getName());
106+
if (isScreenshotSupported()) takeScreenshot(failingTest.getName());
91107
}
92108

93109
@Override
94110
public void onTestSkipped(ITestResult skippedTest) {
95-
takeScreenshot(skippedTest.getName());
111+
if (isScreenshotSupported()) takeScreenshot(skippedTest.getName());
96112
}
97113
}

src/main/java/com/frameworkium/pages/internal/BasePage.java

100644100755
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.frameworkium.pages.internal;
22

3-
import java.lang.annotation.Annotation;
4-
import java.lang.reflect.Field;
5-
import java.util.List;
6-
import java.util.concurrent.TimeUnit;
7-
3+
import com.frameworkium.capture.model.Command;
4+
import com.frameworkium.config.SystemProperty;
5+
import com.frameworkium.reporting.AllureLogger;
6+
import com.frameworkium.tests.internal.BaseTest;
7+
import com.google.inject.Inject;
88
import com.paulhammant.ngwebdriver.WaitForAngularRequestsToFinish;
99
import org.apache.commons.lang.StringUtils;
1010
import org.apache.logging.log4j.LogManager;
@@ -15,16 +15,14 @@
1515
import org.openqa.selenium.WebElement;
1616
import org.openqa.selenium.support.ui.ExpectedConditions;
1717
import org.openqa.selenium.support.ui.WebDriverWait;
18-
1918
import ru.yandex.qatools.htmlelements.element.HtmlElement;
2019
import ru.yandex.qatools.htmlelements.element.TypifiedElement;
2120
import ru.yandex.qatools.htmlelements.loader.HtmlElementLoader;
2221

23-
import com.frameworkium.capture.model.Command;
24-
import com.frameworkium.config.SystemProperty;
25-
import com.frameworkium.reporting.AllureLogger;
26-
import com.frameworkium.tests.internal.BaseTest;
27-
import com.google.inject.Inject;
22+
import java.lang.annotation.Annotation;
23+
import java.lang.reflect.Field;
24+
import java.util.List;
25+
import java.util.concurrent.TimeUnit;
2826

2927
public abstract class BasePage<T extends BasePage<T>> {
3028

@@ -184,7 +182,13 @@ private void tryToEnsureWeHaveUnloadedOldPageAndNewPageIsReady() {
184182
* @return boolean - AngularJS true/false
185183
*/
186184
private boolean isPageAngularJS() {
187-
return executeJS("return typeof angular;").equals("object");
185+
try {
186+
return executeJS("return typeof angular;").equals("object");
187+
} catch (NullPointerException e) {
188+
logger.error("Detecting whether the page was angular returned a null object. This means your browser" +
189+
"hasn't started! Investigate into the issue.");
190+
return false;
191+
}
188192
}
189193

190194
/**

src/main/java/com/frameworkium/tests/internal/BaseTest.java

100644100755
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ protected ScreenshotCapture initialValue() {
8484
*/
8585
@BeforeMethod(alwaysRun = true)
8686
public static void configureBrowserBeforeTest(Method testMethod) {
87-
configureDriverBasedOnParams();
88-
initialiseNewScreenshotCapture(testMethod);
87+
try {
88+
configureDriverBasedOnParams();
89+
initialiseNewScreenshotCapture(testMethod);
90+
} catch (Exception e) {
91+
e.printStackTrace();
92+
}
8993
}
9094

9195
/**

0 commit comments

Comments
 (0)