Skip to content

Commit

Permalink
SendKeys() does not only send keys but also click 'Done' ios-driver#251
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Zaytsev committed Nov 13, 2014
1 parent ad6762a commit ac2386e
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
Expand Up @@ -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) {
Expand Down
Expand Up @@ -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<String, Object> raw = new HashMap<String, Object>();

Expand Down Expand Up @@ -296,6 +297,10 @@ public boolean isTimeHack() {
return getBooleanCapability(TIME_HACK);
}

public boolean isShowKeyboardAfterClickAndType() {
return getBooleanCapability(SHOW_KEYBOARD_AFTER_CLICK_AND_TYPE);
}

private List<String> getList(String key) {
Object o = getCapability(key);
if (o == null){
Expand Down
@@ -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);
}
}
Expand Up @@ -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();
}

Expand Down

0 comments on commit ac2386e

Please sign in to comment.