Created
September 18, 2019 23:16
-
-
Save sauceaaron/6068a874883a377cdd0638736ff8f9d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.saucelabs.junit.ConcurrentParameterized; | |
| import com.saucelabs.saucerest.SauceREST; | |
| import org.junit.After; | |
| import org.junit.Before; | |
| import org.junit.Test; | |
| import org.junit.runner.RunWith; | |
| import org.openqa.selenium.remote.DesiredCapabilities; | |
| import org.openqa.selenium.remote.RemoteWebDriver; | |
| import java.net.MalformedURLException; | |
| import java.net.URL; | |
| import java.util.LinkedList; | |
| import static org.assertj.core.api.Assertions.assertThat; | |
| @RunWith(ConcurrentParameterized.class) | |
| public class CostcoTest | |
| { | |
| String SAUCE_USERNAME = System.getenv("SAUCE_USERNAME"); | |
| String SAUCE_ACCESS_KEY = System.getenv("SAUCE_ACCESS_KEY"); | |
| String SAUCE_URL = "https://" + SAUCE_USERNAME + ":" + SAUCE_ACCESS_KEY + "@" + "ondemand.saucelabs.com/wd/hub"; | |
| RemoteWebDriver driver; | |
| String sessionId; | |
| Boolean passed; | |
| SauceREST api; | |
| String platform; | |
| String browser; | |
| String version; | |
| String resolution; | |
| String WindowsResolution = "1440x900"; | |
| String MacOSResolution = "1400x1050"; | |
| public CostcoTest(String platform, String browser, String version) | |
| { | |
| this.platform = platform; | |
| this.browser = browser; | |
| this.version = version; | |
| this.resolution = platform.contains("Windows") ? WindowsResolution : MacOSResolution; | |
| } | |
| @ConcurrentParameterized.Parameters | |
| public static LinkedList browsers() | |
| { | |
| LinkedList browsers = new LinkedList(); | |
| browsers.add(new String[] { "Windows 7", "internet explorer", "11" }); | |
| browsers.add(new String[] { "Windows 7", "chrome", "latest" }); | |
| browsers.add(new String[] { "Windows 7", "firefox", "latest" }); | |
| browsers.add(new String[] { "Windows 10", "internet explorer", "11" }); | |
| browsers.add(new String[] { "Windows 10", "MicrosoftEdge", "latest" }); | |
| browsers.add(new String[] { "Windows 10", "chrome", "latest" }); | |
| browsers.add(new String[] { "Windows 10", "firefox", "latest" }); | |
| browsers.add(new String[] { "MacOS 10.14", "safari", "latest" }); | |
| browsers.add(new String[] { "MacOS 10.14", "chrome", "latest" }); | |
| browsers.add(new String[] { "MacOS 10.14", "firefox", "latest" }); | |
| return browsers; | |
| } | |
| @Before | |
| public void setup() throws MalformedURLException | |
| { | |
| URL url = new URL(SAUCE_URL); | |
| DesiredCapabilities capabilities = new DesiredCapabilities(); | |
| capabilities.setCapability("name", "Costco test on " + platform + " " + browser); | |
| capabilities.setCapability("build", "Costco build 3"); | |
| capabilities.setCapability("platform", platform); | |
| capabilities.setCapability("browserName", browser); | |
| capabilities.setCapability("version", "latest"); | |
| capabilities.setCapability("resolution", resolution); | |
| System.out.println(capabilities); | |
| capabilities.asMap().forEach( (key, value) -> System.out.println(key + ": " + value)); | |
| driver = new RemoteWebDriver(url, capabilities); | |
| sessionId = driver.getSessionId().toString(); | |
| api = new SauceREST(SAUCE_USERNAME, SAUCE_ACCESS_KEY); | |
| } | |
| @Test | |
| public void homePageTest() | |
| { | |
| driver.get("https://bd-vqa5.costco.com/"); | |
| String title = driver.getTitle(); | |
| System.out.println(title); | |
| try | |
| { | |
| assertThat(title).isEqualTo("Costco Business Center"); | |
| passed = true; | |
| } | |
| catch (AssertionError e) | |
| { | |
| passed = false; | |
| e.printStackTrace(); | |
| } | |
| } | |
| @After | |
| public void cleanup() | |
| { | |
| driver.quit(); | |
| if (passed == true) | |
| { | |
| api.jobPassed(sessionId); | |
| } | |
| if (passed = false) | |
| { | |
| api.jobFailed(sessionId); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project xmlns="http://maven.apache.org/POM/4.0.0" | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| <modelVersion>4.0.0</modelVersion> | |
| <groupId>com.saucelabs.examples</groupId> | |
| <artifactId>saucelabs-headless-java</artifactId> | |
| <version>1.0-SNAPSHOT</version> | |
| <properties> | |
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
| </properties> | |
| <build> | |
| <plugins> | |
| <plugin> | |
| <groupId>org.apache.maven.plugins</groupId> | |
| <artifactId>maven-compiler-plugin</artifactId> | |
| <version>3.8.1</version> | |
| <configuration> | |
| <source>8</source> | |
| <target>8</target> | |
| </configuration> | |
| </plugin> | |
| <plugin> | |
| <groupId>org.apache.maven.plugins</groupId> | |
| <artifactId>maven-surefire-plugin</artifactId> | |
| <version>2.22.2</version> | |
| <configuration> | |
| <parallel>all</parallel> | |
| <threadCount>10</threadCount> | |
| <redirectTestOutputToFile>false</redirectTestOutputToFile> | |
| </configuration> | |
| </plugin> | |
| </plugins> | |
| </build> | |
| <dependencies> | |
| <dependency> | |
| <groupId>org.seleniumhq.selenium</groupId> | |
| <artifactId>selenium-java</artifactId> | |
| <version>3.141.59</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>com.saucelabs</groupId> | |
| <artifactId>saucerest</artifactId> | |
| <version>1.0.42</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>junit</groupId> | |
| <artifactId>junit</artifactId> | |
| <version>4.12</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>org.assertj</groupId> | |
| <artifactId>assertj-core</artifactId> | |
| <version>3.13.2</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>com.saucelabs</groupId> | |
| <artifactId>sauce_junit</artifactId> | |
| <version>2.1.25</version> | |
| <scope>test</scope> | |
| </dependency> | |
| </dependencies> | |
| </project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment