Skip to content

Commit 59e17c1

Browse files
committed
Added select date on iOS and Android
1 parent 3fa3212 commit 59e17c1

3 files changed

Lines changed: 78 additions & 12 deletions

File tree

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,3 @@ teste
1010
.settings/
1111
pom.xml
1212
build/
13-
src/robotframework_AppiumSikuliLibrary.egg-info/dependency_links.txt
14-
src/robotframework_AppiumSikuliLibrary.egg-info/PKG-INFO
15-
src/robotframework_AppiumSikuliLibrary.egg-info/SOURCES.txt
16-
src/robotframework_AppiumSikuliLibrary.egg-info/top_level.txt

src/java/com/github/rainmanwy/robotframework/sikulilib/keywords/AppiumKeywords.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ public int[] tapWordOnMobile(String text, Integer colorOption) throws Exception
349349
int newX = pos.getX();
350350
int newY = pos.getY();
351351
helper.tapOnCoordinates(driver, newX, newY);
352+
353+
if ( colorOption > 0){
354+
OCR.globalOptions().resetFontSetting();
355+
}
356+
352357
return regionFromMatch(match);
353358
} catch (Exception e) {
354359
capture();
@@ -825,4 +830,12 @@ public boolean isTextExistOnMobileScreen(String text) throws Exception {
825830
return helper.pageShouldContainText(driver, text);
826831
}
827832

833+
@RobotKeyword("Pick Date"
834+
+ "\nExamples:"
835+
+ "\n| Pick Date | 10 | November | 2000 |")
836+
@ArgumentNames({"date", "month", "year"})
837+
public void pickDate(String date, String month, String year) throws Exception {
838+
helper.datePicker(driver, date, month, year);
839+
}
840+
828841
}

src/java/com/github/rainmanwy/robotframework/sikulilib/utils/AppiumHelper.java

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.rainmanwy.robotframework.sikulilib.utils;
22

3-
import com.github.rainmanwy.robotframework.sikulilib.exceptions.ScreenOperationException;
43
import com.github.rainmanwy.robotframework.sikulilib.keywords.AppiumKeywords;
54
import io.appium.java_client.AppiumBy;
65
import io.appium.java_client.AppiumDriver;
@@ -10,8 +9,6 @@
109
import io.appium.java_client.android.nativekey.KeyEventMetaModifier;
1110
import io.appium.java_client.ios.IOSDriver;
1211
import org.openqa.selenium.Dimension;
13-
import org.openqa.selenium.StaleElementReferenceException;
14-
import org.openqa.selenium.TimeoutException;
1512
import org.openqa.selenium.WebElement;
1613
import org.openqa.selenium.interactions.PointerInput;
1714
import 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

Comments
 (0)