2012-01-24 35 views
0

我是新來的UIAutomation在iPhone.I有一個登錄屏幕。在我的登錄屏幕有兩個文本框和登錄按鈕。我需要提供一個具有以下目的的腳本。UIAutomation在ios

腳本應該,

  • 輸入正確的用戶名&密碼,並斷言,用戶被引導到出租車附近的頁面
  • 輸入正確的用戶名&錯誤的密碼,並斷言用戶按預期顯示警報消息,並且用戶停留在同一頁面上。

任何人都可以幫助我嗎?

+0

我看到你在UIAutomation上有幾個問題,並且已經知道Apple的文檔。這是另一個可能有用的好資源:http://pragprog.com/book/jptios/test-ios-apps-with-ui-automation。這本書目前仍處於測試階段,但我擁有它,非常方便。免責聲明:我知道作者,但是因爲這個原因,我不願意給他的書。此外,過去幾年中還有幾個WWDC視頻和幻燈片討論了UIAutomation。不確定會話號碼。 – stevekohls

回答

1
  1. 打開儀器
  2. 選擇自動化
  3. 頂部選擇具有下拉目標旁邊的[暫停,錄製,錄製一次]
  4. 在左側的腳本部分,選擇添加,然後創建
  5. 點擊記錄按鈕。
  6. 現在點擊並輸入正確的用戶名和密碼。

這應該讓你開始。看看你從哪裏得到。

0

如果有其他人需要這個,這裏是我的腳本。正確的登錄功能將類似。

function wrongSignIn() { 
    // Assume you are on the signin page already 
    var target = UIATarget.localTarget(); 
    var appWindow = target.frontMostApp().mainWindow(); 
    // Assume you name the text fields username/password and they are accessible 
    appWindow.textFields()["username"].setValue("correct username"); 
    appWindow.textFields()["password"].setValue("wrong password"); 
    // Assume you have a button called "Sign in" 
    appWindow.buttons()["Sign in"].tap(); 

    // Probably you need some delay for the UI to appear 
    target.delay(3); 
    var alert = target.frontMostApp().alert(); 
    // Make sure the alert is on screen with right message, and stay on old screen 
    if (alert.checkIsValid() && alert.name() == "Wrong password!" 
          && appWindow.name() == "Sign in") { 
     UIALogger.logPass("Pass the wrong signin test."); 
    } else { 
     UIALogger.logFail("Fail the wrong signin test."); 
    } 
} 
0

我將其更改爲

appWindow.secureTextFields()[ 「密碼」]的setValue( 「密碼錯誤」)。

正如Roderic解釋的,您也可以記錄腳本並保存以備後用。