Skip to content

Commit

Permalink
Merge pull request #47 from AutomateThePlanet/smpInternal
Browse files Browse the repository at this point in the history
SMP Internal release 18-07-2024
  • Loading branch information
n1xan authored Aug 28, 2024
2 parents 8828946 + 3985911 commit f70deed
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 103 deletions.
10 changes: 0 additions & 10 deletions bellatrix.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,6 @@
<version>${rest.assured.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-secrets</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ public static <T> void register(T instance) {
public static <T> void register(Class<?> classKey, T instance) {
mapHolder.get().put(classKey, instance);
}

public static void clear() {
mapHolder.get().clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static boolean retry(Runnable action, Duration timeout, Duration sleepInt
return false;
}

public static void retry(Runnable action, Duration timeout, Duration sleepInterval, Class<? extends Throwable> ... exceptionsToIgnore) {
public static void retry(Runnable action, Duration sleepInterval, Duration timeout, Class<? extends Throwable> ... exceptionsToIgnore) {
Wait.retry(action, timeout, sleepInterval, true, exceptionsToIgnore);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static Browser initializeBrowserRegularMode() {
BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
launchOptions.setChannel("chrome");
launchOptions.setHeadless(false);
launchOptions.setArgs(List.of("--log-level=3", "--remote-allow-origins=*"));
launchOptions.setArgs(List.of("--log-level=3", "--remote-allow-origins=*", "--disable-search-engine-choice-screen"));
launchOptions.setTimeout(Settings.web().getArtificialDelayBeforeAction());
// System.setProperty("webdriver.chrome.silentOutput", "true"); ?

Expand All @@ -166,7 +166,7 @@ private static Browser initializeBrowserRegularMode() {
BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
launchOptions.setChannel("chrome");
launchOptions.setHeadless(true);
launchOptions.setArgs(List.of("--log-level=3"));
launchOptions.setArgs(List.of("--log-level=3", "--disable-search-engine-choice-screen"));
// System.setProperty("webdriver.chrome.silentOutput", "true"); ?

return browser(browserType.launch(launchOptions));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public boolean equals(Object obj) {
if (!(obj instanceof BrowserConfiguration))
return false;
BrowserConfiguration that = (BrowserConfiguration)obj;
if (!(this.getBrowser() == null ? that.getBrowser() == null : this.getBrowser().equals(that.getBrowser())))
if (!((this.getBrowser() == null) ? (that.getBrowser() == null) : this.getBrowser().equals(that.getBrowser())))
return false;
if (this.deviceName != that.deviceName)
return false;
if (!(this.getLifecycle() == null ? that.getLifecycle() == null : this.getLifecycle().equals(that.getLifecycle())))
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,50 @@
import solutions.bellatrix.core.configuration.ConfigurationService;
import solutions.bellatrix.core.plugins.Plugin;
import solutions.bellatrix.core.plugins.TestResult;
import solutions.bellatrix.core.utilities.DebugInformation;
import solutions.bellatrix.core.utilities.Log;
import solutions.bellatrix.core.utilities.SecretsResolver;
import solutions.bellatrix.web.configuration.WebSettings;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Objects;

public class BrowserLifecyclePlugin extends Plugin {
private static final ThreadLocal<BrowserConfiguration> CURRENT_BROWSER_CONFIGURATION;
private static final ThreadLocal<BrowserConfiguration> PREVIOUS_BROWSER_CONFIGURATION;
private static final ThreadLocal<Boolean> IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS;
private static final ThreadLocal<Boolean> IS_BROWSER_STARTED_CORRECTLY;

static {
CURRENT_BROWSER_CONFIGURATION = new ThreadLocal<>();
PREVIOUS_BROWSER_CONFIGURATION = new ThreadLocal<>();
IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS = ThreadLocal.withInitial(() -> false);
IS_BROWSER_STARTED_CORRECTLY = ThreadLocal.withInitial(() -> false);
}

@Override
public void preBeforeClass(Class type) {
if (Objects.equals(ConfigurationService.get(WebSettings.class).getExecutionType(), "regular")) {
CURRENT_BROWSER_CONFIGURATION.set(getExecutionBrowserClassLevel(type));
CURRENT_BROWSER_CONFIGURATION.set(getBrowserConfiguration(type));
if (shouldRestartBrowser()) {
shutdownBrowser();
startBrowser();
// TODO: maybe we can simplify and remove this parameter.
IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.set(true);
} else {
IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.set(false);
}
} else {
IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.set(false);
}

super.preBeforeClass(type);
}

@Override
public void postAfterClass(Class type) {
shutdownBrowser();
IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.set(false);
super.preAfterClass(type);
}

@Override
public void preBeforeTest(TestResult testResult, Method memberInfo) {
CURRENT_BROWSER_CONFIGURATION.set(getBrowserConfiguration(memberInfo));

if (!IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.get()) {
if (shouldRestartBrowser()) {
startBrowser();
}
if (shouldRestartBrowser()) {
shutdownBrowser();
startBrowser();
}

IS_BROWSER_STARTED_DURING_PRE_BEFORE_CLASS.set(false);
}

@Override
Expand Down Expand Up @@ -101,12 +88,11 @@ private void shutdownBrowser() {
}

private void startBrowser() {
// shutdownBrowser();
try {
DriverService.start(CURRENT_BROWSER_CONFIGURATION.get());
IS_BROWSER_STARTED_CORRECTLY.set(true);
} catch (Exception ex) {
DebugInformation.printStackTrace(ex);
Log.error("Error occurred while trying to start browser: %s".formatted(ex.getMessage()));
IS_BROWSER_STARTED_CORRECTLY.set(false);
}

Expand Down Expand Up @@ -142,6 +128,10 @@ private BrowserConfiguration getBrowserConfiguration(Method memberInfo) {
return result;
}

private BrowserConfiguration getBrowserConfiguration(Type classType) {
return getExecutionBrowserClassLevel((Class<?>)classType);
}

private BrowserConfiguration getExecutionBrowserMethodLevel(Method memberInfo) {
if (!memberInfo.isAnnotationPresent(ExecutionBrowser.class)) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,38 @@
@Getter
public enum DeviceName {
NOT_SET(),
IPHONE_13_PRO_MOBILE("iPhone 13 Pro", 375, 667, true, 2, true, true, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"),
IPHONE_SE_MOBILE("iPhone SE", 750, 1334, true, 2, true, true, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"),
IPHONE_X_MOBILE("iPhone X", 375, 667, true, 3, true, true, "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Version/10.0 Mobile/14D27 Safari/602.1"),
NEXUS_7_TABLET("Nexus 7", 600, 960, true, 2, true, true, "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 7 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Safari/537.36"),
IPAD("Apple iPad", 768, 1024, true, 2, true, true, "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3");
MOBILE_S("MOBILE_S", 300, 873, false, 1),
MOBILE_M("MOBILE_M", 320, 873, false, 1),
MOBILE_L("MOBILE_L", 393, 873, false, 1),
TABLET("TABLET", 768, 873, false, 1),
IPHONE_13_PRO_MOBILE("iPhone 13 Pro", 375, 667, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"),
IPHONE_12_PRO_MOBILE("iPhone 12 Pro", 390, 844, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"),
IPHONE_SE_MOBILE("iPhone SE", 375, 667, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A366 Safari/600.1.4"),
IPHONE_X_MOBILE("iPhone X", 375, 667, true, 2, "Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Version/10.0 Mobile/14D27 Safari/602.1"),
NEXUS_7_TABLET("Nexus 7", 600, 960, true, 2, "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 7 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Safari/537.36"),
IPAD("Apple iPad", 768, 1024, true, 2, "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3");

private final String name;
private final int width;
private final int height;
private final boolean isMobile;
private final int scaleFactor;
private final boolean supportsConsoleLogs;
private final boolean supportsFullPage;
private final String userAgent;

DeviceName(String name, int width, int height, boolean isMobile, int scaleFactor, boolean supportsConsoleLogs, boolean supportsFullPage) {
this(name, width, height, isMobile, scaleFactor, supportsConsoleLogs, supportsFullPage, null);
DeviceName(String name, int width, int height, boolean isMobile, int scaleFactor) {
this(name, width, height, isMobile, scaleFactor, null);
}

DeviceName() {
this(null, 0, 0, false, 0, false, false, null);
this(null, 0, 0, false, 0, "");
}

DeviceName(String name, int width, int height, boolean isMobile, int scaleFactor, boolean supportsConsoleLogs, boolean supportsFullPage, String userAgent) {
DeviceName(String name, int width, int height, boolean isMobile, int scaleFactor, String userAgent) {
this.name = name;
this.width = width;
this.height = height;
this.isMobile = isMobile;
this.scaleFactor = scaleFactor;
this.supportsConsoleLogs = supportsConsoleLogs;
this.supportsFullPage = supportsFullPage;
this.userAgent = userAgent;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private static WebDriver initializeDriverRegularMode() {
var chromeOptions = new ChromeOptions();
addDriverOptions(chromeOptions);
addDriverCapabilities(chromeOptions);
chromeOptions.addArguments("--log-level=3","--remote-allow-origins=*");
chromeOptions.addArguments("--log-level=3","--remote-allow-origins=*", "--disable-search-engine-choice-screen");
chromeOptions.setAcceptInsecureCerts(true);
chromeOptions.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
System.setProperty("webdriver.chrome.silentOutput", "true");
Expand All @@ -266,7 +266,7 @@ private static WebDriver initializeDriverRegularMode() {
var chromeHeadlessOptions = new ChromeOptions();
addDriverOptions(chromeHeadlessOptions);
chromeHeadlessOptions.setAcceptInsecureCerts(true);
chromeHeadlessOptions.addArguments("--log-level=3","--remote-allow-origins=*");
chromeHeadlessOptions.addArguments("--log-level=3","--remote-allow-origins=*", "--disable-search-engine-choice-screen");
chromeHeadlessOptions.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
chromeHeadlessOptions.addArguments("--headless=old");
System.setProperty("webdriver.chrome.silentOutput", "true");
Expand All @@ -278,19 +278,24 @@ private static WebDriver initializeDriverRegularMode() {
var chromeHeadlessOptions = new ChromeOptions();
addDriverOptions(chromeHeadlessOptions);
chromeHeadlessOptions.setAcceptInsecureCerts(true);
chromeHeadlessOptions.addArguments("--log-level=3","--remote-allow-origins=*");
chromeHeadlessOptions.addArguments("--log-level=3","--remote-allow-origins=*", "--disable-search-engine-choice-screen");
chromeHeadlessOptions.setCapability(CapabilityType.UNHANDLED_PROMPT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);

var deviceNameOption = new HashMap<String, String>();
deviceNameOption.put("deviceName", BROWSER_CONFIGURATION.get().getDeviceName().getName());
Map<String, Object> deviceMetrics = new HashMap<>();
deviceMetrics.put("width", BROWSER_CONFIGURATION.get().getDeviceName().getWidth());
deviceMetrics.put("height", BROWSER_CONFIGURATION.get().getDeviceName().getHeight());
deviceMetrics.put("pixelRatio", BROWSER_CONFIGURATION.get().getDeviceName().getScaleFactor());

chromeHeadlessOptions.setExperimentalOption("mobileEmulation", deviceNameOption);
Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("userAgent", "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19");

chromeHeadlessOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
System.setProperty("webdriver.chrome.silentOutput", "true");
if (shouldCaptureHttpTraffic) chromeHeadlessOptions.setProxy(proxyConfig);

driver = new TouchableWebDriver(chromeHeadlessOptions);
}

case FIREFOX -> {
var firefoxOptions = new FirefoxOptions();
addDriverOptions(firefoxOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static void waitForResponse(WebDriver driver, String requestPartialUrl, H
webDriverWait.until(d -> {
var harEntries = PROXY_SERVER.get().getHar().getLog().getEntries();
var isResponseReceived = harEntries.stream().anyMatch(
r -> r.getRequest().getUrl().contains(requestPartialUrl)
r -> (r.getRequest().getUrl().contains(requestPartialUrl) || r.getRequest().getUrl().contains(requestPartialUrl.replace("%20", "+")))
&& r.getRequest().getMethod().equals(httpMethod.toString())
&& successHttpStatusesList.contains(r.getResponse().getStatus())
&& (httpMethod.equals(HttpMethod.DELETE)? true : (r.getResponse().getContent().getText() != null && !r.getResponse().getContent().getText().isEmpty()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ public void triggerTapEvent(WebElement swipeFromElement)
tap.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
this.perform(Arrays.asList(tap));
}

public void triggerHoldEvent(WebElement swipeFromElement) {
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence tap = new Sequence(finger, 1);

int centerX = swipeFromElement.getLocation().x + swipeFromElement.getSize().getWidth() / 2;
int centerY = swipeFromElement.getLocation().y + swipeFromElement.getSize().getHeight() / 2;

// Move to the center of the element and perform a tap
tap.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), centerX, centerY));
tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
this.perform(Arrays.asList(tap));
}

//
// public void triggerTapEvent(WebElement tapElement)
// {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ public void open() {
}

protected void waitForPageLoad() {
browser().waitForAjax();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void close() {
}

DriverService.close();

SingletonFactory.clear();
disposed = true;
}
}
Loading

0 comments on commit f70deed

Please sign in to comment.