11package net .itarray .automotion .internal ;
22
33import io .appium .java_client .AppiumDriver ;
4+ import io .appium .java_client .android .AndroidDriver ;
45import org .openqa .selenium .*;
56import org .openqa .selenium .remote .RemoteWebDriver ;
67
@@ -33,6 +34,31 @@ public void takeScreenshot(File file) {
3334 }
3435 }
3536
37+ public WebDriver getDriver () {
38+ return driver ;
39+ }
40+
41+ public boolean isAppiumAndroidContext () {
42+ if ((driver instanceof AndroidDriver )) {
43+ return true ;
44+ }
45+ return false ;
46+ }
47+
48+ public boolean isAppiumIOSContext () {
49+ if ((driver instanceof AndroidDriver )) {
50+ return true ;
51+ }
52+ return false ;
53+ }
54+
55+ public boolean isAppiumContext () {
56+ if ((driver instanceof AppiumDriver )) {
57+ return true ;
58+ }
59+ return false ;
60+ }
61+
3662 public boolean isAppiumWebContext () {
3763 if (!(driver instanceof AppiumDriver )) {
3864 return false ;
@@ -68,14 +94,14 @@ private String getZoomScript() {
6894 }
6995
7096 private long retrievePageHeight () {
71- if (!isMobile ()) {
97+ if (!isAppiumAndroidContext ()) {
7298 if (getZoom ().equals ("100%" )) {
7399 return (long ) executeScript ("if (self.innerHeight) {return self.innerHeight;} if (document.documentElement && document.documentElement.clientHeight) {return document.documentElement.clientHeight;}if (document.body) {return document.body.clientHeight;}" );
74100 } else {
75101 return (long ) executeScript ("return document.getElementsByTagName('body')[0].offsetHeight" );
76102 }
77103 } else {
78- if (isAppiumNativeMobileContext () || isIOS ()) {
104+ if (isAppiumNativeMobileContext () || isAppiumIOSContext ()) {
79105 return driver .manage ().window ().getSize ().getHeight ();
80106 } else {
81107 return (long ) executeScript ("if (self.innerHeight) {return self.innerHeight;} if (document.documentElement && document.documentElement.clientHeight) {return document.documentElement.clientHeight;}if (document.body) {return document.body.clientHeight;}" );
@@ -84,15 +110,15 @@ private long retrievePageHeight() {
84110 }
85111
86112 private long retrievePageWidth () {
87- if (!isMobile ()) {
113+ if (!isAppiumAndroidContext ()) {
88114 if (getZoom ().equals ("100%" )) {
89115 String script = "if (self.innerWidth) {return self.innerWidth;} if (document.documentElement && document.documentElement.clientWidth) {return document.documentElement.clientWidth;}if (document.body) {return document.body.clientWidth;}" ;
90116 return (long ) executeScript (script );
91117 } else {
92118 return (long ) executeScript ("return document.getElementsByTagName('body')[0].offsetWidth" );
93119 }
94120 } else {
95- if (isAppiumNativeMobileContext () || isIOS ()) {
121+ if (isAppiumNativeMobileContext () || isAppiumIOSContext ()) {
96122 return driver .manage ().window ().getSize ().getWidth ();
97123 } else {
98124 return (long ) executeScript ("if (self.innerWidth) {return self.innerWidth;} if (document.documentElement && document.documentElement.clientWidth) {return document.documentElement.clientWidth;}if (document.body) {return document.body.clientWidth;}" );
@@ -110,7 +136,7 @@ public void setResolution(Dimension resolution) {
110136 }
111137
112138 public Dimension getResolution () {
113- if (isMobile () && getApp () == null ) {
139+ if (isAppiumContext () && getApp () == null ) {
114140 String resolution = ((RemoteWebDriver ) driver ).getCapabilities ().getCapability ("deviceScreenSize" ).toString ();
115141 int width = Integer .parseInt (resolution .split ("x" )[0 ]);
116142 int height = Integer .parseInt (resolution .split ("x" )[1 ]);
0 commit comments