Skip to content

Commit

Permalink
#123 - Support global browser settings
Browse files Browse the repository at this point in the history
Small changes after review, added browser resolution as global browser setting
  • Loading branch information
Marcel Pfotenhauer committed Oct 20, 2020
1 parent e9f70af commit 4f998b5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 23 deletions.
26 changes: 21 additions & 5 deletions config/browser.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# configure your test environment and take over the values to this property file
#
# A browser profile is defined by a couple of properties. All of them need
# the prefix "browserprofile.<short tag>." (see examples below)
# the prefix "browserprofile.<configuration tag>." (see examples below)
# Some of these properties are optional, other are mandatory.
#
# browserprofile.<short tag>.<property>
# browserprofile.<configuration tag>.<property>
#
# valid values for property are: name, browser, version, platform, deviceName,
# deviceOrientation, chromeEmulationProfile, screenResolution, browserResolution,
Expand All @@ -19,9 +19,10 @@
#
#################################################################################
#
# <short tag> must be an string w/o any spaces.
# it is used to group desired properties for this browserprofile and will
# later referred by testcase annotations
# <configuration tag> must be a string w/o any spaces.
# it is used to group desired properties for this browser profile and will
# later referred by test case annotations

This comment has been minimized.

Copy link
@ckeiner

ckeiner Oct 21, 2020

IIRC, it should be

later be referred by test case annotations

This comment has been minimized.

Copy link
@occupant23

occupant23 Oct 21, 2020

Contributor

done

# ATTENTION: "global" is a reserved keyword and should not be used.
#
# .name: is a more detailed name of this browser/device test
#
Expand All @@ -34,8 +35,22 @@
# by default version references the browser version, but in case of
# saucelabs device emulation usage it may be used for the OS version instead
#
################################################################################
#
# Global properties
#
#################################################################################
#
# The following properties can be configured on a global level. A specific configuration
# on browser profile level will override the global value.
# Please check the "Optional properties" section for more details regarding the properties.
#
# browserprofile.global.pageLoadStrategy = normal|eager|none
# browserprofile.global.headless = true|false
# browserprofile.global.acceptInsecureCertificates = true|false
# browserprofile.global.browserResolution = 1200x900
#
##################################################################################
#
# Optional properties
#
Expand Down Expand Up @@ -84,6 +99,7 @@
# .arguments: Additional command line arguments for the browser to apply.
# As you can specify only on 'arguments' property for a browser at a time you need to chain multiple arguments.
# Multiple arguments are chained by semicolon (";") e.g.: `-window-position=0,0 ; -window-size=400,300`
#
################################################################################
# A local Chrome with a small window size
browserprofile.Chrome_1024x768.name = Chrome 1024x768
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public class BrowserConfigurationMapper

private static final String ORIENTATION = "orientation";

public BrowserConfiguration map(Map<String, String> browserProfileConfiguration, String globalHeadless, String globalAcceptIncecureCertificates,
String globalPageLoadStrategy)
public BrowserConfiguration map(Map<String, String> browserProfileConfiguration, String globalHeadless, String globalAcceptInsecureCertificates,
String globalPageLoadStrategy, String globalBrowserResolution)
{
BrowserConfiguration browserConfiguration = new BrowserConfiguration();

Expand Down Expand Up @@ -249,18 +249,11 @@ else if ("opera".equals(emulatedBrowser))
String browserResolution = browserProfileConfiguration.get(BROWSER_RESOLUTION);
if (!StringUtils.isEmpty(browserResolution))
{
// split the combined resolution string on every 'x', 'X' or ',' and remove all whitespace
// e.g: 1920x1080 or 1920, 1080

String[] browserWidthHeight = browserResolution.replaceAll("[\\s]", "").split("[xX,]");
if (!StringUtils.isEmpty(browserWidthHeight[0]))
{
browserConfiguration.setBrowserWidth(Integer.parseInt(browserWidthHeight[0]));
}
if (!StringUtils.isEmpty(browserWidthHeight[0]))
{
browserConfiguration.setBrowserHeight(Integer.parseInt(browserWidthHeight[1]));
}
setBrowserResolution(browserConfiguration, browserResolution);
}
else if (!StringUtils.isEmpty(globalBrowserResolution))
{
setBrowserResolution(browserConfiguration, globalBrowserResolution);
}

// page load strategy
Expand All @@ -276,9 +269,9 @@ else if (!StringUtils.isEmpty(globalPageLoadStrategy))
String acceptInsecureCerts = browserProfileConfiguration.get(ACCEPT_INSECURE_CERTS);
if (!StringUtils.isEmpty(acceptInsecureCerts))
capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, Boolean.parseBoolean(acceptInsecureCerts));
else if (!StringUtils.isEmpty(globalAcceptIncecureCertificates))
else if (!StringUtils.isEmpty(globalAcceptInsecureCertificates))
{
capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, Boolean.parseBoolean(globalAcceptIncecureCertificates));
capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, Boolean.parseBoolean(globalAcceptInsecureCertificates));
}

// headless
Expand Down Expand Up @@ -313,4 +306,20 @@ else if (!StringUtils.isEmpty(globalHeadless))

return browserConfiguration;
}

