Skip to content

Commit

Permalink
Version 2023.03.20: Detect and fail on static Page/Endpoint object cr…
Browse files Browse the repository at this point in the history
…eation
  • Loading branch information
KMariusz committed Mar 20, 2023
1 parent 73e7f01 commit 1aabfe0
Show file tree
Hide file tree
Showing 25 changed files with 109 additions and 68 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.16</version>
<version>2023.03.20</version>
</parent>

<artifactId>mrchecker-cli-module</artifactId>
<version>2023.03.16</version>
<version>2023.03.20</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.16</version>
<version>2023.03.20</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.16</version>
<version>2023.03.20</version>
</parent>

<artifactId>mrchecker-core-module</artifactId>
<version>2023.03.16</version>
<version>2023.03.20</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
@@ -1,5 +1,6 @@
package com.capgemini.mrchecker.test.core;

import com.capgemini.mrchecker.test.core.exceptions.BFStaticVariableException;
import com.capgemini.mrchecker.test.core.logger.BFLogger;

public abstract class Page implements ITestObserver {
Expand Down Expand Up @@ -79,4 +80,15 @@ public void onTestExecutionException() {
public final void addToTestExecutionObserver() {
TEST_EXECUTION_OBSERVER.addObserver(this);
}

protected void verifyStaticObject(boolean allowStaticObject, String objectName) {
if (!allowStaticObject) {
StackTraceElement[] stackTrace = new Exception().getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
if (stackTraceElement.getMethodName().equalsIgnoreCase("<clinit>")) {
throw new BFStaticVariableException(objectName);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.capgemini.mrchecker.test.core.exceptions;

public class BFStaticVariableException extends RuntimeException {
private static final String MESSAGE_FORMAT = "Mr Checker does not support static %s variables";

public BFStaticVariableException(String objectName) {
super(String.format(MESSAGE_FORMAT, objectName));
}
}
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.16</version>
<version>2023.03.20</version>
</parent>

<artifactId>mrchecker-database-module</artifactId>
<version>2023.03.16</version>
<version>2023.03.20</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.16</version>
<version>2023.03.20</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.16</version>
<version>2023.03.20</version>
</parent>

<artifactId>mrchecker-mobile-module</artifactId>
<version>2023.03.16</version>
<version>2023.03.20</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.16</version>
<version>2023.03.20</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-selenium-module</artifactId>
<version>2023.03.16</version>
<version>2023.03.20</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.16</version>
<version>2023.03.20</version>
</parent>

<artifactId>mrchecker-playwright-module</artifactId>
<version>2023.03.16</version>
<version>2023.03.20</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.16</version>
<version>2023.03.20</version>
</dependency>

<!--This dependency is necessary for Playwright plugin. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public BasePage(com.microsoft.playwright.Page page) {
}

public BasePage(com.microsoft.playwright.Page page, BasePage parent) {
verifyStaticObject(PROPERTIES_PLAYWRIGHT.getAllowStaticPage(), "Page");
setParent(parent);
setPage(page);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class PropertiesPlaywright {
private String channel;
private String browsersPath = "./lib/playwright";
private int skipBrowserDownload = 0;
private boolean allowStaticPage = false;

@Inject(optional = true)
@SuppressWarnings("unused")
Expand Down Expand Up @@ -49,4 +50,14 @@ private void setSkipBrowserDownload(@Named("playwright.browser.skipDownload") in
public int getSkipBrowserDownload() {
return skipBrowserDownload;
}

@Inject(optional = true)
@SuppressWarnings("unused")
private void setAllowStaticPage(@Named("playwright.allowStaticPage") boolean value) {
this.allowStaticPage = value;
}

public boolean getAllowStaticPage() {
return allowStaticPage;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
playwright.browser.proxy=
playwright.browser.channel=
playwright.browser.downloadPath=./lib/playwright
playwright.browser.skipDownload=0
playwright.browser.skipDownload=0
playwright.allowStaticPage=false
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.16</version>
<version>2023.03.20</version>
</parent>

<artifactId>mrchecker-security-module</artifactId>
<version>2023.03.16</version>
<version>2023.03.20</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.16</version>
<version>2023.03.20</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.16</version>
<version>2023.03.20</version>
</parent>

<artifactId>mrchecker-selenium-module</artifactId>
<version>2023.03.16</version>
<version>2023.03.20</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.16</version>
<version>2023.03.20</version>
</dependency>

<!--This dependency is necessary for Selenium plugin. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public BasePage() {
}

public BasePage(BasePage parent) {
verifyStaticObject(PROPERTIES_SELENIUM.getAllowStaticPage(), "Page");
setParent(parent);

// If the page is not yet loaded, then load it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class PropertiesSelenium {
private String seleniumIE = webDrivers + "/internetexplorer/IEDriverServer.exe";
private String driverVersionIE = "";
private boolean driverAutoUpdateFlag = true;
private boolean allowStaticPage = false;

@Inject(optional = true)
@SuppressWarnings("unused")
Expand Down Expand Up @@ -104,4 +105,14 @@ private void setEdgeDriverVersion(@Named("wdm.edgeVersion") String version) {
public String getEdgeDriverVersion() {
return driverVersionEdge;
}

@Inject(optional = true)
@SuppressWarnings("unused")
private void setAllowStaticPage(@Named("selenium.allowStaticPage") boolean value) {
this.allowStaticPage = value;
}

public boolean getAllowStaticPage() {
return allowStaticPage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ selenium.firefox=./lib/webdrivers/firefox/geckodriver.exe
selenium.ie=./lib/webdrivers/internetexplorer/IEDriverServer.exe
selenium.edge=./lib/webdrivers/edge/msedgedriver.exe
selenium.driverAutoUpdate=true
wdm.chromeDriverVersion=83.0.4103.39
wdm.internetExplorerDriverVersion=
wdm.geckoDriverVersion=
wdm.edgeVersion=
selenium.allowStaticPage=false
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.16</version>
<version>2023.03.20</version>
</parent>

<artifactId>mrchecker-webapi-module</artifactId>
<version>2023.03.16</version>
<version>2023.03.20</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.16</version>
<version>2023.03.20</version>
</dependency>

<!-- Dependency to REST and SOAP lib -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.capgemini.mrchecker.test.core.base.properties.PropertiesSettingsModule;
import com.capgemini.mrchecker.test.core.logger.BFLogger;
import com.capgemini.mrchecker.webapi.core.base.driver.DriverManager;
import com.capgemini.mrchecker.webapi.core.base.properties.PropertiesFileSettings;
import com.capgemini.mrchecker.webapi.core.base.properties.PropertiesWebAPI;
import com.capgemini.mrchecker.webapi.core.base.runtime.RuntimeParameters;
import com.google.inject.Guice;
import io.restassured.config.RestAssuredConfig;
Expand All @@ -17,7 +17,7 @@

public abstract class BaseEndpoint extends Page implements IWebAPI {
private static DriverManager driver = null;
private final static PropertiesFileSettings propertiesFileSettings;
private final static PropertiesWebAPI PROPERTIES_WEB_API;
private final static IAnalytics ANALYTICS;
public final static String ANALYTICS_CATEGORY_NAME = "WebAPI-Module";

Expand All @@ -26,7 +26,7 @@ public abstract class BaseEndpoint extends Page implements IWebAPI {
ANALYTICS = BaseTest.getAnalytics();

// Get and then set properties information from selenium.settings file
propertiesFileSettings = setPropertiesSettings();
PROPERTIES_WEB_API = setPropertiesSettings();

// Read System or maven parameters
setRuntimeParametersWebApi();
Expand All @@ -35,6 +35,10 @@ public abstract class BaseEndpoint extends Page implements IWebAPI {
setEnvironmentInstance();
}

public BaseEndpoint() {
verifyStaticObject(PROPERTIES_WEB_API.getAllowStaticEndpoint(), "Endpoint");
}

public static IAnalytics getAnalytics() {
return ANALYTICS;
}
Expand All @@ -47,23 +51,23 @@ public ModuleType getModuleType() {
public static RequestSpecification getDriver() {
if (Objects.isNull(driver)) {
// Create module driver
driver = new DriverManager(propertiesFileSettings);
driver = new DriverManager(PROPERTIES_WEB_API);
}
return driver.getDriverWebAPI();
}

public static RequestSpecification getDriver(RestAssuredConfig config) {
if (Objects.isNull(driver)) {
// Create module driver
driver = new DriverManager(propertiesFileSettings);
driver = new DriverManager(PROPERTIES_WEB_API);
}
return driver.getDriverWebAPI(config);
}

private static PropertiesFileSettings setPropertiesSettings() {
private static PropertiesWebAPI setPropertiesSettings() {
// Get and then set properties information from settings.properties file
return Guice.createInjector(PropertiesSettingsModule.init())
.getInstance(PropertiesFileSettings.class);
.getInstance(PropertiesWebAPI.class);
}

private static void setRuntimeParametersWebApi() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.capgemini.mrchecker.webapi.core.base.driver;

import com.capgemini.mrchecker.test.core.logger.BFLogger;
import com.capgemini.mrchecker.webapi.core.base.properties.PropertiesFileSettings;
import com.capgemini.mrchecker.webapi.core.base.properties.PropertiesWebAPI;
import com.capgemini.mrchecker.webapi.core.base.runtime.RuntimeParameters;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
Expand All @@ -24,10 +24,10 @@

public class DriverManager {
private static final ThreadLocal<VirtualizedService> driverVirtualizedService = new ThreadLocal<>();
private static PropertiesFileSettings propertiesFileSettings;
private static PropertiesWebAPI propertiesFileSettings;

@Inject
public DriverManager(@Named("properties") PropertiesFileSettings propertiesFileSettings) {
public DriverManager(@Named("properties") PropertiesWebAPI propertiesFileSettings) {
if (Objects.isNull(DriverManager.propertiesFileSettings)) {
DriverManager.propertiesFileSettings = propertiesFileSettings;
}
Expand Down
Loading

0 comments on commit 1aabfe0

Please sign in to comment.