|
16 | 16 |
|
17 | 17 | package io.appium.java_client.ios; |
18 | 18 |
|
| 19 | +import static io.appium.java_client.MobileCommand.prepareArguments; |
19 | 20 | import static io.appium.java_client.ios.IOSMobileCommandHelper.hideKeyboardCommand; |
20 | 21 | import static io.appium.java_client.ios.IOSMobileCommandHelper.lockDeviceCommand; |
21 | 22 | import static io.appium.java_client.ios.IOSMobileCommandHelper.shakeCommand; |
|
27 | 28 | import io.appium.java_client.remote.MobilePlatform; |
28 | 29 | import io.appium.java_client.service.local.AppiumDriverLocalService; |
29 | 30 | import io.appium.java_client.service.local.AppiumServiceBuilder; |
30 | | - |
| 31 | +import org.openqa.selenium.Alert; |
31 | 32 | import org.openqa.selenium.Capabilities; |
32 | 33 | import org.openqa.selenium.WebDriverException; |
33 | 34 | import org.openqa.selenium.WebElement; |
| 35 | +import org.openqa.selenium.remote.DriverCommand; |
34 | 36 | import org.openqa.selenium.remote.HttpCommandExecutor; |
| 37 | +import org.openqa.selenium.remote.Response; |
35 | 38 | import org.openqa.selenium.remote.http.HttpClient; |
| 39 | +import org.openqa.selenium.security.Credentials; |
36 | 40 |
|
37 | 41 | import java.net.URL; |
38 | 42 | import java.util.List; |
39 | 43 |
|
| 44 | + |
40 | 45 | /** |
41 | 46 | * @param <T> the required type of class which implement |
42 | 47 | * {@link org.openqa.selenium.WebElement}. |
@@ -220,4 +225,50 @@ public List<T> findElementsByIosUIAutomation(String using) |
220 | 225 | public void lockDevice(int seconds) { |
221 | 226 | CommandExecutionHelper.execute(this, lockDeviceCommand(seconds)); |
222 | 227 | } |
| 228 | + |
| 229 | + @Override public TargetLocator switchTo() { |
| 230 | + return new InnerTargetLocator(); |
| 231 | + } |
| 232 | + |
| 233 | + private class InnerTargetLocator extends RemoteTargetLocator { |
| 234 | + @Override public Alert alert() { |
| 235 | + return new IOSAlert(super.alert()); |
| 236 | + } |
| 237 | + } |
| 238 | + |
| 239 | + |
| 240 | + class IOSAlert implements Alert { |
| 241 | + |
| 242 | + private final Alert alert; |
| 243 | + |
| 244 | + IOSAlert(Alert alert) { |
| 245 | + this.alert = alert; |
| 246 | + } |
| 247 | + |
| 248 | + @Override public void dismiss() { |
| 249 | + execute(DriverCommand.DISMISS_ALERT); |
| 250 | + } |
| 251 | + |
| 252 | + @Override public void accept() { |
| 253 | + execute(DriverCommand.ACCEPT_ALERT); |
| 254 | + } |
| 255 | + |
| 256 | + @Override public String getText() { |
| 257 | + Response response = execute(DriverCommand.GET_ALERT_TEXT); |
| 258 | + return response.getValue().toString(); |
| 259 | + } |
| 260 | + |
| 261 | + @Override public void sendKeys(String keysToSend) { |
| 262 | + execute(DriverCommand.SET_ALERT_VALUE, prepareArguments("value", keysToSend)); |
| 263 | + } |
| 264 | + |
| 265 | + @Override public void setCredentials(Credentials credentials) { |
| 266 | + alert.setCredentials(credentials); |
| 267 | + } |
| 268 | + |
| 269 | + @Override public void authenticateUsing(Credentials credentials) { |
| 270 | + alert.authenticateUsing(credentials); |
| 271 | + } |
| 272 | + |
| 273 | + } |
223 | 274 | } |
0 commit comments