|
| 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 | + |
| 26 | +public abstract class MobileOptions<T extends MobileOptions<T>> extends MutableCapabilities { |
| 27 | + |
| 28 | + public String getPlatformName() { |
| 29 | + return (String) getCapability(CapabilityType.PLATFORM_NAME); |
| 30 | + } |
| 31 | + |
| 32 | + public T setApp(String url) { |
| 33 | + return amend(MobileCapabilityType.APP, url); |
| 34 | + } |
| 35 | + |
| 36 | + public T setApp(URL url) { |
| 37 | + return setApp(url.toString()); |
| 38 | + } |
| 39 | + |
| 40 | + public String getApp() { |
| 41 | + return (String) getCapability(MobileCapabilityType.APP); |
| 42 | + } |
| 43 | + |
| 44 | + public T setAutomationName(String name) { |
| 45 | + return amend(MobileCapabilityType.AUTOMATION_NAME, name); |
| 46 | + } |
| 47 | + |
| 48 | + public String getAutomationName() { |
| 49 | + return (String) getCapability(MobileCapabilityType.AUTOMATION_NAME); |
| 50 | + } |
| 51 | + |
| 52 | + public T setAutoWebview() { |
| 53 | + return setAutoWebview(true); |
| 54 | + } |
| 55 | + |
| 56 | + public T setAutoWebview(boolean bool) { |
| 57 | + return amend(MobileCapabilityType.AUTO_WEBVIEW, bool); |
| 58 | + } |
| 59 | + |
| 60 | + public boolean isAutoWebview() { |
| 61 | + return (boolean) getCapability(MobileCapabilityType.AUTO_WEBVIEW); |
| 62 | + } |
| 63 | + |
| 64 | + public T setClearSystemFiles() { |
| 65 | + return setClearSystemFiles(true); |
| 66 | + } |
| 67 | + |
| 68 | + public T setClearSystemFiles(boolean bool) { |
| 69 | + return amend(MobileCapabilityType.CLEAR_SYSTEM_FILES, bool); |
| 70 | + } |
| 71 | + |
| 72 | + public boolean isClearSystemFiles() { |
| 73 | + return (boolean) getCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES); |
| 74 | + } |
| 75 | + |
| 76 | + public T setDeviceName(String deviceName) { |
| 77 | + return amend(MobileCapabilityType.DEVICE_NAME, deviceName); |
| 78 | + } |
| 79 | + |
| 80 | + public String getDeviceName() { |
| 81 | + return (String) getCapability(MobileCapabilityType.DEVICE_NAME); |
| 82 | + } |
| 83 | + |
| 84 | + public T setEnablePerformanceLogging(boolean bool) { |
| 85 | + return amend(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING, bool); |
| 86 | + } |
| 87 | + |
| 88 | + public T setEnablePerformanceLogging() { |
| 89 | + return setEnablePerformanceLogging(true); |
| 90 | + } |
| 91 | + |
| 92 | + public boolean isEnablePerformanceLogging() { |
| 93 | + return (boolean) getCapability(MobileCapabilityType.ENABLE_PERFORMANCE_LOGGING); |
| 94 | + } |
| 95 | + |
| 96 | + public T setEventTimings(boolean bool) { |
| 97 | + return amend(MobileCapabilityType.EVENT_TIMINGS, bool); |
| 98 | + } |
| 99 | + |
| 100 | + public T setEventTimings() { |
| 101 | + return setEventTimings(true); |
| 102 | + } |
| 103 | + |
| 104 | + public boolean isEventTimings() { |
| 105 | + return (boolean) getCapability(MobileCapabilityType.EVENT_TIMINGS); |
| 106 | + } |
| 107 | + |
| 108 | + public T setFullReset(boolean bool) { |
| 109 | + return amend(MobileCapabilityType.FULL_RESET, bool); |
| 110 | + } |
| 111 | + |
| 112 | + public T setFullReset() { |
| 113 | + return setFullReset(true); |
| 114 | + } |
| 115 | + |
| 116 | + public boolean isFullReset() { |
| 117 | + return (boolean) getCapability(MobileCapabilityType.FULL_RESET); |
| 118 | + } |
| 119 | + |
| 120 | + public T setLanguage(String language) { |
| 121 | + return amend(MobileCapabilityType.LANGUAGE, language); |
| 122 | + } |
| 123 | + |
| 124 | + public String getLanguage() { |
| 125 | + return (String) getCapability(MobileCapabilityType.LANGUAGE); |
| 126 | + } |
| 127 | + |
| 128 | + public T setLocale(String locale) { |
| 129 | + return amend(MobileCapabilityType.LOCALE, locale); |
| 130 | + } |
| 131 | + |
| 132 | + public String getLocale() { |
| 133 | + return (String) getCapability(MobileCapabilityType.LOCALE); |
| 134 | + } |
| 135 | + |
| 136 | + public T setNewCommandTimeout(int seconds) { |
| 137 | + return amend(MobileCapabilityType.NEW_COMMAND_TIMEOUT, seconds); |
| 138 | + } |
| 139 | + |
| 140 | + public int getNewCommandTimeout() { |
| 141 | + return (int) getCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT); |
| 142 | + } |
| 143 | + |
| 144 | + public T setNoReset(boolean bool) { |
| 145 | + return amend(MobileCapabilityType.NO_RESET, bool); |
| 146 | + } |
| 147 | + |
| 148 | + public T setNoReset() { |
| 149 | + return setNoReset(true); |
| 150 | + } |
| 151 | + |
| 152 | + public boolean isNoReset() { |
| 153 | + return (boolean) getCapability(MobileCapabilityType.NO_RESET); |
| 154 | + } |
| 155 | + |
| 156 | + public T setOrientation(ScreenOrientation orientation) { |
| 157 | + return amend(MobileCapabilityType.ORIENTATION, orientation); |
| 158 | + } |
| 159 | + |
| 160 | + public ScreenOrientation getOrientation() { |
| 161 | + return (ScreenOrientation) getCapability(MobileCapabilityType.ORIENTATION); |
| 162 | + } |
| 163 | + |
| 164 | + // TODO: add new method for List |
| 165 | + public T setOtherApps(String app) { |
| 166 | + return amend(MobileCapabilityType.OTHER_APPS, app); |
| 167 | + } |
| 168 | + |
| 169 | + public String getOtherApps() { |
| 170 | + return (String) getCapability(MobileCapabilityType.OTHER_APPS); |
| 171 | + } |
| 172 | + |
| 173 | + public T setPlatformVersion(String version) { |
| 174 | + return amend(MobileCapabilityType.PLATFORM_VERSION, version); |
| 175 | + } |
| 176 | + |
| 177 | + public String getPlatformVersion() { |
| 178 | + return (String) getCapability(MobileCapabilityType.PLATFORM_VERSION); |
| 179 | + } |
| 180 | + |
| 181 | + public T setPrintPageSourceOnFindFailure() { |
| 182 | + return setPrintPageSourceOnFindFailure(true); |
| 183 | + } |
| 184 | + |
| 185 | + public T setPrintPageSourceOnFindFailure(boolean bool) { |
| 186 | + return amend(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE, bool); |
| 187 | + } |
| 188 | + |
| 189 | + public boolean isPrintPageSourceOnFindFailure() { |
| 190 | + return (boolean) getCapability(MobileCapabilityType.PRINT_PAGE_SOURCE_ON_FIND_FAILURE); |
| 191 | + } |
| 192 | + |
| 193 | + public T setUdid(String id) { |
| 194 | + return amend(MobileCapabilityType.UDID, id); |
| 195 | + } |
| 196 | + |
| 197 | + public String getUdid() { |
| 198 | + return (String) getCapability(MobileCapabilityType.UDID); |
| 199 | + } |
| 200 | + |
| 201 | + @Override |
| 202 | + public T merge(Capabilities extraCapabilities) { |
| 203 | + super.merge(extraCapabilities); |
| 204 | + return (T) this; |
| 205 | + } |
| 206 | + |
| 207 | + protected T amend(String optionName, Object value) { |
| 208 | + setCapability(optionName, value); |
| 209 | + return (T) this; |
| 210 | + } |
| 211 | +} |
0 commit comments