2012-03-22 77 views
1

我的工作我的第一個UI自動化腳本,我在下面的deactivateAppForDuration線遭遇了失敗:的iOS UI自動化deactivateAppForDuration失敗

// Verify password field is shown when app is moved to the foreground 
UIALogger.logMessage("move app to background"); 
target.deactivateAppForDuration(10); 
UIALogger.logMessage("move app to foreground"); 

我從儀器得到的錯誤是:

Script threw an uncaught JavaScript error: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().switcherScrollView().buttons()["TimeClock"]

我在測試設備上看到的應用程序已切換到背景並顯示iOS應用程序切換器。我可以看到我的應用程序(TimeClock)。它從錯誤消息和設備屏幕中顯示,UI自動化無法選擇我的應用程序以轉換到前臺。

有其他人遇到過這個問題嗎?有沒有解決辦法?

謝謝。

回答

1

我試過你的代碼,它在這裏工作的很好。如果你在一個新的Instruments文件中運行下面的代碼(沒有其他),這是否工作?

var target = UIATarget.localTarget(); 
UIALogger.logMessage("move app to background"); 
target.deactivateAppForDuration(1); 
UIALogger.logMessage("move app to foreground"); 

請注意:儀器是總是顯示你到底其中的錯誤發生。有時會在它顯示的行的上面或下面幾行。 但是:原因錯誤發生的原因是正確的。我承認你有一個錯誤在這一行,我猜你是從跳板回來後打電話:

Script threw an uncaught JavaScript error: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().switcherScrollView().buttons()["TimeClock"] 

確定元素switcherScrollView().buttons()["TimeClock"]在您的應用程序存在,都可以訪問?

+2

在這種情況下,'switcherScrollView()'表示設備本身的切換控件,而不是應用程序。 'switcherScrollView()。buttons()[「TimeClock」]'表示應用切換器中他的應用的圖標。 – Darc 2012-03-28 22:22:14

1

我有同樣的問題。重新啓動我的設備爲我解決了它。

+0

在這種情況下重新啓動模擬器,但也適用於我。 – 2013-07-24 23:26:34