Skip to content

Commit fcb089c

Browse files
committed
[java] fix static analysis complaints
1 parent ea1b089 commit fcb089c

File tree

2 files changed

+71
-23
lines changed

2 files changed

+71
-23
lines changed

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

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@
1414
import java.net.URL;
1515

1616
public class SauceSession {
17+
@Getter protected RemoteWebDriver driver;
1718
@Getter @Setter private DataCenter dataCenter = DataCenter.US_WEST;
1819
@Getter private final SauceOptions sauceOptions;
1920
@Setter private URL sauceUrl;
2021
@Getter private String result;
2122

22-
@Getter protected RemoteWebDriver driver;
23-
2423
public SauceSession() {
2524
this(new SauceOptions());
2625
}
2726

2827
/**
29-
* Ideally the end user calls build() on Configurations instance
30-
* this constructor is being accommodating in case they do not
28+
* Ideally the end user calls build() on Configurations instance.
29+
* This constructor is being accommodating in case they do not.
3130
*
3231
* @param configs the instance of Configuration used to create the Options
3332
*/
@@ -39,11 +38,19 @@ public SauceSession(SauceOptions options) {
3938
sauceOptions = options;
4039
}
4140

41+
/**
42+
* Starts the session on Sauce Labs.
43+
*
44+
* @return the driver instance for using as normal in your tests.
45+
*/
4246
public RemoteWebDriver start() {
4347
this.driver = createRemoteWebDriver(getSauceUrl(), sauceOptions.toCapabilities());
4448
return driver;
4549
}
4650

51+
/**
52+
* @return the full URL for sending to Sauce Labs based on the desired data center.
53+
*/
4754
public URL getSauceUrl() {
4855
try {
4956
if (sauceUrl != null) {
@@ -56,14 +63,26 @@ public URL getSauceUrl() {
5663
}
5764
}
5865

59-
protected RemoteWebDriver createRemoteWebDriver(URL url, Capabilities capabilities) {
60-
return new RemoteWebDriver(url, capabilities);
61-
}
62-
66+
/**
67+
* Analyzes Accessibility for the current page.
68+
* User can work with the results from the Results object or see them
69+
* in the accessibility tab in the Sauce Labs UI.
70+
*
71+
* @return an object with the accessibility analysis
72+
*/
6373
public Results getAccessibilityResults() {
6474
return getAccessibilityResults(true);
6575
}
6676

77+
/**
78+
* Analyzes Accessibility for the current page.
79+
* User can work with the results from the Results object or see them
80+
* in the accessibility tab in the Sauce Labs UI.
81+
*
82+
* @param frames whether the page being evaluated needs to dig into frames.
83+
* passing false here will slightly improve performance.
84+
* @return an object with the accessibility analysis
85+
*/
6786
public Results getAccessibilityResults(boolean frames) {
6887
AxeBuilder axeBuilder = new AxeBuilder();
6988
if (!frames) {
@@ -72,22 +91,55 @@ public Results getAccessibilityResults(boolean frames) {
7291
return getAccessibilityResults(axeBuilder);
7392
}
7493

94+
/**
95+
* Analyzes Accessibility for the current page.
96+
* User can work with the results from the Results object or see them
97+
* in the accessibility tab in the Sauce Labs UI.
98+
*
99+
* @param builder for advanced accessibility information provide your own
100+
* instance of an AxeBuilder.
101+
* @return an object with the accessibility analysis
102+
*/
75103
public Results getAccessibilityResults(AxeBuilder builder) {
76104
return builder.analyze(driver);
77105
}
78106

107+
/**
108+
* Ends the session on Sauce Labs and quits the driver.
109+
* It requires reporting whether the test has passed or failed.
110+
*
111+
* @param passed true if the test has passed, otherwise false
112+
*/
79113
public void stop(Boolean passed) {
80114
String result = passed ? "passed" : "failed";
81115
stop(result);
82116
}
83117

118+
/**
119+
* Ends the session on Sauce Labs and quits the driver.
120+
* It requires reporting whether the test has passed or failed.
121+
*
122+
* @param result only allowed "passed" or "failed"
123+
*/
84124
public void stop(String result) {
85125
if (this.driver != null) {
86126
updateResult(result);
87127
quit();
88128
}
89129
}
90130

131+
/**
132+
* Not intended for subclassing.
133+
* Package-private for testing.
134+
*
135+
* @param url to send session commands to
136+
* @param capabilities configuration for session
137+
* @return driver instance
138+
*/
139+
RemoteWebDriver createRemoteWebDriver(URL url, Capabilities capabilities) {
140+
return new RemoteWebDriver(url, capabilities);
141+
}
142+
91143
private void updateResult(String result) {
92144
this.result = result;
93145
getDriver().executeScript("sauce:job-result=" + result);

java/main/src/test/java/com/saucelabs/saucebindings/integration/DesktopBrowserTest.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
import com.saucelabs.saucebindings.SauceSession;
66
import com.saucelabs.saucebindings.options.SauceOptions;
77
import org.junit.After;
8+
import org.junit.Assert;
89
import org.junit.Test;
910
import org.openqa.selenium.remote.RemoteWebDriver;
1011

11-
import static org.junit.Assert.assertEquals;
12-
import static org.junit.Assert.assertNotNull;
13-
import static org.junit.Assert.assertNull;
14-
import static org.junit.Assert.assertTrue;
15-
1612
public class DesktopBrowserTest {
1713
private SauceSession session = new SauceSession();
1814
private RemoteWebDriver webDriver;
@@ -27,8 +23,8 @@ public void cleanUp() {
2723
@Test
2824
public void defaultsToUSWest() {
2925
webDriver = session.start();
30-
assertNotNull(webDriver);
31-
assertTrue(session.getSauceUrl().toString().contains("us-west-"));
26+
Assert.assertNotNull(webDriver);
27+
Assert.assertTrue(session.getSauceUrl().toString().contains("us-west-"));
3228
}
3329

3430
@Test
@@ -39,26 +35,26 @@ public void runsUSEast() {
3935
session.setDataCenter(DataCenter.US_EAST);
4036
webDriver = session.start();
4137

42-
assertNotNull(webDriver);
43-
assertTrue(session.getSauceUrl().toString().contains("us-east-1"));
38+
Assert.assertNotNull(webDriver);
39+
Assert.assertTrue(session.getSauceUrl().toString().contains("us-east-1"));
4440
}
4541

4642
@Test
4743
public void runsAPACSoutheast() {
4844
session.setDataCenter(DataCenter.APAC_SOUTHEAST);
4945
webDriver = session.start();
5046

51-
assertNotNull(webDriver);
52-
assertTrue(session.getSauceUrl().toString().contains("apac-southeast"));
47+
Assert.assertNotNull(webDriver);
48+
Assert.assertTrue(session.getSauceUrl().toString().contains("apac-southeast"));
5349
}
5450

5551
@Test
5652
public void runsEUCentral() {
5753
session.setDataCenter(DataCenter.EU_CENTRAL);
5854
webDriver = session.start();
5955

60-
assertNotNull(webDriver);
61-
assertTrue(session.getSauceUrl().toString().contains("eu-central-1"));
56+
Assert.assertNotNull(webDriver);
57+
Assert.assertTrue(session.getSauceUrl().toString().contains("eu-central-1"));
6258
}
6359

6460
@Test
@@ -68,14 +64,14 @@ public void storesResultOfFirstStop() {
6864
session.stop(true);
6965
session.stop(false);
7066

71-
assertEquals("passed", session.getResult());
67+
Assert.assertEquals("passed", session.getResult());
7268
}
7369

7470
@Test
7571
public void nullsDriver() {
7672
webDriver = session.start();
7773
session.stop(true);
7874

79-
assertNull(session.getDriver());
75+
Assert.assertNull(session.getDriver());
8076
}
8177
}

0 commit comments

Comments
 (0)