-
Notifications
You must be signed in to change notification settings - Fork 61
Sauce Driver Prototype #84
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); | ||
} | ||
} |
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){ | ||
this.options = capabilities; | ||
//this.driver = connect(capabilities); | ||
} | ||
|
||
public SauceRemoteGrid(){ | ||
this(new MutableCapabilities()); | ||
} | ||
|
||
public SauceRemoteGrid(String browser){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
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; | ||
} | ||
} | ||
} |
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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
||
MutableCapabilities expectedOptions = new ChromeOptions(); | ||
|
||
assertEquals(sauceGrid.getOptions(), expectedOptions); | ||
} | ||
|
||
@Test | ||
public void setOnlyMobileOS() { | ||
sauceGrid = new SauceRemoteGrid("android"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 aSauceRemoteGrid
andSauceAPI
component. I chose the names arbitrarily (seemed to make sense :) ). This object would be specifically for Webdriver-like functionality.