14
14
import java .net .URL ;
15
15
16
16
public class SauceSession {
17
+ @ Getter protected RemoteWebDriver driver ;
17
18
@ Getter @ Setter private DataCenter dataCenter = DataCenter .US_WEST ;
18
19
@ Getter private final SauceOptions sauceOptions ;
19
20
@ Setter private URL sauceUrl ;
20
21
@ Getter private String result ;
21
22
22
- @ Getter protected RemoteWebDriver driver ;
23
-
24
23
public SauceSession () {
25
24
this (new SauceOptions ());
26
25
}
27
26
28
27
/**
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.
31
30
*
32
31
* @param configs the instance of Configuration used to create the Options
33
32
*/
@@ -39,11 +38,19 @@ public SauceSession(SauceOptions options) {
39
38
sauceOptions = options ;
40
39
}
41
40
41
+ /**
42
+ * Starts the session on Sauce Labs.
43
+ *
44
+ * @return the driver instance for using as normal in your tests.
45
+ */
42
46
public RemoteWebDriver start () {
43
47
this .driver = createRemoteWebDriver (getSauceUrl (), sauceOptions .toCapabilities ());
44
48
return driver ;
45
49
}
46
50
51
+ /**
52
+ * @return the full URL for sending to Sauce Labs based on the desired data center.
53
+ */
47
54
public URL getSauceUrl () {
48
55
try {
49
56
if (sauceUrl != null ) {
@@ -56,14 +63,26 @@ public URL getSauceUrl() {
56
63
}
57
64
}
58
65
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
+ */
63
73
public Results getAccessibilityResults () {
64
74
return getAccessibilityResults (true );
65
75
}
66
76
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
+ */
67
86
public Results getAccessibilityResults (boolean frames ) {
68
87
AxeBuilder axeBuilder = new AxeBuilder ();
69
88
if (!frames ) {
@@ -72,33 +91,64 @@ public Results getAccessibilityResults(boolean frames) {
72
91
return getAccessibilityResults (axeBuilder );
73
92
}
74
93
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
+ */
75
103
public Results getAccessibilityResults (AxeBuilder builder ) {
76
104
return builder .analyze (driver );
77
105
}
78
106
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
+ */
79
113
public void stop (Boolean passed ) {
80
- String result = passed ? "passed" : "failed" ;
81
- stop (result );
82
- }
83
-
84
- public void stop (String result ) {
85
114
if (this .driver != null ) {
86
- updateResult (result );
115
+ String update = passed ? "passed" : "failed" ;
116
+ updateResult (update );
87
117
quit ();
88
118
}
89
119
}
90
120
121
+ /**
122
+ * @deprecated Do not use magic strings, pass in boolean for whether test has passed.
123
+ */
124
+ @ Deprecated
125
+ public void stop (String result ) {
126
+ stop (result .equals ("passed" ));
127
+ }
128
+
129
+ /**
130
+ * Not intended for subclassing.
131
+ * Package-private for testing.
132
+ *
133
+ * @param url to send session commands to
134
+ * @param capabilities configuration for session
135
+ * @return driver instance
136
+ */
137
+ RemoteWebDriver createRemoteWebDriver (URL url , Capabilities capabilities ) {
138
+ return new RemoteWebDriver (url , capabilities );
139
+ }
140
+
91
141
private void updateResult (String result ) {
92
142
this .result = result ;
93
143
getDriver ().executeScript ("sauce:job-result=" + result );
94
144
95
145
// Add output for the Sauce OnDemand Jenkins plugin
96
146
// The first print statement will automatically populate links on Jenkins to Sauce
97
147
// The second print statement will output the job link to logging/console
98
- String sauceReporter = String .format ("SauceOnDemandSessionID=%s job-name=%s" ,
148
+ final String sauceReporter = String .format ("SauceOnDemandSessionID=%s job-name=%s" ,
99
149
this .driver .getSessionId (),
100
150
this .sauceOptions .sauce ().getName ());
101
- String sauceTestLink = String .format ("Test Job Link: https://app.saucelabs.com/tests/%s" ,
151
+ final String sauceTestLink = String .format ("Test Job Link: https://app.saucelabs.com/tests/%s" ,
102
152
this .driver .getSessionId ());
103
153
System .out .print (sauceReporter + "\n " + sauceTestLink + "\n " );
104
154
}
0 commit comments