Skip to content

Commit

Permalink
Merge pull request serenity-bdd#2127 from renatomefi/fix/desiredcapat…
Browse files Browse the repository at this point in the history
…ibilities-factory-deprecation

Stop using deprecated DesiredCapabilities in main
  • Loading branch information
wakaleo authored Jun 12, 2020
2 parents aa52378 + 2bd2c0d commit 2437e7f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.serenitybdd.core.webdriver.driverproviders;

import com.google.common.base.Optional;
import com.google.gson.JsonObject;
import net.serenitybdd.core.webdriver.servicepools.DriverServiceExecutable;
import net.thucydides.core.ThucydidesSystemProperty;
import net.thucydides.core.util.EnvironmentVariables;
Expand All @@ -10,7 +8,6 @@
import net.thucydides.core.webdriver.chrome.OptionsSplitter;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
Expand Down Expand Up @@ -42,11 +39,7 @@ public ChromeDriverCapabilities(EnvironmentVariables environmentVariables, Strin

@Override
public DesiredCapabilities getCapabilities() {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();

ChromeOptions chromeOptions = configuredOptions();

capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
DesiredCapabilities capabilities = new DesiredCapabilities(configuredOptions());

String chromeSwitches = ThucydidesSystemProperty.CHROME_SWITCHES.from(environmentVariables);
capabilities.setCapability("chrome.switches", chromeSwitches);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.thucydides.core.webdriver.SupportedWebDriver;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.Platform;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.util.Map;
Expand Down Expand Up @@ -74,7 +75,7 @@ private Map<SupportedWebDriver, DriverCapabilitiesProvider> driverCapabilitiesSe
selectors.put(HTMLUNIT, DesiredCapabilities::htmlUnit);
selectors.put(OPERA, DesiredCapabilities::operaBlink);
selectors.put(IEXPLORER, DesiredCapabilities::internetExplorer);
selectors.put(EDGE, DesiredCapabilities::edge);
selectors.put(EDGE, () -> new DesiredCapabilities(new EdgeOptions()));
selectors.put(PHANTOMJS, DesiredCapabilities::phantomjs);
selectors.put(IPHONE, DesiredCapabilities::iphone);
selectors.put(ANDROID, DesiredCapabilities::android);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.thucydides.core.webdriver.stubs.WebDriverStub;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -40,7 +41,10 @@ public WebDriver newInstance(String options, EnvironmentVariables environmentVar
}

CapabilityEnhancer enhancer = new CapabilityEnhancer(environmentVariables, fixtureProviderService);
DesiredCapabilities desiredCapabilities = enhancer.enhanced(DesiredCapabilities.edge(), SupportedWebDriver.EDGE);
DesiredCapabilities desiredCapabilities = enhancer.enhanced(
new DesiredCapabilities(new EdgeOptions()),
SupportedWebDriver.EDGE);

driverProperties.registerCapabilities("edge", capabilitiesToProperties(desiredCapabilities));

SetProxyConfiguration.from(environmentVariables).in(desiredCapabilities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import net.thucydides.core.util.EnvironmentVariables;
import net.thucydides.core.webdriver.firefox.FirefoxProfileEnhancer;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.remote.CapabilityType;
Expand Down Expand Up @@ -46,8 +45,11 @@ public FirefoxDriverCapabilities(EnvironmentVariables environmentVariables, Stri
}

public DesiredCapabilities getCapabilities() {
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("firefox_profile",buildFirefoxProfile());
DesiredCapabilities capabilities = new DesiredCapabilities(new FirefoxOptions());

capabilities.setCapability("firefox_profile", buildFirefoxProfile());
capabilities.acceptInsecureCerts();

Map<String, Object> firefoxOptions = new HashMap<>();
String geckoOptions = (!options.isEmpty()) ? options : ThucydidesSystemProperty.GECKO_FIREFOX_OPTIONS.from(environmentVariables,"");
if (!geckoOptions.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.thucydides.core.webdriver;

import net.serenitybdd.core.webdriver.OverrideDriverCapabilities;
import net.serenitybdd.core.webdriver.driverproviders.AddCustomDriverCapabilities;
import net.serenitybdd.core.webdriver.driverproviders.AddEnvironmentSpecifiedDriverCapabilities;
import net.thucydides.core.fixtureservices.FixtureProviderService;
Expand Down Expand Up @@ -29,7 +28,7 @@ public CapabilityEnhancer(EnvironmentVariables environmentVariables, FixtureProv

public DesiredCapabilities enhanced(DesiredCapabilities capabilities, SupportedWebDriver driver) {
CapabilitySet capabilitySet = new CapabilitySet(environmentVariables);
addExtraCapabiities(capabilities, capabilitySet);
addExtraCapabilities(capabilities, capabilitySet);
if (ACCEPT_INSECURE_CERTIFICATES.booleanFrom(environmentVariables,false)) {
capabilities.acceptInsecureCerts();
}
Expand All @@ -41,19 +40,18 @@ public DesiredCapabilities enhanced(DesiredCapabilities capabilities, SupportedW
Optional<TestOutcome> currentTestOutcome = StepEventBus.getEventBus()
.getBaseStepListener()
.latestTestOutcome();
if (currentTestOutcome != null) { // Technically not required but needed for some test scenarios
currentTestOutcome.ifPresent(
outcome -> AddCustomDriverCapabilities.from(environmentVariables)
.withTestDetails(driver, outcome)
.to(capabilities)
);
}
// Technically not required but needed for some test scenarios
currentTestOutcome.ifPresent(
outcome -> AddCustomDriverCapabilities.from(environmentVariables)
.withTestDetails(driver, outcome)
.to(capabilities)
);
}

return capabilities;
}

private void addExtraCapabiities(DesiredCapabilities capabilities, CapabilitySet capabilitySet) {
private void addExtraCapabilities(DesiredCapabilities capabilities, CapabilitySet capabilitySet) {
Map<String, Object> extraCapabilities = capabilitySet.getCapabilities();
for(String capabilityName : extraCapabilities.keySet()) {
capabilities.setCapability(capabilityName, extraCapabilities.get(capabilityName));
Expand Down

0 comments on commit 2437e7f

Please sign in to comment.