2015-06-01 50 views
1

我是UIAutomation的新手,我試圖在UITabelView中爲兩個文本字段輸入值。UIAutomation腳本用於設置UItableView中的文本字段值

我嘗試的劇本是低於第一小區

var target = UIATarget.localTarget(); 

var app = target.frontMostApp(); 

var window = app.mainWindow(); 

target.delay(1); 

var tableView = window.tableViews()[0]; 

tableView.logElementTree(); 

var cellOne = tableView.cells()[0].textFields()[0].setValue(「username」); 
var cellTwo = tableView.cells()[1].textFields()[0].setValue(「password」); 

文本字段總是被進入,但第二個總是失敗。當我嘗試登錄其元素樹時,它返回UIElementNil

我的腳本有什麼問題嗎?

回答

2

我檢查了Apple的Automation UI Testing文檔,並將錄製手動用戶界面操作記錄到自動化腳本和工具中,並根據我的手動操作爲我創建了腳本。

如果有人像我一樣被我擊敗,並且不會瀏覽Apple的文檔。請不要那樣做,並且總是先引用Apple的文檔。

這裏的參考

https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UsingtheAutomationInstrument/UsingtheAutomationInstrument.html

這是我的腳本

var target = UIATarget.localTarget(); 

var app = target.frontMostApp(); 

var window = app.mainWindow(); 

window.buttons()["Login"].tap(); 

target.delay(1); 

var tableView = window.tableViews()[0]; 

tableView.cells()[0].textFields()[0].textFields()[0].setValue("username"); 

tableView.cells()[1].secureTextFields()[0].secureTextFields()[0].setValue("password"); 

window.navigationBar().rightButton().tap(); 

正如你可以看到我沒有注意到,密碼文本框是一個securedTextField。