iOS Swift UI测试点击警报按钮

时间:2019-10-02 22:11:10

标签: ios swift salesforce xcode-ui-testing

当试图点击警报按钮时,一个很小的UI测试失败了,我缺​​少什么步骤?

我正在尝试使用以下代码(从recording my steps获取)点击下面显示的警报中的“继续”按钮。

[:find ?artist-name ?release-name
 :keys artist release
 :where [?release :release/name ?release-name]
 [?release :release/artists ?artist]
 [?artist :artist/name ?artist-name]]

运行测试时,它在最后一行(即let app = XCUIApplication() let salesforceloginbuttonButton = app.buttons["salesforceLoginButton"] salesforceloginbuttonButton.tap() let posWantsToUseSalesforceComToSignInAlert = app.alerts["“POS” Wants to Use “salesforce.com” to Sign In"] let continueButton = posWantsToUseSalesforceComToSignInAlert.buttons["Continue"] continueButton.tap() )失败,并显示错误continueButton.tap()

注意:

  • 我已经尝试等待几秒钟,然后点击“继续”按钮,结果相同。
  • 运行测试后,点击No matches found for Find: Descendants matching type Alert from input后,应用将启动并显示警报

Salesforce Login Alert

1 个答案:

答案 0 :(得分:0)

我认为您的警报无法识别,可能是因为双引号

您可以尝试像这样显式设置警报的标识符:

let alert = UIAlertController(title: "Alert", message: "msg", preferredStyle: .alert)
alert.view.accessibilityIdentifier = "myAlert"

然后在您的测试中:

let alert = app.alerts["myAlert"]
let button = alert.buttons["Continue"]
button.tap()