6
6
import com .saucelabs .saucebindings .options .SauceOptions ;
7
7
import lombok .Getter ;
8
8
import lombok .Setter ;
9
+ import org .openqa .selenium .Capabilities ;
9
10
import org .openqa .selenium .InvalidArgumentException ;
10
- import org .openqa .selenium .MutableCapabilities ;
11
11
import org .openqa .selenium .remote .RemoteWebDriver ;
12
12
13
13
import java .net .MalformedURLException ;
@@ -19,7 +19,7 @@ public class SauceSession {
19
19
@ Setter private URL sauceUrl ;
20
20
@ Getter private String result ;
21
21
22
- @ Getter private RemoteWebDriver driver ;
22
+ @ Getter protected RemoteWebDriver driver ;
23
23
24
24
public SauceSession () {
25
25
this (new SauceOptions ());
@@ -40,23 +40,23 @@ public SauceSession(SauceOptions options) {
40
40
}
41
41
42
42
public RemoteWebDriver start () {
43
- driver = createRemoteWebDriver (getSauceUrl (), sauceOptions .toCapabilities ());
43
+ this . driver = createRemoteWebDriver (getSauceUrl (), sauceOptions .toCapabilities ());
44
44
return driver ;
45
45
}
46
46
47
47
public URL getSauceUrl () {
48
- if (sauceUrl != null ) {
49
- return sauceUrl ;
50
- } else {
51
- try {
52
- return new URL (dataCenter .getValue ());
53
- } catch (MalformedURLException e ) {
54
- throw new InvalidArgumentException ("Invalid URL" );
48
+ try {
49
+ if (sauceUrl != null ) {
50
+ return sauceUrl ;
51
+ } else {
52
+ return new URL (getDataCenter ().getValue ());
55
53
}
54
+ } catch (MalformedURLException e ) {
55
+ throw new InvalidArgumentException ("Invalid URL" , e );
56
56
}
57
57
}
58
58
59
- protected RemoteWebDriver createRemoteWebDriver (URL url , MutableCapabilities capabilities ) {
59
+ protected RemoteWebDriver createRemoteWebDriver (URL url , Capabilities capabilities ) {
60
60
return new RemoteWebDriver (url , capabilities );
61
61
}
62
62
@@ -82,27 +82,29 @@ public void stop(Boolean passed) {
82
82
}
83
83
84
84
public void stop (String result ) {
85
- updateResult (result );
86
- stop ();
85
+ if (this .driver != null ) {
86
+ updateResult (result );
87
+ quit ();
88
+ }
87
89
}
88
90
89
91
private void updateResult (String result ) {
90
92
this .result = result ;
91
93
getDriver ().executeScript ("sauce:job-result=" + result );
94
+
92
95
// Add output for the Sauce OnDemand Jenkins plugin
93
96
// The first print statement will automatically populate links on Jenkins to Sauce
94
97
// The second print statement will output the job link to logging/console
95
- if (this .driver != null ) {
96
- String sauceReporter = String .format ("SauceOnDemandSessionID=%s job-name=%s" , this .driver .getSessionId (), this .sauceOptions .sauce ().getName ());
97
- String sauceTestLink = String .format ("Test Job Link: https://app.saucelabs.com/tests/%s" , this .driver .getSessionId ());
98
- System .out .print (sauceReporter + "\n " + sauceTestLink + "\n " );
99
- }
98
+ String sauceReporter = String .format ("SauceOnDemandSessionID=%s job-name=%s" ,
99
+ this .driver .getSessionId (),
100
+ this .sauceOptions .sauce ().getName ());
101
+ String sauceTestLink = String .format ("Test Job Link: https://app.saucelabs.com/tests/%s" ,
102
+ this .driver .getSessionId ());
103
+ System .out .print (sauceReporter + "\n " + sauceTestLink + "\n " );
100
104
}
101
105
102
- private void stop () {
103
- if (driver !=null ) {
104
- driver .quit ();
105
- driver = null ;
106
- }
106
+ private void quit () {
107
+ driver .quit ();
108
+ driver = null ;
107
109
}
108
110
}
0 commit comments