private void setBrowserResolution(BrowserConfiguration browserConfiguration, String browserResolution)
{
// split the combined resolution string on every 'x', 'X' or ',' and remove all whitespace
// e.g: 1920x1080 or 1920, 1080

String[] browserWidthHeight = browserResolution.replaceAll("[\\s]", "").split("[xX,]");
if (!StringUtils.isEmpty(browserWidthHeight[0]))
{
browserConfiguration.setBrowserWidth(Integer.parseInt(browserWidthHeight[0]));
}
if (!StringUtils.isEmpty(browserWidthHeight[0]))
{
browserConfiguration.setBrowserHeight(Integer.parseInt(browserWidthHeight[1]));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class MultibrowserConfiguration

private static final String BROWSER_GLOBAL_PAGE_LOAD_STRATEGY = BROWSER_PROFILE_PREFIX + "global.pageLoadStrategy";

private static final String BROWSER_GLOBAL_RESOLUTION = BROWSER_PROFILE_PREFIX + "global.browserResolution";

private Map<String, TestEnvironment> testEnvironments;

private Map<String, BrowserConfiguration> browserProfiles;
Expand Down Expand Up @@ -86,8 +88,9 @@ private void parseBrowserProfiles()
BrowserConfigurationMapper mapper = new BrowserConfigurationMapper();

String globalHeadless = browserProfileProperties.getProperty(BROWSER_GLOBAL_HEADLESS);
String globalAcceptIncecureCertificates = browserProfileProperties.getProperty(BROWSER_GLOBAL_ACCEPT_INSECURE_CERTIFICATES);
String globalAcceptInsecureCertificates = browserProfileProperties.getProperty(BROWSER_GLOBAL_ACCEPT_INSECURE_CERTIFICATES);
String globalPageLoadStrategy = browserProfileProperties.getProperty(BROWSER_GLOBAL_PAGE_LOAD_STRATEGY);
String globalBrowserResolution = browserProfileProperties.getProperty(BROWSER_GLOBAL_RESOLUTION);

for (String browserProfile : browserProfileKeys)
{
Expand All @@ -100,7 +103,8 @@ private void parseBrowserProfiles()
browserProfileConfiguration.put(subkey, value);
}
browserProfiles.put(browserProfile,
mapper.map(browserProfileConfiguration, globalHeadless, globalAcceptIncecureCertificates, globalPageLoadStrategy));
mapper.map(browserProfileConfiguration, globalHeadless, globalAcceptInsecureCertificates, globalPageLoadStrategy,
globalBrowserResolution));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public void testOverridingBrowsers1()
configuration.getCapabilities().getCapability(CapabilityType.ACCEPT_INSECURE_CERTS));
Assert.assertEquals(EnvironmentAndBrowserConfigurationTest.GLOBALPAGELOADSTRATEGY,
configuration.getCapabilities().getCapability(CapabilityType.PAGE_LOAD_STRATEGY));
Assert.assertEquals(EnvironmentAndBrowserConfigurationTest.GLOBALBROWSERRESOLUTION,
configuration.getBrowserWidth() + "x" + configuration.getBrowserHeight());
}

@Test
Expand All @@ -92,5 +94,7 @@ public void testOverridingBrowsers2()
configuration.getCapabilities().getCapability(CapabilityType.ACCEPT_INSECURE_CERTS));
Assert.assertEquals(EnvironmentAndBrowserConfigurationTest.BROWSER2PAGELOADSTRATEGY,
configuration.getCapabilities().getCapability(CapabilityType.PAGE_LOAD_STRATEGY));
Assert.assertEquals(EnvironmentAndBrowserConfigurationTest.BROWSER2RESOLUTION,
configuration.getBrowserWidth() + "x" + configuration.getBrowserHeight());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class EnvironmentAndBrowserConfigurationTest extends NeodymiumTest

public static final String GLOBALPAGELOADSTRATEGY = "eager";

public static final String GLOBALBROWSERRESOLUTION = "1200x900";

public static final String BROWSER2NAME = "My new name for Samsung S4";;

public static final Boolean BROWSER2HEADLESS = !GLOBALHEADLESS;
Expand All @@ -62,6 +64,8 @@ public class EnvironmentAndBrowserConfigurationTest extends NeodymiumTest

public static final String BROWSER2PAGELOADSTRATEGY = "none";

public static final String BROWSER2RESOLUTION = "1024x768";

@BeforeClass
public static void beforeClass() throws IOException
{
Expand Down Expand Up @@ -106,12 +110,14 @@ public static void beforeClass() throws IOException
properties3.put("browserprofile.global.headless", GLOBALHEADLESS.toString());
properties3.put("browserprofile.global.acceptInsecureCertificates", GLOBALACCEPTINSECURECERTIFICATES.toString());
properties3.put("browserprofile.global.pageLoadStrategy", GLOBALPAGELOADSTRATEGY);
properties3.put("browserprofile.global.browserResolution", GLOBALBROWSERRESOLUTION);
properties3.put("browserprofile.Galaxy_Note3_Emulation.name", BROWSERNAME);
properties3.put("browserprofile.Galaxy_Note3_Emulation.testEnvironment", ENVIRONMENTNAME);
properties3.put("browserprofile.Galaxy_Note4_Emulation.name", BROWSER2NAME);
properties3.put("browserprofile.Galaxy_Note4_Emulation.headless", BROWSER2HEADLESS.toString());
properties3.put("browserprofile.Galaxy_Note4_Emulation.acceptInsecureCertificates", BROWSER2ACCEPTINSECURECERTIFICATES.toString());
properties3.put("browserprofile.Galaxy_Note4_Emulation.pageLoadStrategy", BROWSER2PAGELOADSTRATEGY);
properties3.put("browserprofile.Galaxy_Note4_Emulation.browserResolution", BROWSER2RESOLUTION);
File tempConfigFile3 = new File("./config/dev-browser.properties");
writeMapToPropertiesFile(properties3, tempConfigFile3);
tempFiles.add(tempConfigFile3);
Expand Down

0 comments on commit 4f998b5

Please sign in to comment.