gpt4 book ai didi

uiwebview - 使用 Xcode UI 测试测试 UIWebView

转载 作者:行者123 更新时间:2023-12-04 01:59:00 28 4
gpt4 key购买 nike

我正在使用新的 Xcode UI Testing来自 XCTest FrameworkXcode 7 GM .我有一个带有简单 UIWebView 的应用程序(它只是一个带有 web View 和按钮的导航 Controller + View Controller ),我想检查以下场景:

  • Web View 加载页面 www.example.com
  • 用户点击按钮
  • Web View 加载一些带有 URL 的页面:www.example2.com

  • 我想检查按下按钮后在 UIWebView 中加载了哪个页面。现在可以使用 UI 测试吗?

    实际上我得到这样的网络 View :
    let app:XCUIApplication = XCUIApplication()
    let webViewQury:XCUIElementQuery = app.descendantsMatchingType(.WebView)
    let webView = webViewQury.elementAtIndex(0)

    最佳答案

    您将无法判断加载了哪个页面,就像在显示的实际 URL 中一样。但是,您可以检查断言内容是否在屏幕上。 UI 测试提供了一个 XCUIElementQuerylinks that works great with both UIWebView and WKWebView .

    请记住,页面不会同步加载,因此您必须wait for the actual elements to appear .

    let app = XCUIApplication()
    app.launch()

    app.buttons["Go to Google.com"].tap()

    let about = self.app.staticTexts["About"]
    let exists = NSPredicate(format: "exists == 1")
    expectationForPredicate(exists, evaluatedWithObject: about, handler: nil)

    waitForExpectationsWithTimeout(5, handler: nil)
    XCTAssert(about.exists)

    XCTAssert(app.staticTexts["Google Search"].exists)
    app.links["I'm Feeling Lukcy"].tap()

    还有一个 working test host如果您想深入了解代码,请与两个链接一起使用。

    关于uiwebview - 使用 Xcode UI 测试测试 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32623869/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com