17
17
18
18
package org .openqa .selenium .safari ;
19
19
20
+ import static org .openqa .selenium .remote .CapabilityType .BROWSER_NAME ;
21
+
20
22
import org .openqa .selenium .Capabilities ;
21
- import org .openqa .selenium .MutableCapabilities ;
22
23
import org .openqa .selenium .WebDriverException ;
23
24
import org .openqa .selenium .internal .Require ;
24
25
import org .openqa .selenium .remote .AbstractDriverOptions ;
26
+ import org .openqa .selenium .remote .BrowserType ;
25
27
26
28
import java .util .Collections ;
27
- import java .util .Map ;
28
29
import java .util .Set ;
29
30
30
- import static org .openqa .selenium .remote .CapabilityType .BROWSER_NAME ;
31
-
32
31
/**
33
32
* Class to manage options specific to {@link SafariDriver}.
34
33
*
@@ -50,22 +49,9 @@ public class SafariOptions extends AbstractDriverOptions<SafariOptions> {
50
49
51
50
static final String SAFARI_TECH_PREVIEW = "Safari Technology Preview" ;
52
51
53
- /**
54
- * Key used to store SafariOptions in a {@link Capabilities} object.
55
- * @deprecated No replacement. Use the methods on this class
56
- */
57
- @ Deprecated
58
- public static final String CAPABILITY = "safari.options" ;
59
-
60
- private interface Option {
61
- // Defined by Apple
62
- String AUTOMATIC_INSPECTION = "safari:automaticInspection" ;
63
- String AUTOMATIC_PROFILING = "safari:automaticProfiling" ;
64
- }
65
-
66
52
public SafariOptions () {
67
53
setUseTechnologyPreview (false );
68
- setCapability (BROWSER_NAME , "safari" );
54
+ setCapability (BROWSER_NAME , BrowserType . SAFARI );
69
55
}
70
56
71
57
public SafariOptions (Capabilities source ) {
@@ -74,6 +60,21 @@ public SafariOptions(Capabilities source) {
74
60
source .getCapabilityNames ().forEach (name -> setCapability (name , source .getCapability (name )));
75
61
}
76
62
63
+ /**
64
+ * Construct a {@link SafariOptions} instance from given capabilities.
65
+ *
66
+ * @param capabilities Desired capabilities from which the options are derived.
67
+ * @return SafariOptions
68
+ * @throws WebDriverException If an error occurred during the reconstruction of the options
69
+ */
70
+ public static SafariOptions fromCapabilities (Capabilities capabilities )
71
+ throws WebDriverException {
72
+ if (capabilities instanceof SafariOptions ) {
73
+ return (SafariOptions ) capabilities ;
74
+ }
75
+ return new SafariOptions (capabilities );
76
+ }
77
+
77
78
@ Override
78
79
public SafariOptions merge (Capabilities extraCapabilities ) {
79
80
Require .nonNull ("Capabilities to merge" , extraCapabilities );
@@ -87,27 +88,8 @@ public SafariOptions merge(Capabilities extraCapabilities) {
87
88
return newInstance ;
88
89
}
89
90
90
- /**
91
- * Construct a {@link SafariOptions} instance from given capabilities.
92
- * When the {@link #CAPABILITY} capability is set, all other capabilities will be ignored!
93
- *
94
- * @param capabilities Desired capabilities from which the options are derived.
95
- * @return SafariOptions
96
- * @throws WebDriverException If an error occurred during the reconstruction of the options
97
- */
98
- public static SafariOptions fromCapabilities (Capabilities capabilities )
99
- throws WebDriverException {
100
- if (capabilities instanceof SafariOptions ) {
101
- return (SafariOptions ) capabilities ;
102
- }
103
- Object cap = capabilities .getCapability (SafariOptions .CAPABILITY );
104
- if (cap instanceof SafariOptions ) {
105
- return (SafariOptions ) cap ;
106
- } else if (cap instanceof Map ) {
107
- return new SafariOptions (new MutableCapabilities (((Map <String , ?>) cap )));
108
- } else {
109
- return new SafariOptions (capabilities );
110
- }
91
+ public boolean getAutomaticInspection () {
92
+ return Boolean .TRUE .equals (getCapability (Option .AUTOMATIC_INSPECTION ));
111
93
}
112
94
113
95
// Setters
@@ -124,45 +106,41 @@ public SafariOptions setAutomaticInspection(boolean automaticInspection) {
124
106
return this ;
125
107
}
126
108
109
+ public boolean getAutomaticProfiling () {
110
+ return Boolean .TRUE .equals (is (Option .AUTOMATIC_PROFILING ));
111
+ }
112
+
127
113
/**
128
114
* Instruct the SafariDriver to enable the Automatic profiling if true, otherwise disable
129
115
* the automatic profiling. Defaults to disabling the automatic profiling.
130
116
*
131
117
* @param automaticProfiling If true, the SafariDriver will enable the Automation Profiling,
132
- * otherwise will disable.
118
+ * otherwise will disable.
133
119
*/
134
120
public SafariOptions setAutomaticProfiling (boolean automaticProfiling ) {
135
121
setCapability (Option .AUTOMATIC_PROFILING , automaticProfiling );
136
122
return this ;
137
123
}
138
124
125
+ // Getters
126
+
127
+ public boolean getUseTechnologyPreview () {
128
+ return SAFARI_TECH_PREVIEW .equals (getBrowserName ());
129
+ }
130
+
139
131
/**
140
132
* Instruct the SafariDriver to use the Safari Technology Preview if true, otherwise use the
141
133
* release version of Safari. Defaults to using the release version of Safari.
142
134
*
143
135
* @param useTechnologyPreview If true, the SafariDriver will use the Safari Technology Preview,
144
- * otherwise will use the release version of Safari.
136
+ * otherwise will use the release version of Safari.
145
137
*/
146
138
public SafariOptions setUseTechnologyPreview (boolean useTechnologyPreview ) {
147
139
// Use an object here, rather than a boolean to avoid a stack overflow
148
140
super .setCapability (BROWSER_NAME , useTechnologyPreview ? SAFARI_TECH_PREVIEW : "safari" );
149
141
return this ;
150
142
}
151
143
152
- // Getters
153
-
154
- public boolean getAutomaticInspection () {
155
- return Boolean .TRUE .equals (getCapability (Option .AUTOMATIC_INSPECTION ));
156
- }
157
-
158
- public boolean getAutomaticProfiling () {
159
- return Boolean .TRUE .equals (is (Option .AUTOMATIC_PROFILING ));
160
- }
161
-
162
- public boolean getUseTechnologyPreview () {
163
- return SAFARI_TECH_PREVIEW .equals (getBrowserName ());
164
- }
165
-
166
144
@ Override
167
145
protected Set <String > getExtraCapabilityNames () {
168
146
return Collections .emptySet ();
@@ -172,4 +150,11 @@ protected Set<String> getExtraCapabilityNames() {
172
150
protected Object getExtraCapability (String capabilityName ) {
173
151
return null ;
174
152
}
153
+
154
+ private interface Option {
155
+
156
+ // Defined by Apple
157
+ String AUTOMATIC_INSPECTION = "safari:automaticInspection" ;
158
+ String AUTOMATIC_PROFILING = "safari:automaticProfiling" ;
159
+ }
175
160
}
0 commit comments