Need help automate iPhone keyboard input throught javascript
I am trying to automate iPHone UI testing throught JavaScript.
I am in a compose mail page and I need to enter email-id in the TO,CC & BCC fields. I have the focus in TO field and keyboard is displayed. To field is UIATextField, however the usual way of entering data into textfield i开发者_运维知识库s not entering the data.
I used the following code
var app = UIATarget.localTarget().frontMostApp();
app.keyboard().elements()["go"].tap();
But did no good for me :(
I want to input the email address(abc@xyz.com) through the displayed keyboard.
Please help me with a code snippet. Also please let me know how to change the focus from "TO" field to "CC" which are one below the other.
The Header
, Body
buttons on the page are a segmentedControls
. I am not able to tap them using the code snippet.
var app = UIATarget.localTarget().frontMostApp();
app.segmentedControls()[0].buttons()["Body"].tap();
Please help me with this.
Thanks in Advance Kiran
I think you could do this a little better and with some reusability. Try defining a method like this:
function typeCharacters(inputString) {
for(var i in inputString) {
target.frontMostApp().keyboard().typeString(inputString[i]);
}
target.frontMostApp().keyboard().typeString("\n");
}
A quick test of this might look like this:
var timestamp = new Date().toString();
typeCharacters(timestamp);
Then you sit back and enjoy watching the keyboard type out a nice date for you.
Finally figured out how to automate the keyboard tapping
This is the code snippet which worked for me
//Get the keyboard handle
var keyBoard=app.keyboard();
//Get the handle for keys
var keys = keyBoard.keys();
//Get the handle for buttons on the keyboard (Space, Enter, Shift etc)
var keyButtons = keyBoard.buttons();
//To type "hi"
//type "h"
keys.firstWithName("h").tap();
//insert a delay for the tap() action to be completed
target.delay(0.5);
keys.firstWithName("i").tap();
target.delay(0.5);
精彩评论