Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
fix selenoid capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
kosteman committed Oct 4, 2022
1 parent 423c8f1 commit 9740430
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import ru.sbtqa.tag.pagefactory.properties.Configuration;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;

public class SelenoidCapabilitiesParser implements CapabilitiesParser {
Expand All @@ -32,45 +34,38 @@ public DesiredCapabilities parse() {
String logName = getProperty(PROPERTIES.getSelenoidLogName());
String videoName = getProperty(PROPERTIES.getSelenoidVideoName());

HashMap<String, Object> selenoidOptions = new HashMap<>();
selenoidOptions.put("enableVNC", PROPERTIES.getSelenoidEnableVNC());
selenoidOptions.put("enableLog", PROPERTIES.getSelenoidEnableLog());
selenoidOptions.put("screenResolution", PROPERTIES.getSelenoidScreenResolution());
selenoidOptions.put("enableVideo", PROPERTIES.getSelenoidEnableVideo());
selenoidOptions.put("videoScreenSize", PROPERTIES.getSelenoidVideoScreenSize());
if (!PROPERTIES.getSelenoidVideoFrameRate().equals("")) {
selenoidOptions.put("videoFrameRate", Integer.parseInt(PROPERTIES.getSelenoidVideoFrameRate()));
}
selenoidOptions.put("name", name);
selenoidOptions.put("logName", String.format(UNIQUE_NAME_FORMAT + ".log", logName));
selenoidOptions.put("videoName", String.format(UNIQUE_NAME_FORMAT + ".mp4", videoName));
selenoidOptions.put("timeZone", PROPERTIES.getSelenoidTimeZone());
if (!PROPERTIES.getSelenoidApplicationContainers().equals("")) {
selenoidOptions.put("applicationContainers", Arrays.asList(PROPERTIES.getSelenoidApplicationContainers().split(",")));
}
if (!PROPERTIES.getSelenoidHostEntries().equals("")) {
selenoidOptions.put("hostsEntries", Arrays.asList(PROPERTIES.getSelenoidHostEntries().split(",")));
}
if (!PROPERTIES.getSelenoidContainerLabels().equals("")) {
selenoidOptions.put("labels", Arrays.asList(PROPERTIES.getSelenoidContainerLabels().split(",")));
}
selenoidOptions.put("sessionTimeout", PROPERTIES.getSelenoidSessionTimeout());

setCapability("enableVNC", PROPERTIES.getSelenoidEnableVNC());
setCapability("enableLog", PROPERTIES.getSelenoidEnableLog());
setCapability("screenResolution", PROPERTIES.getSelenoidScreenResolution());
setCapability("enableVideo", PROPERTIES.getSelenoidEnableVideo());
setCapability("videoScreenSize", PROPERTIES.getSelenoidVideoScreenSize());
setCapability("videoFrameRate", PROPERTIES.getSelenoidVideoFrameRate());
setCapability("name", name);
setCapability("logName", logName, UNIQUE_NAME_FORMAT + ".log");
setCapability("videoName", videoName, UNIQUE_NAME_FORMAT + ".mp4");
setCapability("timeZone", PROPERTIES.getSelenoidTimeZone());
setCapability("hostsEntries", PROPERTIES.getSelenoidHostEntries());
setCapability("applicationContainers", PROPERTIES.getSelenoidApplicationContainers());
setCapability("labels", PROPERTIES.getSelenoidContainerLabels());
setCapability("sessionTimeout", PROPERTIES.getSelenoidSessionTimeout());

capabilities.setCapability("selenoid:options", selenoidOptions);
return capabilities;
}

private String getProperty(String property) {
return property.trim().isEmpty() && Environment.getScenario() != null ? Environment.getScenario().getName() : property;
}

private void setCapability(String capabilityName, String capabilityValue, String format) {
if (!capabilityValue.isEmpty()) {
capabilities.setCapability(capabilityName, String.format(format, capabilityValue));
} else {
LOG.info("Capability \"{}\" for Selenoid isn't set. Using default capability.", capabilityName);
}
}

private void setCapability(String capabilityName, String capabilityValue) {
setCapability(capabilityName, capabilityValue, "%s");
}

private void setCapability(String capabilityName, boolean capabilityValue) {
capabilities.setCapability(capabilityName, capabilityValue);
}

private void setVersion(String capabilityValue) {
if (!capabilityValue.isEmpty()) {
capabilities.setVersion(capabilityValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.IOSMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -80,7 +79,7 @@ public void mountDriver() {
mobileDriver = PROPERTIES.getAppiumPlatformName().equals("IOS") ? new IOSDriver(url, capabilities) : new AndroidDriver(url, capabilities);

if (PROPERTIES.getAppiumPlatformName().equals("ANDROID")) {
((AndroidDriver) mobileDriver).setSetting(Setting.WAIT_FOR_IDLE_TIMEOUT, PROPERTIES.getWaitForIdleTimeout());
mobileDriver.setSetting(Setting.WAIT_FOR_IDLE_TIMEOUT, PROPERTIES.getWaitForIdleTimeout());
}

if (PROPERTIES.getAppiumVideoEnabled()) {
Expand Down

0 comments on commit 9740430

Please sign in to comment.