1414import org .openqa .selenium .edge .EdgeOptions ;
1515import org .openqa .selenium .firefox .FirefoxOptions ;
1616import org .openqa .selenium .ie .InternetExplorerOptions ;
17+ import org .openqa .selenium .remote .DesiredCapabilities ;
1718import org .openqa .selenium .remote .RemoteWebDriver ;
1819import org .openqa .selenium .safari .SafariOptions ;
1920
@@ -29,7 +30,10 @@ public class SauceSession {
2930 @ Getter private String result ;
3031
3132 private static SauceOptions castMutableCapabilities (MutableCapabilities capabilities ) {
32- if (ChromeOptions .class .equals (capabilities .getClass ())) {
33+ if (DesiredCapabilities .class .equals (capabilities .getClass ())) {
34+ String msg = "DesiredCapabilities class does not create valid w3c compliant capabilities and are deprecated; Please update" ;
35+ throw new InvalidSauceOptionsArgumentException (msg );
36+ } else if (ChromeOptions .class .equals (capabilities .getClass ())) {
3337 return SauceOptions .chrome ((ChromeOptions ) capabilities ).build ();
3438 } else if (EdgeOptions .class .equals (capabilities .getClass ())) {
3539 return SauceOptions .edge ((EdgeOptions ) capabilities ).build ();
@@ -39,8 +43,11 @@ private static SauceOptions castMutableCapabilities(MutableCapabilities capabili
3943 return SauceOptions .safari ((SafariOptions ) capabilities ).build ();
4044 } else if (InternetExplorerOptions .class .equals (capabilities .getClass ())) {
4145 return SauceOptions .ie ((InternetExplorerOptions ) capabilities ).build ();
46+ } else if (MutableCapabilities .class .equals (capabilities .getClass ())) {
47+ return new SauceOptions (capabilities .asMap ());
48+ } else {
49+ throw new InvalidSauceOptionsArgumentException ("Browser Options class not recognized: " + capabilities .getClass ());
4250 }
43- throw new InvalidSauceOptionsArgumentException ("invalid browser option class: " + capabilities .getClass ());
4451 }
4552
4653 public SauceSession () {
@@ -134,7 +141,7 @@ public Results getAccessibilityResults(boolean frames) {
134141 * @return an object with the accessibility analysis
135142 */
136143 public Results getAccessibilityResults (AxeBuilder builder ) {
137- validateSessionStarted ("getAccessibilityResults() " );
144+ validateSessionStarted ("getAccessibilityResults" );
138145 return builder .analyze (driver );
139146 }
140147
@@ -160,7 +167,7 @@ public void stop(Boolean passed) {
160167 * Providing Context for Selenium Commands</a>
161168 */
162169 public void annotate (String comment ) {
163- validateSessionStarted ("annotate() " );
170+ validateSessionStarted ("annotate" );
164171 driver .executeScript ("sauce:context=" + comment );
165172 }
166173
@@ -172,7 +179,7 @@ public void annotate(String comment) {
172179 * Test Annotation Methods</a>
173180 */
174181 public void pause () {
175- validateSessionStarted ("pause() " );
182+ validateSessionStarted ("pause" );
176183 String sauceTestLink = String .format ("https://app.saucelabs.com/tests/%s" ,
177184 this .driver .getSessionId ());
178185 driver .executeScript ("sauce: break" );
@@ -191,7 +198,7 @@ public void pause() {
191198 * Test Annotation Methods</a>
192199 */
193200 public void disableLogging () {
194- validateSessionStarted ("disableLogging() " );
201+ validateSessionStarted ("disableLogging" );
195202 driver .executeScript ("sauce: disable log" );
196203 }
197204
@@ -203,7 +210,7 @@ public void disableLogging() {
203210 * Test Annotation Methods</a>
204211 */
205212 public void enableLogging () {
206- validateSessionStarted ("enableLogging() " );
213+ validateSessionStarted ("enableLogging" );
207214 driver .executeScript ("sauce: enable log" );
208215 }
209216
@@ -215,7 +222,7 @@ public void enableLogging() {
215222 * Test Annotation Methods</a>
216223 */
217224 public void stopNetwork () {
218- validateSessionStarted ("stopNetwork() " );
225+ validateSessionStarted ("stopNetwork" );
219226 validateMac ("Can only stop network for a Mac Platform;" );
220227
221228 driver .executeScript ("sauce: stop network" );
@@ -229,7 +236,7 @@ public void stopNetwork() {
229236 * Test Annotation Methods</a>
230237 */
231238 public void startNetwork () {
232- validateSessionStarted ("startNetwork() " );
239+ validateSessionStarted ("startNetwork" );
233240 validateMac ("Can only start network for a Mac Platform;" );
234241
235242 driver .executeScript ("sauce: start network" );
@@ -245,7 +252,7 @@ public void startNetwork() {
245252 * @see BaseConfigurations#setName(String)
246253 */
247254 public void changeTestName (String name ) {
248- validateSessionStarted ("changeName() " );
255+ validateSessionStarted ("changeName" );
249256 driver .executeScript ("sauce:job-name=" + name );
250257 }
251258
@@ -259,7 +266,7 @@ public void changeTestName(String name) {
259266 * @see BaseConfigurations#setTags(List)
260267 */
261268 public void addTags (List <String > tags ) {
262- validateSessionStarted ("setTags() " );
269+ validateSessionStarted ("setTags" );
263270 String tagString = String .join ("," , tags );
264271 driver .executeScript ("sauce:job-tags=" + tagString );
265272 }
@@ -301,7 +308,7 @@ private void updateResult(String result) {
301308
302309 private void validateSessionStarted (String method ) {
303310 if (driver == null ) {
304- throw new SauceSessionNotStartedException (method );
311+ throw new SauceSessionNotStartedException (method + "()" );
305312 }
306313 }
307314
0 commit comments