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

Commit 4c2dfa1

Browse files
add tests that actually return the correct values from the DriverFactory
1 parent d4c4775 commit 4c2dfa1

File tree

4 files changed

+57
-16
lines changed

4 files changed

+57
-16
lines changed

common/src/main/java/com/saucelabs/common/SauceSession.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.saucelabs.common;
22

33
import com.saucelabs.remotedriver.DriverFactory;
4+
import com.saucelabs.remotedriver.RemoteDriverInterface;
5+
import com.saucelabs.remotedriver.SauceOptions;
46
import org.openqa.selenium.WebDriver;
57

68
import java.net.MalformedURLException;
79

810
public class SauceSession {
11+
private DriverFactory driverFactory;
12+
private RemoteDriverInterface remoteDriverManager;
13+
private SauceOptions sauceOptions;
914
private WebDriver webDriver;
1015

1116
public SauceSession(WebDriver driver)
@@ -15,6 +20,23 @@ public SauceSession(WebDriver driver)
1520

1621
public SauceSession()
1722
{
23+
driverFactory = new DriverFactory();
24+
}
25+
26+
public SauceSession(SauceOptions options) {
27+
this.sauceOptions = options;
28+
driverFactory = new DriverFactory();
29+
}
30+
31+
public SauceSession(SauceOptions options, RemoteDriverInterface remoteDriverManager) {
32+
this.sauceOptions = options;
33+
this.remoteDriverManager = remoteDriverManager;
34+
this.driverFactory = new DriverFactory(remoteDriverManager);
35+
}
36+
37+
public SauceSession(RemoteDriverInterface stubRemoteDriver) {
38+
this.remoteDriverManager = stubRemoteDriver;
39+
this.driverFactory = new DriverFactory(remoteDriverManager);
1840
}
1941

2042
public WebDriver getDriver() {
@@ -27,15 +49,15 @@ public String getBrowser() {
2749
}
2850

2951
public String getOs() {
30-
return "Linux";
52+
return driverFactory.capabilities.getPlatform().name();
3153
}
3254

3355
public String getBrowserVersion() {
3456
return "latest";
3557
}
3658

3759
public SauceSession start() throws MalformedURLException {
38-
this.webDriver = new DriverFactory().getInstance();
60+
this.webDriver = driverFactory.getInstance();
3961
return this;
4062
}
4163
}

common/src/main/java/com/saucelabs/remotedriver/SauceOptions.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,25 @@
55
public class SauceOptions extends MutableCapabilities
66
{
77

8-
public SauceOptions(String username, String accessKey)
8+
private String browser;
9+
private String browserVersion;
10+
private String os;
11+
12+
public SauceOptions(String username, String accessKey)
913
{
1014
setCapability("username", username);
1115
setCapability("accessKey", accessKey);
1216

1317
setCapability("name", "mytest");
1418
}
19+
20+
public SauceOptions() {
21+
browser = "Chrome";
22+
os = "windows 10";
23+
browserVersion = "latest";
24+
}
25+
26+
public void setOs(String operatingSystem) {
27+
this.os = operatingSystem;
28+
}
1529
}

common/src/test/java/com/saucelabs/common/unit/SauceSessionTest.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.saucelabs.common.unit;
22

33
import com.saucelabs.common.SauceSession;
4+
import com.saucelabs.remotedriver.RemoteDriverInterface;
45
import com.saucelabs.remotedriver.SauceOptions;
56
import org.hamcrest.text.IsEqualIgnoringCase;
6-
import org.junit.Ignore;
77
import org.junit.Test;
88
import org.openqa.selenium.WebDriver;
99

10+
import java.net.MalformedURLException;
11+
1012
import static org.junit.Assert.*;
1113
import static org.mockito.Mockito.mock;
1214

@@ -33,11 +35,12 @@ public void noSauceOptionsSet_whenCreated_defaultChrome()
3335
assertThat(actualBrowser, IsEqualIgnoringCase.equalToIgnoringCase("Chrome"));
3436
}
3537
@Test
36-
public void noSauceOptionsSet_instantiated_defaultLinux()
37-
{
38-
SauceSession session = new SauceSession();
38+
public void noSauceOptionsSet_instantiated_defaultOsWindows10() throws MalformedURLException {
39+
RemoteDriverInterface stubRemoteDriver = mock(RemoteDriverInterface.class);
40+
SauceSession session = new SauceSession(stubRemoteDriver);
41+
session.start();
3942
String actualOperatingSystem = session.getOs();
40-
assertThat(actualOperatingSystem, IsEqualIgnoringCase.equalToIgnoringCase("Linux"));
43+
assertThat(actualOperatingSystem, IsEqualIgnoringCase.equalToIgnoringCase("win10"));
4144
}
4245
@Test
4346
public void noSauceOptionsSet_instantiated_latestBrowserVersion()
@@ -47,12 +50,14 @@ public void noSauceOptionsSet_instantiated_latestBrowserVersion()
4750
assertThat(actualOperatingSystem, IsEqualIgnoringCase.equalToIgnoringCase("latest"));
4851
}
4952
@Test
50-
@Ignore("need to implement")
51-
public void sauceOptionsSet_withOnlyWindows10_returnsWindows10()
52-
{
53-
SauceOptions options = new SauceOptions("","");
54-
SauceSession session = new SauceSession();
55-
String actualOperatingSystem = session.getBrowserVersion();
56-
assertThat(actualOperatingSystem, IsEqualIgnoringCase.equalToIgnoringCase("latest"));
53+
public void sauceOptionsSet_withOnlyWindows10_returnsWindows10() throws MalformedURLException {
54+
SauceOptions options = new SauceOptions();
55+
options.setOs("Windows 10");
56+
57+
RemoteDriverInterface stubRemoteDriver = mock(RemoteDriverInterface.class);
58+
SauceSession session = new SauceSession(options, stubRemoteDriver);
59+
session.start();
60+
String actualOperatingSystem = session.getOs();
61+
assertThat(actualOperatingSystem, IsEqualIgnoringCase.equalToIgnoringCase("win10"));
5762
}
5863
}

common/src/test/java/com/saucelabs/remotedriver/DriverFactoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void getInstance_default_setsCapabilityToLinux() throws MalformedURLExcep
6464
factory.getInstance();
6565

6666
String actualBrowser = factory.capabilities.getPlatform().name();
67-
assertThat(actualBrowser, IsEqualIgnoringCase.equalToIgnoringCase("windows 10"));
67+
assertThat(actualBrowser, IsEqualIgnoringCase.equalToIgnoringCase("win10"));
6868
}
6969

7070
private DriverFactory getFactoryWithStubRemoteManager() {

0 commit comments

Comments
 (0)