Skip to content

Commit 2c2141e

Browse files
committed
feat: create android and ios driver option classes
1 parent cc4003f commit 2c2141e

4 files changed

Lines changed: 288 additions & 1 deletion

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.android;
18+
19+
import io.appium.java_client.remote.MobileOptions;
20+
import io.appium.java_client.remote.MobilePlatform;
21+
import org.openqa.selenium.Capabilities;
22+
23+
public class AndroidOptions extends MobileOptions<AndroidOptions> {
24+
public AndroidOptions() {
25+
setPlatformName(MobilePlatform.ANDROID);
26+
}
27+
28+
public AndroidOptions(Capabilities source) {
29+
this();
30+
merge(source);
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.ios;
18+
19+
import io.appium.java_client.remote.MobileOptions;
20+
import io.appium.java_client.remote.MobilePlatform;
21+
import org.openqa.selenium.Capabilities;
22+
23+
public class IOSOptions extends MobileOptions<IOSOptions> {
24+
public IOSOptions() {
25+
setPlatformName(MobilePlatform.IOS);
26+
}
27+
28+
public IOSOptions(Capabilities source) {
29+
this();
30+
merge(source);
31+
}
32+
}

src/main/java/io/appium/java_client/remote/MobileCapabilityType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public interface MobileCapabilityType extends CapabilityType {
120120
String EVENT_TIMINGS = "eventTimings";
121121

122122
/**
123-
* This is the flag which forces server to switch to the mobile WSONWP.
123+
* This is the flag which forces server to switch to the mobile JSONWP.
124124
* If {@code false} then it is switched to W3C mode.
125125
*/
126126
String FORCE_MJSONWP = "forceMjsonwp";
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.appium.java_client.remote;
18+
19+
import org.openqa.selenium.Capabilities;
20+
import org.openqa.selenium.MutableCapabilities;
21+
import org.openqa.selenium.ScreenOrientation;
22+
import org.openqa.selenium.remote.CapabilityType;
23+
24+
import java.net.URL;
25+
import java.time.Duration;
26+
27+
public class MobileOptions<T extends MobileOptions<T>> extends MutableCapabilities {
28+
29+
public MobileOptions() {
30+
}
31+
32+
public MobileOptions(Capabilities source) {
33+
merge(source);
34+
}
35+
36+
public T setPlatformName(String platform) {
37+
return amend(CapabilityType.PLATFORM_NAME, platform);
38+
}
39+
40+
public String getPlatformName() {
41+
return (String) getCapability(CapabilityType.PLATFORM_NAME);
42+
}
43+
44+
public T setApp(String path) {
45+
return amend(MobileCapabilityType.APP, path);
46+
}
47+
48+
public T setApp(URL url) {
49+
return setApp(url.toString());
50+
}
51+
52+
public String getApp() {
53+
return (String) getCapability(MobileCapabilityType.APP);
54+
}
55+
56+
public T setAutomationName(String name) {
57+
return amend(MobileCapabilityType.AUTOMATION_NAME, name);
58+
}
59+
60+
public String getAutomationName() {
61+
return (String) getCapability(MobileCapabilityType.AUTOMATION_NAME);
62+
}
63+
64+
public T setAutoWebview() {
65+
return setAutoWebview(true);
66+
}
67+
68+
public T setAutoWebview(boolean bool) {
69+
return amend(MobileCapabilityType.AUTO_WEBVIEW, bool);
70+
}
71+
72+
public boolean doesAutoWebview() {
73+
return (boolean) getCapability(MobileCapabilityType.AUTO_WEBVIEW);
74+
}
75+
76+
public T setClearSystemFiles() {
77+
return setClearSystemFiles(true);
78+
}
79+
80+
public T setClearSystemFiles(boolean bool) {
81+
return amend(MobileCapabilityType.CLEAR_SYSTEM_FILES, bool);
82+
}
83+
84+
public boolean doesClearSystemFiles() {
85+
return (boolean) getCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES);
86+
}
87+
88+
public T setDeviceName(String deviceName) {
89+
return amend(MobileCapabilityType.DEVICE_NAME, deviceName);
90+
}
91+
92+
public String getDeviceName() {
93+
return (String) getCapability(MobileCapabilityType.DEVICE_NAME);
94+
}
95+
96+
public T setEnablePerformanceLogging() {
97+
return setEnablePerformanceLogging(true);
98+
}
99+
100+
public T setEnablePerformanceLogging(boolean bool) {
101+
return amend(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING, bool);
102+
}
103+
104+
public boolean isEnablePerformanceLogging() {
105+
return (boolean) getCapability(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING);
106+
}
107+
108+
public T setEventTimings() {
109+
return setEventTimings(true);
110+
}
111+
112+
public T setEventTimings(boolean bool) {
113+
return amend(MobileCapabilityType.EVENT_TIMINGS, bool);
114+
}
115+
116+
public boolean doesEventTimings() {
117+
return (boolean) getCapability(MobileCapabilityType.EVENT_TIMINGS);
118+
}
119+
120+
public T setFullReset() {
121+
return setFullReset(true);
122+
}
123+
124+
public T setFullReset(boolean bool) {
125+
return amend(MobileCapabilityType.FULL_RESET, bool);
126+
}
127+
128+
public boolean doesFullReset() {
129+
return (boolean) getCapability(MobileCapabilityType.FULL_RESET);
130+
}
131+
132+
public T setLanguage(String language) {
133+
return amend(MobileCapabilityType.LANGUAGE, language);
134+
}
135+
136+
public String getLanguage() {
137+
return (String) getCapability(MobileCapabilityType.LANGUAGE);
138+
}
139+
140+
public T setLocale(String locale) {
141+
return amend(MobileCapabilityType.LOCALE, locale);
142+
}
143+
144+
public String getLocale() {
145+
return (String) getCapability(MobileCapabilityType.LOCALE);
146+
}
147+
148+
public T setNewCommandTimeout(Duration duration) {
149+
return amend(MobileCapabilityType.NEW_COMMAND_TIMEOUT, duration.getSeconds());
150+
}
151+
152+
public Duration getNewCommandTimeout() {
153+
Object duration = getCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT);
154+
return Duration.ofSeconds(Long.parseLong("" + duration));
155+
}
156+
157+
public T setNoReset() {
158+
return setNoReset(true);
159+
}
160+
161+
public T setNoReset(boolean bool) {
162+
return amend(MobileCapabilityType.NO_RESET, bool);
163+
}
164+
165+
public boolean doesNoReset() {
166+
return (boolean) getCapability(MobileCapabilityType.NO_RESET);
167+
}
168+
169+
public T setOrientation(ScreenOrientation orientation) {
170+
return amend(MobileCapabilityType.ORIENTATION, orientation);
171+
}
172+
173+
public ScreenOrientation getOrientation() {
174+
return (ScreenOrientation) getCapability(MobileCapabilityType.ORIENTATION);
175+
}
176+
177+
public T setOtherApps(String apps) {
178+
return amend(MobileCapabilityType.OTHER_APPS, apps);
179+
}
180+
181+
public String getOtherApps() {
182+
return (String) getCapability(MobileCapabilityType.OTHER_APPS);
183+
}
184+
185+
public T setPlatformVersion(String version) {
186+
return amend(MobileCapabilityType.PLATFORM_VERSION, version);
187+
}
188+
189+
public String getPlatformVersion() {
190+
return (String) getCapability(MobileCapabilityType.PLATFORM_VERSION);
191+
}
192+
193+
public T setPrintPageSourceOnFindFailure() {
194+
return setPrintPageSourceOnFindFailure(true);
195+
}
196+
197+
public T setPrintPageSourceOnFindFailure(boolean bool) {
198+
return amend(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE, bool);
199+
}
200+
201+
public boolean doesPrintPageSourceOnFindFailure() {
202+
return (boolean) getCapability(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE);
203+
}
204+
205+
public T setUdid(String id) {
206+
return amend(MobileCapabilityType.UDID, id);
207+
}
208+
209+
public String getUdid() {
210+
return (String) getCapability(MobileCapabilityType.UDID);
211+
}
212+
213+
@Override
214+
public T merge(Capabilities extraCapabilities) {
215+
super.merge(extraCapabilities);
216+
return (T) this;
217+
}
218+
219+
protected T amend(String optionName, Object value) {
220+
setCapability(optionName, value);
221+
return (T) this;
222+
}
223+
}

0 commit comments

Comments
 (0)