From ac2386e9a117ea501c61d7dd595c38b28661e6c7 Mon Sep 17 00:00:00 2001 From: Alex Zaytsev Date: Wed, 12 Nov 2014 13:03:48 -0800 Subject: [PATCH] SendKeys() does not only send keys but also click 'Done' #251 --- .../uiamodels/impl/RemoteIOSDriver.java | 8 ++ .../org/uiautomation/ios/IOSCapabilities.java | 5 ++ .../ShowKeyboardAfterClickAndTypeTest.java | 78 +++++++++++++++++++ .../model/RemoteWebNativeBackedElement.java | 11 ++- 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 ios-selenium-tests/src/test/java/org/uiautomation/ios/selenium/ShowKeyboardAfterClickAndTypeTest.java diff --git a/client/src/main/java/org/uiautomation/ios/client/uiamodels/impl/RemoteIOSDriver.java b/client/src/main/java/org/uiautomation/ios/client/uiamodels/impl/RemoteIOSDriver.java index 22629061..e1939d67 100644 --- a/client/src/main/java/org/uiautomation/ios/client/uiamodels/impl/RemoteIOSDriver.java +++ b/client/src/main/java/org/uiautomation/ios/client/uiamodels/impl/RemoteIOSDriver.java @@ -139,6 +139,14 @@ public IOSCapabilities getCapabilities() { return ioscap; } + public IOSCapabilities getRequestedCapabilities() { + if (requestedCapabilities == null) { + return null; + } + IOSCapabilities ioscap = new IOSCapabilities(requestedCapabilities); + return ioscap; + } + @Override protected WebElement findElement(String by, String using) { if (using == null) { diff --git a/common/src/main/java/org/uiautomation/ios/IOSCapabilities.java b/common/src/main/java/org/uiautomation/ios/IOSCapabilities.java index 2c33c35a..c7df923d 100644 --- a/common/src/main/java/org/uiautomation/ios/IOSCapabilities.java +++ b/common/src/main/java/org/uiautomation/ios/IOSCapabilities.java @@ -90,6 +90,7 @@ public class IOSCapabilities extends DesiredCapabilities { public static final String INSTRUMENTS = "instruments"; public static final String PROVISIONNED = "provisionnedDevices"; + public static final String SHOW_KEYBOARD_AFTER_CLICK_AND_TYPE = "showKeyboardAfterClickAndType"; // private final Map raw = new HashMap(); @@ -296,6 +297,10 @@ public boolean isTimeHack() { return getBooleanCapability(TIME_HACK); } + public boolean isShowKeyboardAfterClickAndType() { + return getBooleanCapability(SHOW_KEYBOARD_AFTER_CLICK_AND_TYPE); + } + private List getList(String key) { Object o = getCapability(key); if (o == null){ diff --git a/ios-selenium-tests/src/test/java/org/uiautomation/ios/selenium/ShowKeyboardAfterClickAndTypeTest.java b/ios-selenium-tests/src/test/java/org/uiautomation/ios/selenium/ShowKeyboardAfterClickAndTypeTest.java new file mode 100644 index 00000000..ea4dbcaa --- /dev/null +++ b/ios-selenium-tests/src/test/java/org/uiautomation/ios/selenium/ShowKeyboardAfterClickAndTypeTest.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2013 eBay Software Foundation and ios-driver committers + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.uiautomation.ios.selenium; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.testng.annotations.Test; +import org.uiautomation.ios.IOSCapabilities; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + + +public class ShowKeyboardAfterClickAndTypeTest extends BaseSeleniumTest { + + @Test() + public void testShowKeyBoardAfterClick() throws Exception { + + IOSCapabilities caps = IOSCapabilities.iphone("Safari"); + caps.setCapability(IOSCapabilities.SHOW_KEYBOARD_AFTER_CLICK_AND_TYPE, true); + + startDriver(caps); + driver.get(pages.formPage); + + String stringyNumber = ""; + String numberNumber = "18003569377"; + String validationNumber = null; + // iphone has number trackpad, ipad is has full keyboard still + if (driver.getCapabilities().getCapability(IOSCapabilities.DEVICE).equals("iphone")) { + validationNumber = numberNumber; + } else { + validationNumber = stringyNumber; + } + + WebElement input = driver.findElement(By.id("telephone")); + input.sendKeys(numberNumber); + Thread.sleep(2000); + + assertEquals(input.getAttribute("value"), validationNumber); + assertTrue(Boolean.TRUE.equals(driver.getRequestedCapabilities().getCapability + (IOSCapabilities.SHOW_KEYBOARD_AFTER_CLICK_AND_TYPE))); + + stopDriver(); + } + + @Test() + public void testHideKeyBoardAfterClick() throws Exception { + + driver.get(pages.formPage); + + String stringyNumber = ""; + String numberNumber = "18003569377"; + String validationNumber = null; + // iphone has number trackpad, ipad is has full keyboard still + if (driver.getCapabilities().getCapability(IOSCapabilities.DEVICE).equals("iphone")) { + validationNumber = numberNumber; + } else { + validationNumber = stringyNumber; + } + + WebElement input = driver.findElement(By.id("telephone")); + input.sendKeys(numberNumber); + Thread.sleep(2000); + + assertEquals(input.getAttribute("value"), validationNumber); + } +} diff --git a/server/src/main/java/org/uiautomation/ios/wkrdp/model/RemoteWebNativeBackedElement.java b/server/src/main/java/org/uiautomation/ios/wkrdp/model/RemoteWebNativeBackedElement.java index a00da0cb..9ed3b529 100644 --- a/server/src/main/java/org/uiautomation/ios/wkrdp/model/RemoteWebNativeBackedElement.java +++ b/server/src/main/java/org/uiautomation/ios/wkrdp/model/RemoteWebNativeBackedElement.java @@ -288,9 +288,16 @@ private String getNativeElementClickOnItAndTypeUsingKeyboardScript(String value) script.append(getKeyboardTypeStringSegement(current.toString())); } - if (!keyboardResigned) { - script.append("keyboard.hide();"); + //check to see if the user wants to keep the keyboard after typing in text + Boolean showKeyboardAfterClickAndType = Boolean.TRUE.equals(session.getCapabilities() + .getCapability((IOSCapabilities.SHOW_KEYBOARD_AFTER_CLICK_AND_TYPE))); + + if (!showKeyboardAfterClickAndType) { + if (!keyboardResigned) { + script.append("keyboard.hide();"); + } } + return script.toString(); }