Skip to content

Commit

Permalink
Version 2023.03.16: Fix browser names, better handle setup and teardo…
Browse files Browse the repository at this point in the history
…wn exceptions
  • Loading branch information
KMariusz committed Mar 16, 2023
1 parent 8b82019 commit 73e7f01
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 58 deletions.
6 changes: 3 additions & 3 deletions mrchecker-framework-modules/mrchecker-cli-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</parent>

<artifactId>mrchecker-cli-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
<packaging>jar</packaging>
<name>MrChecker - CLI - Module</name>
<description>MrChecker CLI Module supports:
Expand Down Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions mrchecker-framework-modules/mrchecker-core-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</parent>

<artifactId>mrchecker-core-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
<packaging>jar</packaging>
<name>MrChecker - Test core - Module</name>
<description>MrChecker Test Framework Core is responsible for:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public void beforeTestExecution(ExtensionContext context) {
try {
validateTestClassAndCallHook(context, BaseTest::setUp);
} catch (Throwable throwable) {
forEachObserver(ITestObserver::onSetupFailure);
try {
handleExecutionException(context, throwable, "setup", ITestObserver::onSetupFailure);
} catch (Throwable e) {
throw new RuntimeException(e);
}
throw throwable;
}
}
Expand All @@ -95,7 +99,11 @@ public void afterTestExecution(ExtensionContext context) {
try {
validateTestClassAndCallHook(context, BaseTest::tearDown);
} catch (Throwable throwable) {
forEachObserver(ITestObserver::onTeardownFailure);
try {
handleExecutionException(context, throwable, "teardown", ITestObserver::onTeardownFailure);
} catch (Throwable e) {
throw new RuntimeException(e);
}
throw throwable;
}
}
Expand Down
6 changes: 3 additions & 3 deletions mrchecker-framework-modules/mrchecker-database-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</parent>

<artifactId>mrchecker-database-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
<packaging>jar</packaging>
<name>MrChecker - Database - Module</name>
<description>MrChecker Database Module:
Expand Down Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</dependency>

<!-- JPA dependencies -->
Expand Down
8 changes: 4 additions & 4 deletions mrchecker-framework-modules/mrchecker-mobile-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</parent>

<artifactId>mrchecker-mobile-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
<packaging>jar</packaging>
<name>MrChecker - Mobile - Module</name>
<description>MrChecker Test Framework name supports:
Expand Down Expand Up @@ -52,12 +52,12 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-selenium-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</dependency>

<!--This dependency is necessary for Appium plugin. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</parent>

<artifactId>mrchecker-playwright-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
<packaging>jar</packaging>
<name>MrChecker - Playwright - Module</name>
<description>MrChecker Test Framework Playwright</description>
Expand Down Expand Up @@ -68,7 +68,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</dependency>

<!--This dependency is necessary for Playwright plugin. -->
Expand Down
6 changes: 3 additions & 3 deletions mrchecker-framework-modules/mrchecker-security-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</parent>

<artifactId>mrchecker-security-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
<packaging>jar</packaging>
<name>MrChecker - Security - Module</name>
<description>MrChecker Test Framework Security supports:
Expand Down Expand Up @@ -63,7 +63,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</dependency>

<!-- Needed to perform all API calls -->
Expand Down
6 changes: 3 additions & 3 deletions mrchecker-framework-modules/mrchecker-selenium-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</parent>

<artifactId>mrchecker-selenium-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
<packaging>jar</packaging>
<name>MrChecker - Selenium - Module</name>
<description>MrChecker Test Framework Selenium supports:
Expand Down Expand Up @@ -101,7 +101,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</dependency>

