11package com .github .rainmanwy .robotframework .sikulilib .utils ;
22
3- import com .github .rainmanwy .robotframework .sikulilib .exceptions .ScreenOperationException ;
43import com .github .rainmanwy .robotframework .sikulilib .keywords .AppiumKeywords ;
54import io .appium .java_client .AppiumBy ;
65import io .appium .java_client .AppiumDriver ;
109import io .appium .java_client .android .nativekey .KeyEventMetaModifier ;
1110import io .appium .java_client .ios .IOSDriver ;
1211import org .openqa .selenium .Dimension ;
13- import org .openqa .selenium .StaleElementReferenceException ;
14- import org .openqa .selenium .TimeoutException ;
1512import org .openqa .selenium .WebElement ;
1613import org .openqa .selenium .interactions .PointerInput ;
1714import org .openqa .selenium .interactions .Sequence ;
@@ -139,7 +136,7 @@ public void appiumInputText(AppiumDriver appiumDriver, String locator, String te
139136 public void appiumClearText1 (AppiumDriver appiumDriver , String text , boolean exactMatch ) {
140137 String locator = locator (text , exactMatch );
141138 WebDriverWait wait = new WebDriverWait (appiumDriver , Duration .ofSeconds (10 ));
142- WebElement el = wait .until (ExpectedConditions .visibilityOfElementLocated ( AppiumBy .xpath (locator )));
139+ WebElement el = wait .until (ExpectedConditions .visibilityOfElementLocated (AppiumBy .xpath (locator )));
143140 el .clear ();
144141 }
145142
@@ -154,7 +151,7 @@ public void appiumClickElement(AppiumDriver appiumDriver, String locator) {
154151 public void appiumClickText (AppiumDriver appiumDriver , String textClick , boolean exactMatch ) {
155152 try {
156153 String locator = locator (textClick , exactMatch );
157- appiumDriver .findElement ( AppiumBy .xpath (locator )).click ();
154+ appiumDriver .findElement (AppiumBy .xpath (locator )).click ();
158155 } catch (Exception e ) {
159156 throw new ScreenshotException ("Cannot find element has " + textClick );
160157 }
@@ -214,7 +211,7 @@ public void swipeUntilTextIsVisible(AppiumDriver appiumDriver, String text) thro
214211 String locator = locator (text , false );
215212 while (!isTextVisible ) {
216213 try {
217- WebElement element = appiumDriver .findElement ( AppiumBy .xpath (locator ));
214+ WebElement element = appiumDriver .findElement (AppiumBy .xpath (locator ));
218215 if (element != null && element .isDisplayed ()) {
219216 isTextVisible = true ;
220217 }
@@ -444,7 +441,7 @@ public void waitUntilPageContainsText(AppiumDriver appiumDriver, String text, Bo
444441 try {
445442 String xpath = locator (text , exactMatch );
446443 WebDriverWait wait = new WebDriverWait (appiumDriver , Duration .ofSeconds (time ));
447- wait .until (ExpectedConditions .visibilityOfElementLocated ( AppiumBy .xpath (xpath ) ));
444+ wait .until (ExpectedConditions .visibilityOfElementLocated (AppiumBy .xpath (xpath )));
448445 } catch (Exception e ) {
449446 throw new ScreenshotException ("Timed out waiting for page to contain text: " + text );
450447 }
@@ -479,7 +476,7 @@ public void waitUntilPageDoesNotContain(AppiumDriver appiumDriver, String text,
479476 try {
480477 String xpath = locator (text , false );
481478 WebDriverWait wait = new WebDriverWait (appiumDriver , Duration .ofSeconds (time ));
482- wait .until (ExpectedConditions .invisibilityOfElementLocated ( AppiumBy .xpath (xpath ) ));
479+ wait .until (ExpectedConditions .invisibilityOfElementLocated (AppiumBy .xpath (xpath )));
483480 } catch (Exception e ) {
484481 throw new ScreenshotException ("Timed out waiting for page to contain text: " + text );
485482 }
@@ -492,4 +489,64 @@ public void tapOnCoordinates(AppiumDriver appiumDriver, int x, int y) {
492489 appiumDriver .perform (Arrays .asList (clickPosition ));
493490 }
494491
492+ public void tapElement (AppiumDriver appiumDriver , WebElement element ) {
493+ PointerInput finger = new PointerInput (org .openqa .selenium .interactions .PointerInput .Kind .TOUCH , "finger" );
494+ org .openqa .selenium .interactions .Sequence clickPosition = new org .openqa .selenium .interactions .Sequence (finger , 1 );
495+ clickPosition .addAction (finger .createPointerMove (Duration .ZERO , PointerInput .Origin .viewport (), element .getLocation ().x , element .getLocation ().y )).addAction (finger .createPointerDown (PointerInput .MouseButton .LEFT .asArg ())).addAction (finger .createPointerUp (PointerInput .MouseButton .LEFT .asArg ()));
496+ appiumDriver .perform (Arrays .asList (clickPosition ));
497+ }
498+
499+ public void datePicker (AppiumDriver appiumDriver , String date , String month , String year ) throws InterruptedException {
500+ if (AppiumKeywords .platform .equalsIgnoreCase ("iOS" )) {
501+
502+ WebElement yearEl = appiumDriver .findElement (AppiumBy .xpath ("//XCUIElementTypeOther[@name='Select date']/XCUIElementTypeDatePicker/XCUIElementTypePicker/XCUIElementTypePickerWheel[3]" ));
503+ yearEl .clear ();
504+ yearEl .sendKeys (year );
505+
506+ WebElement monEl = appiumDriver .findElement (AppiumBy .xpath ("//XCUIElementTypeOther[@name='Select date']/XCUIElementTypeDatePicker/XCUIElementTypePicker/XCUIElementTypePickerWheel[1]" ));
507+ monEl .clear ();
508+ monEl .sendKeys (month );
509+
510+ WebElement dateEl = appiumDriver .findElement (AppiumBy .xpath ("//XCUIElementTypeOther[@name='Select date']/XCUIElementTypeDatePicker/XCUIElementTypePicker/XCUIElementTypePickerWheel[2]" ));
511+ dateEl .clear ();
512+ dateEl .sendKeys (date );
513+
514+ } else if (AppiumKeywords .platform .equalsIgnoreCase ("Android" )) {
515+
516+ for (int i = 0 ; i < 100 ; i ++) {
517+ if (!findElements (appiumDriver , "xpath=//android.widget.NumberPicker[3]//android.widget.EditText" ).getText ().equalsIgnoreCase (year )) {
518+ WebElement preYear = appiumDriver .findElement (AppiumBy .xpath ("//android.widget.NumberPicker[3]/android.widget.Button" ));
519+ tapElement (appiumDriver , preYear );
520+ } else {
521+ break ;
522+ }
523+ Thread .sleep (1000 );
524+ }
525+
526+ for (int i = 0 ; i < 31 ; i ++) {
527+ if (!findElements (appiumDriver , "xpath=//android.widget.NumberPicker[2]/android.widget.EditText" ).getText ().equalsIgnoreCase (date )) {
528+ WebElement nextDate = appiumDriver .findElement (AppiumBy .xpath ("//android.widget.NumberPicker[2]/android.widget.Button[1]" ));
529+ tapElement (appiumDriver , nextDate );
530+ } else {
531+ break ;
532+ }
533+ Thread .sleep (1000 );
534+ }
535+
536+ for (int i = 0 ; i < 12 ; i ++) {
537+ if (!findElements (appiumDriver , "xpath=//android.widget.NumberPicker[1]/android.widget.EditText" ).getText ().equalsIgnoreCase (month )) {
538+ WebElement nextMonth = appiumDriver .findElement (AppiumBy .xpath ("//android.widget.NumberPicker[1]/android.widget.Button[1]" ));
539+ tapElement (appiumDriver , nextMonth );
540+ } else {
541+ break ;
542+ }
543+ Thread .sleep (1000 );
544+ }
545+
546+
547+ } else {
548+ System .out .println ("Unsupported platform" );
549+ }
550+ }
551+
495552}
0 commit comments