30
30
31
31
import org .openqa .selenium .By ;
32
32
import org .openqa .selenium .Capabilities ;
33
+ import org .openqa .selenium .DeviceRotation ;
33
34
import org .openqa .selenium .Dimension ;
34
35
import org .openqa .selenium .Point ;
35
36
import org .openqa .selenium .ScreenOrientation ;
57
58
import java .util .Map ;
58
59
import java .util .Set ;
59
60
61
+
60
62
/**
61
- * @param <T> the required type of class which implement {@link org.openqa.selenium.WebElement}.
62
- * Instances of the defined type will be returned via findElement* and findElements*
63
- * Warning (!!!). Allowed types:
64
- * {@link org.openqa.selenium.WebElement}
65
- * {@link io.appium.java_client.TouchableElement}
66
- * {@link org.openqa.selenium.remote.RemoteWebElement}
67
- * {@link io.appium.java_client.MobileElement} and its subclasses that designed
68
- * specifically
69
- * for each target mobile OS (still Android and iOS)
70
- */
63
+ * @param <T> the required type of class which implement {@link org.openqa.selenium.WebElement}.
64
+ * Instances of the defined type will be returned via findElement* and findElements*
65
+ * Warning (!!!). Allowed types:
66
+ * {@link org.openqa.selenium.WebElement}
67
+ * {@link io.appium.java_client.TouchableElement}
68
+ * {@link org.openqa.selenium.remote.RemoteWebElement}
69
+ * {@link io.appium.java_client.MobileElement} and its subclasses that designed
70
+ * specifically
71
+ * for each target mobile OS (still Android and iOS)
72
+ */
71
73
@ SuppressWarnings ("unchecked" )
72
74
public abstract class AppiumDriver <T extends WebElement >
73
75
extends DefaultGenericMobileDriver <T > {
@@ -79,13 +81,13 @@ public abstract class AppiumDriver<T extends WebElement>
79
81
private ExecuteMethod executeMethod ;
80
82
81
83
/**
82
- * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}
83
- * or class that extends it. Default commands or another vendor-specific
84
- * commands may be specified there.
85
- * @param capabilities take a look
86
- * at {@link org.openqa.selenium.Capabilities}
84
+ * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}
85
+ * or class that extends it. Default commands or another vendor-specific
86
+ * commands may be specified there.
87
+ * @param capabilities take a look
88
+ * at {@link org.openqa.selenium.Capabilities}
87
89
* @param converterClazz is an instance of a class that extends
88
- * {@link org.openqa.selenium.remote.internal.JsonToWebElementConverter}. It converts
90
+ * {@link org.openqa.selenium.remote.internal.JsonToWebElementConverter}. It converts
89
91
* JSON response to an instance of
90
92
* {@link org.openqa.selenium.WebElement}
91
93
*/
@@ -98,10 +100,10 @@ protected AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities,
98
100
this .remoteAddress = executor .getAddressOfRemoteServer ();
99
101
try {
100
102
Constructor <? extends JsonToWebElementConverter > constructor =
101
- converterClazz .getConstructor (RemoteWebDriver .class );
103
+ converterClazz .getConstructor (RemoteWebDriver .class );
102
104
this .setElementConverter (constructor .newInstance (this ));
103
105
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException
104
- | InvocationTargetException e ) {
106
+ | InvocationTargetException e ) {
105
107
throw new RuntimeException (e );
106
108
}
107
109
}
@@ -114,7 +116,7 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities,
114
116
115
117
public AppiumDriver (URL remoteAddress , HttpClient .Factory httpClientFactory ,
116
118
Capabilities desiredCapabilities ,
117
- Class <? extends JsonToWebElementConverter > converterClazz ) {
119
+ Class <? extends JsonToWebElementConverter > converterClazz ) {
118
120
this (new AppiumCommandExecutor (MobileCommand .commandRepository , remoteAddress ,
119
121
httpClientFactory ), desiredCapabilities , converterClazz );
120
122
}
@@ -127,7 +129,7 @@ public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabi
127
129
128
130
public AppiumDriver (AppiumDriverLocalService service , HttpClient .Factory httpClientFactory ,
129
131
Capabilities desiredCapabilities ,
130
- Class <? extends JsonToWebElementConverter > converterClazz ) {
132
+ Class <? extends JsonToWebElementConverter > converterClazz ) {
131
133
this (new AppiumCommandExecutor (MobileCommand .commandRepository , service , httpClientFactory ),
132
134
desiredCapabilities , converterClazz );
133
135
}
@@ -139,14 +141,14 @@ public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabiliti
139
141
140
142
public AppiumDriver (AppiumServiceBuilder builder , HttpClient .Factory httpClientFactory ,
141
143
Capabilities desiredCapabilities ,
142
- Class <? extends JsonToWebElementConverter > converterClazz ) {
144
+ Class <? extends JsonToWebElementConverter > converterClazz ) {
143
145
this (builder .build (), httpClientFactory , desiredCapabilities , converterClazz );
144
146
}
145
147
146
148
public AppiumDriver (HttpClient .Factory httpClientFactory , Capabilities desiredCapabilities ,
147
149
Class <? extends JsonToWebElementConverter > converterClazz ) {
148
- this (AppiumDriverLocalService .buildDefaultService (), httpClientFactory ,
149
- desiredCapabilities , converterClazz );
150
+ this (AppiumDriverLocalService .buildDefaultService (), httpClientFactory , desiredCapabilities ,
151
+ converterClazz );
150
152
}
151
153
152
154
public AppiumDriver (Capabilities desiredCapabilities ,
@@ -156,8 +158,8 @@ public AppiumDriver(Capabilities desiredCapabilities,
156
158
157
159
/**
158
160
* @param originalCapabilities the given {@link Capabilities}.
159
- * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has
160
- * to be set up
161
+ * @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has
162
+ * to be set up
161
163
* @return {@link Capabilities} with changed mobile platform value
162
164
*/
163
165
protected static Capabilities substituteMobilePlatform (Capabilities originalCapabilities ,
@@ -409,6 +411,21 @@ public void zoom(int x, int y) {
409
411
return contextName ;
410
412
}
411
413
414
+ @ Override public DeviceRotation rotation () {
415
+ Response response = execute (DriverCommand .GET_SCREEN_ROTATION );
416
+ DeviceRotation deviceRotation =
417
+ new DeviceRotation ((Map <String , Number >) response .getValue ());
418
+ if (deviceRotation .getX () < 0 || deviceRotation .getY () < 0 || deviceRotation .getZ () < 0 ) {
419
+ throw new WebDriverException ("Unexpected orientation returned: " + deviceRotation );
420
+ }
421
+ return deviceRotation ;
422
+ }
423
+
424
+ @ Override public void rotate (DeviceRotation rotation ) {
425
+ execute (DriverCommand .SET_SCREEN_ROTATION , rotation .parameters ());
426
+ }
427
+
428
+
412
429
@ Override public void rotate (ScreenOrientation orientation ) {
413
430
execute (DriverCommand .SET_SCREEN_ORIENTATION ,
414
431
ImmutableMap .of ("orientation" , orientation .value ().toUpperCase ()));
@@ -450,7 +467,6 @@ public URL getRemoteAddress() {
450
467
451
468
/**
452
469
* @return a map with values that hold session details.
453
- *
454
470
*/
455
471
public Map <String , Object > getSessionDetails () {
456
472
Response response = execute (GET_SESSION );
0 commit comments