2011-02-01 60 views
1

我想通過JavaScript自動化iPHone UI測試。需要幫助通過JavaScript自動化iPhone鍵盤輸入

我處於撰寫郵件頁面,我需要在TO,CC & BCC字段中輸入email-id。我將焦點放在TO字段並顯示鍵盤。字段是UIATextField,但是將數據輸入到文本字段的常用方式是不輸入數據。

我用下面的代碼

var app = UIATarget.localTarget().frontMostApp(); 
app.keyboard().elements()["go"].tap(); 

但通過顯示的鍵盤確實不適合我:(

我想輸入的電子郵件地址([email protected])。

請幫助我一個代碼片段,請讓我知道如何將焦點從「TO」字段更改爲「CC」,它們是一個在另一個之下。,Body按鈕在頁面上是segmentedControls。我無法使用代碼段點擊它們。

var app = UIATarget.localTarget().frontMostApp(); 
app.segmentedControls()[0].buttons()["Body"].tap(); 

請幫我這個。

由於提前 基蘭

+0

請修復標籤。 visual-C++是用於在Windows上開發的Microsoft編譯器,而不是iPhone。你想要iphone標籤。 – 2011-02-01 07:07:02

回答

0

我認爲你可以做到這一點更好,並具有一些可重用性。嘗試定義這樣的方法:

function typeCharacters(inputString) { 
    for(var i in inputString) { 
     target.frontMostApp().keyboard().typeString(inputString[i]); 
    } 
    target.frontMostApp().keyboard().typeString("\n"); 
} 

的這種快速測試可能是這樣的:

var timestamp = new Date().toString(); 
typeCharacters(timestamp); 

然後,你坐下來欣賞的鍵盤鍵入了一個不錯的日期。

0

終於想通了如何將鍵盤敲擊自動化

這是代碼片段,其工作對我來說

//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);