Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Sauce Driver Prototype #84

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions common/src/main/java/com/saucelabs/common/SauceLabs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.saucelabs.common;

public class SauceLabs {

public SauceRemoteGrid grid;
public SauceHelper helper;

public SauceLabs(){
this.grid = new SauceRemoteGrid();
this.helper = new SauceHelper();
}
}
58 changes: 58 additions & 0 deletions common/src/main/java/com/saucelabs/common/SauceRemoteGrid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.saucelabs.common;

import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.MalformedURLException;
import java.net.URL;

public class SauceRemoteGrid {

private static final String SAUCE_ONDEMAND_URL = "https://ondemand.saucelabs.com/wd/hub";

private MutableCapabilities options;
private WebDriver driver;

public SauceRemoteGrid(MutableCapabilities capabilities){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, so is this the new name you picked from SauceLabs or SauceClient?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshgrantsauce @joshmgrant Hey bud, let me know your thoughts on all my comments. I'm not sure how to proceed here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean in your comment. Basically my idea was to break down the SauceLabs "object" into a SauceRemoteGrid and SauceAPI component. I chose the names arbitrarily (seemed to make sense :) ). This object would be specifically for Webdriver-like functionality.

this.options = capabilities;
//this.driver = connect(capabilities);
}

public SauceRemoteGrid(){
this(new MutableCapabilities());
}

public SauceRemoteGrid(String browser){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just for demo purposes? I would love to get away from using strings with Sauce and rather use statically typed objects like enums or classes.
grid = new SauceRemoteGrid(Browser.Chrome, "73", Platform.Windows, DataCenter.US)
What do you think?

this.options = browserNameToOptions(browser);
//this.driver = connect(this.options);
}


public MutableCapabilities getOptions() {
return options;
}

public WebDriver getDriver() {
return driver;
}

private MutableCapabilities browserNameToOptions(String browser) {
if (browser.toLowerCase().equals("chrome")) {
return new ChromeOptions();
}
else {
return new MutableCapabilities();
}
}

private WebDriver connect(MutableCapabilities options) {
try {
return new RemoteWebDriver(new URL(SAUCE_ONDEMAND_URL), options);
} catch (MalformedURLException e) {
System.out.println("Did you change the Sauce URL?");
return null;
}
}
}
63 changes: 63 additions & 0 deletions common/src/test/java/com.saucelabs.common/SauceRemoteGridTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.saucelabs.common;

import org.junit.Test;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

import static org.junit.Assert.assertEquals;

public class SauceRemoteGridTest {

private SauceRemoteGrid sauceGrid;

@Test
public void basicDefault() {
sauceGrid = new SauceRemoteGrid();

MutableCapabilities expectedOptions = new MutableCapabilities();

assertEquals(sauceGrid.getOptions(), expectedOptions);
}

@Test
public void desiredCapabilities(){
DesiredCapabilities capabilities = new DesiredCapabilities();

sauceGrid = new SauceRemoteGrid(capabilities);

MutableCapabilities expectedOptions = new MutableCapabilities();

assertEquals(sauceGrid.getOptions(), expectedOptions);
}

@Test
public void browserOptions(){
MutableCapabilities options = new MutableCapabilities();

sauceGrid = new SauceRemoteGrid(options);

MutableCapabilities expectedOptions = new MutableCapabilities();

assertEquals(sauceGrid.getOptions(), expectedOptions);
}

@Test
public void setOnlyBrowser(){
sauceGrid = new SauceRemoteGrid("chrome");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So would this apply to all browsers? You can just pick one and run a test on some default VM?
I've also considered another approach along this route:
sauceGrid = new SauceRemoteGrid(); //would start a session on a default configuration
Not to replace yours, I like your idea. But maybe an additional override for an even simpler way to get started?


MutableCapabilities expectedOptions = new ChromeOptions();

assertEquals(sauceGrid.getOptions(), expectedOptions);
}

@Test
public void setOnlyMobileOS() {
sauceGrid = new SauceRemoteGrid("android");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like this feature where you can just pick a platform and a test runs? Is that what you're going for?


MutableCapabilities expectedOptions = new MutableCapabilities();
expectedOptions.setCapability("platformName", "Android");

assertEquals(sauceGrid.getOptions(), expectedOptions);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good path. I know that this was just a sample, but I'd love to see a few more use cases of where you're headed. Like Using JSExecutor and using API. But overall, I really like the idea and I think SauceRemoteGrid is a perfect name for the object!

1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
Expand Down