Apa*_*pan 11 uiwebview xctest ios9 xcode-ui-testing
我使用的是新Xcode UI Testing的XCTest Framework与Xcode 7 GM.我有一个简单的UIWebView应用程序(它只是一个导航控制器+带有Web视图和按钮的视图控制器),我想检查以下场景:
www.example.com www.example2.com我想在按下按钮后检查UIWebView中加载了哪个页面.这是否可以通过UI测试立即实现?
其实我得到这样的网页视图:
let app:XCUIApplication = XCUIApplication()
let webViewQury:XCUIElementQuery = app.descendantsMatchingType(.WebView)
let webView = webViewQury.elementAtIndex(0)
Run Code Online (Sandbox Code Playgroud)
Joe*_*tti 11
你将不能够告诉它加载页面时,在正在显示实际的URL.但是,您可以在屏幕上检查断言内容.UI测试提供了一个XCUIElementQuery为那伟大工程具有两个链接UIWebView和WKWebView.
请记住,页面不会同步加载,因此您必须等待显示实际元素.
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()
Run Code Online (Sandbox Code Playgroud)
如果你想深入研究代码,还有一个工作测试主机与两个链接一起使用.
| 归档时间: |
|
| 查看次数: |
12469 次 |
| 最近记录: |