<!--This dependency is necessary for Selenium plugin. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,14 @@
* @author MBABIARZ
*/
public enum RuntimeParametersSelenium implements IRuntimeParameters {
BROWSER("browser", "chrome") {
protected void setValue() {
super.setValue();
paramValue = paramValue.toLowerCase();
if (paramValue.equals(INVALID_IE_NAME))
paramValue = VALID_IE_NAME;
}
},
BROWSER("browser", "chrome"),
BROWSER_VERSION("browserVersion", ""),
SELENIUM_GRID("seleniumGrid", ""),
OS("os", ""),
BROWSER_OPTIONS("browserOptions", "") {
public Map<String, Object> getValues() {
return Arrays.stream(getValue().split(BROWSER_OPTIONS_DELIMITER_REGEX))
.filter(i -> !i.isEmpty()) // remove
// empty
// inputs
.filter(i -> !i.trim().isEmpty()) // remove empty inputs
.map(i -> i.split(BROWSER_OPTIONS_KEY_VALUE_DELIMITER_REGEX, TOKENS_LIMIT)) // split to key, value.
// Not more than one time
.map(i -> new String[]{i[0], (i.length == 1) ? "" : i[1]}) // if value is empty, set empty text
Expand All @@ -42,8 +33,6 @@ public Map<String, Object> getValues() {
},
HEADLESS("headless", "false");

public static final String VALID_IE_NAME = "internet explorer";
public static final String INVALID_IE_NAME = "ie";
private static final int TOKENS_LIMIT = 2;
private static final String BROWSER_OPTIONS_KEY_VALUE_DELIMITER_REGEX = "=";
private static final String BROWSER_OPTIONS_DELIMITER_REGEX = ";";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

public class DriverManager {
private static final ThreadLocal<INewWebDriver> DRIVERS = new ThreadLocal<>();
Expand Down Expand Up @@ -339,6 +342,8 @@ private static void setBrowserName(DesiredCapabilities capabilities, MutableCapa
capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
break;
case IE:
capabilities.setCapability(InternetExplorerOptions.IE_OPTIONS, options);
break;
default:
throw new IllegalStateException("Unsupported browser: " + browserType);
}
Expand Down Expand Up @@ -472,26 +477,22 @@ private static <T extends RemoteWebDriver> void download(BrowserType browserType
wdm = WebDriverManager.getInstance(ChromeDriver.class);
driverPath = DriverManager.propertiesSelenium.getSeleniumChrome();
driverVersion = DriverManager.propertiesSelenium.getChromeDriverVersion().trim();
//System.setProperty("webdriver.chrome.driver", driverPath);
break;
case EDGE:
wdm = WebDriverManager.getInstance(EdgeDriver.class);
driverPath = DriverManager.propertiesSelenium.getSeleniumEdge();
driverVersion = DriverManager.propertiesSelenium.getEdgeDriverVersion().trim();
//System.setProperty("webdriver.edge.driver", browserPath);
break;
case FIREFOX:
wdm = WebDriverManager.getInstance(FirefoxDriver.class);
driverPath = DriverManager.propertiesSelenium.getSeleniumFirefox();
driverVersion = DriverManager.propertiesSelenium.getGeckoDriverVersion().trim();
//System.setProperty("webdriver.gecko.driver", browserPath);
System.setProperty("webdriver.firefox.logfile", "logs\\firefox_logs.txt");
break;
case IE:
wdm = WebDriverManager.getInstance(InternetExplorerDriver.class);
driverPath = DriverManager.propertiesSelenium.getSeleniumIE();
driverVersion = DriverManager.propertiesSelenium.getInternetExplorerDriverVersion().trim();
//System.setProperty("webdriver.ie.driver", browserPath);
break;
default:
throw new IllegalStateException("Unsupported browser: " + browserType);
Expand Down Expand Up @@ -560,7 +561,25 @@ public static BrowserType get(String browserName) {
return browserType;
}
}
throw new IllegalStateException("Unsupported browser: " + browserName);
//Names not included in Selenium 4 (W3C standard) but still in use
switch (browserName.toLowerCase()) {
case "edge":
case "msedge":
return EDGE;
case "ie":
return IE;
}

throw new IllegalStateException("Unsupported browser name: " + browserName + "\nSupported browsers names: " + getValidBrowsers());
}

public static Set<String> getValidBrowsers() {
Set<String> browsers = Arrays.stream(values()).map(browser -> browser.getBrowser().browserName()).collect(Collectors.toSet());
//Names not included in Selenium 4 (W3C standard) but still in use
browsers.add("edge");
browsers.add("msedge");
browsers.add("ie");
return browsers;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import java.util.Map;
import java.util.function.Consumer;

import static com.capgemini.mrchecker.selenium.core.base.runtime.RuntimeParametersSelenium.INVALID_IE_NAME;
import static com.capgemini.mrchecker.selenium.core.base.runtime.RuntimeParametersSelenium.VALID_IE_NAME;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
Expand Down Expand Up @@ -99,17 +97,6 @@ public void shouldGetReturnDefaultBrowserValueWhenNoSystemProperty() {
assertThat(browserValue, is(equalTo(DEFAULT_BROWSER_VALUE)));
}

@Test
public void shouldGetValidIEName() {
System.setProperty("browser", INVALID_IE_NAME);

refreshAllParameters();
String browserValue = RuntimeParametersSelenium.BROWSER.getValue();

assertThat(browserValue, is(equalTo(VALID_IE_NAME)));

}

@Test
public void shouldBrowserOptionBeBoolean() {
shouldBrowserOptionBeOfClass("true", Boolean.class);
Expand Down
6 changes: 3 additions & 3 deletions mrchecker-framework-modules/mrchecker-webapi-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</parent>

<artifactId>mrchecker-webapi-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
<packaging>jar</packaging>
<name>MrChecker - WebApi - Module</name>
<description>
Expand Down Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
</dependency>

<!-- Dependency to REST and SOAP lib -->
Expand Down
2 changes: 1 addition & 1 deletion mrchecker-framework-modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.capgemini.mrchecker</groupId>
<artifactId>mrchecker-test-framework</artifactId>
<version>2023.03.10</version>
<version>2023.03.16</version>
<name>MrChecker</name>
<description>MrChecker Test Framework is an automated testing framework for functional testing of web applications,
native mobile apps, webservices and database.
Expand Down

0 comments on commit 73e7f01

Please sign in to comment.