Skip to content

Commit

Permalink
Added Browsers and Platforms objects to make these options more acces…
Browse files Browse the repository at this point in the history
…sible. Also added checks to ensure that the correct platforms and browsers are being passed through the Toolkit and subsequent SauceLabs API.
  • Loading branch information
dwhit88 committed Jan 18, 2019
1 parent 437a644 commit 82f32d5
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 19 deletions.
Binary file modified out/production/classes/framework/Drivers.class
Binary file not shown.
Binary file modified out/production/classes/gateways/sauceLabs/SauceLabsUtils.class
Binary file not shown.
Binary file modified out/test/classes/frameworkSandbox/DefaultConfig.class
Binary file not shown.
Binary file modified out/test/classes/frameworkSandbox/HoverOver.class
Binary file not shown.
7 changes: 7 additions & 0 deletions src/main/java/framework/Browsers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package framework;

public class Browsers {
public static String firefox = "firefox";
public static String chrome = "chrome";
public static String safari = "safari";
}
100 changes: 84 additions & 16 deletions src/main/java/framework/Drivers.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Drivers {
* test will run in the browser
*/
public static WebDriver driverInit(String browser, String appAddress, Boolean headless){
checkAvailableBrowsers(browser);
switch(browser){
case "firefox": return firefoxDriver(appAddress, headless);
case "chrome": return chromeDriver(appAddress, headless);
Expand Down Expand Up @@ -58,6 +59,16 @@ public static WebDriver driverInit(String browser, String appAddress, String pla
/**
* Sets the capabilities for the web driver based on given {@param browser} and {@param platform}.
*
* Note: PC platform options are: Windows 10, Windows 8.1, Windows 8, Windows 7, Linux
* Note: MAC platform options are:
* macOS 10.14 = Mojave
* macOS 10.13 = High Sierra
* macOS 10.12 = Sierra
* OS X 10.11 = El Capitan
* OS X 10.10 = Yosemite
* Note: Chrome version options are: 71.0 to 26.0
* Note: Firefox version options are: 64.0 to 4.0 (in addition to 25.0b2 and 21.0b1)
*
* @param platform the intended operating system that the test will run in
* @param browser the intended browser that the test will run in
*/
Expand All @@ -67,23 +78,20 @@ public static DesiredCapabilities setCaps(String browser, String platform){
switch (browser){
case "firefox":
caps = DesiredCapabilities.firefox();
caps.setCapability("version", "52.0");

switch (platform){
case "Windows 10": caps.setCapability("platform", platform); return caps;
default: return null;
}
caps.setCapability("version", "60.0"); break;
case "chrome":
caps = DesiredCapabilities.chrome();
caps.setCapability("version", "58");

switch (platform){
case "Windows 10": caps.setCapability("platform", platform); return caps;
default: return null;
}
default: return null;
}
}
caps.setCapability("version", "69.0"); break;
case "safari":
caps = DesiredCapabilities.safari();break;
default: caps = DesiredCapabilities.chrome(); caps.setCapability("version", "69.0");
break;
}

checkAvailablePlatforms(platform);
caps.setCapability("platform", platform);
return caps;
}

/**
* Sets up the Chrome web driver
Expand Down Expand Up @@ -149,9 +157,69 @@ public static WebDriver firefoxDriver(String appAddress, Boolean headless){
* @param driver the web driver through which the action will take place
* @param appAddress the url that the browser will load
*/
public static WebDriver checkAppAddress(WebDriver driver, String appAddress){
private static WebDriver checkAppAddress(WebDriver driver, String appAddress){
if (appAddress == null){ Assert.fail("Please provide an application URL."); }
driver.get(appAddress);
return driver;
}

/**
* Checks if {@param platform} matches a supported platform in SauceLabs.
*
* @param platform the intended operating system that the test will run in
*/
private static void checkAvailablePlatforms(String platform){
Boolean found = false;

for(String thisP : listOfPlatforms()){
if (platform.equals(thisP)){
found = true;
break;
}
}

if (!found){
Assert.fail("You must enter a valid platform that is handled by SauceLabs. Here are the available " +
"options: \n * For PC platforms: \"Windows 10\", \"Windows 8.1\", \"Windows 8\", \"Windows 7\", " +
"\"Linux\" \n * For MAC platforms: \"macOS 10.14\" (Mojave), \"macOS 10.13\" (High Sierra), " +
"\"macOS 10.12\" (Sierra), \"OS X 10.11\" (El Capitan), \"OS X 10.10\" (Yosemite)");
}
}

public static void checkAvailableBrowsers(String browser){
Boolean found = false;

for(String thisB : listOfBrowsers()){
if (browser.equals(thisB)){
found = true;
break;
}
}

if (!found){
Assert.fail("You must enter a valid platform that is handled by SauceLabs. Here are the available " +
"options: \"chrome\", \"firefox\", \"safari\"");
}
}

/**
* A list of platforms supported by SauceLabs
*/
private static String[] listOfPlatforms(){
return new String[]{"Windows 10", "Windows 8.1", "Windows 8", "Windows 7", "Linux",
"macOS 10.14", "macOS 10.13", "macOS 10.12", "OS X 10.11", "OS X 10.10"};
}

/**
* A list of browsers supported by the Toolkit
*/
private static String[] listOfBrowsers(){
return new String[]{"firefox", "chrome", "safari"};
}

// private static void checkPlatFormBrowserCompatability(String platform){
// if (System.getProperty("os.name").contains("Windows") && platform.equals("safari")){
// Assert.fail("Browser/Platform mismatch! ");
// }
// }
}
15 changes: 15 additions & 0 deletions src/main/java/framework/Platforms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package framework;

public class Platforms {
public static String mojave = "macOS 10.14";
public static String highSierra = "macOS 10.13";
public static String sierra = "macOS 10.12";
public static String elCapitan = "OS X 10.11";
public static String yosemite = "OS X 10.10";

public static String windows10 = "Windows 10";
public static String windows8_1 = "Windows 8.1";
public static String windows8 = "Windows 8";
public static String windows7 = "Windows 7";
public static String linux = "Linux";
}
1 change: 1 addition & 0 deletions src/main/java/gateways/sauceLabs/SauceLabsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static WebDriver sauceLabsConfig(String slUser, String slPass, String bro
if (slUser == null){ Assert.fail("Please provide a SauceLabs username"); }
if (slPass == null){ Assert.fail("Please provide a SauceLabs password"); }
if (appAddress == null){ Assert.fail("Please provide an application URL."); }
Drivers.checkAvailableBrowsers(browser);

try {
final String URL = "https://" + slUser + ":" + slPass + "@ondemand.saucelabs.com:443/wd/hub";
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/frameworkSandbox/DefaultConfig.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package frameworkSandbox;

import framework.Browsers;
import framework.Drivers;
import framework.Platforms;
import org.openqa.selenium.WebDriver;

import java.io.File;

public class DefaultConfig {

public static String platform = "Windows 10";
public static String browser = "chrome";
public static String platform = Platforms.windows10;
public static String browser = Browsers.chrome;
public static String appAddress;
public static Boolean headless = true;

Expand Down
8 changes: 7 additions & 1 deletion src/test/java/frameworkSandbox/HoverOver.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package frameworkSandbox;

import framework.Browsers;
import framework.Commands;
import framework.Drivers;
import framework.Platforms;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
Expand All @@ -19,7 +21,11 @@ public class HoverOver {
@BeforeTest
public static void beforeTest(){
DefaultConfig.appAddress = "https://www.amazon.com/";
d = DefaultConfig.defaultConfig();
DefaultConfig.runSauceLabs = true;
DefaultConfig.platform = Platforms.highSierra;
DefaultConfig.browser = Browsers.safari;
// d = DefaultConfig.defaultConfig();
d = DefaultConfig.defaultSauceLabsConfig();
PageFactory.initElements(d, HoverOver.class);
}

Expand Down

0 comments on commit 82f32d5

Please sign in to comment.