Testing UIWebView with Xcode UI Testing(使用 Xcode UI 测试测试 UIWebView)
问题描述
我正在使用来自 XCTest Framework 的新 Xcode UI 测试 和 Xcode 7 GM.我有一个带有简单 UIWebView 的应用程序(它只是一个导航控制器 + 带有 Web 视图和按钮的视图控制器),我想检查以下场景:
I'm using new Xcode UI Testing from XCTest Framework with the Xcode 7 GM. I've got an app with simple UIWebView (it's just a navigation controller + view controller with web view and button) and I want to check following scenario:
- 网页视图加载页面
www.example.com - 用户点击按钮
- Web View 加载一些带有 URL 的页面:
www.example2.com
我想在按下按钮后检查 UIWebView 中加载了哪个页面.现在可以通过 UI 测试实现吗?
I want to check which page is loaded in UIWebView after pressing button. Is this possible with UI Testing right now?
实际上我得到了这样的网络视图:
Actually I'm getting web view like this:
let app:XCUIApplication = XCUIApplication()
let webViewQury:XCUIElementQuery = app.descendantsMatchingType(.WebView)
let webView = webViewQury.elementAtIndex(0)
推荐答案
您将无法告诉 哪个 页面被加载,就像显示的实际 URL 一样.但是,您可以检查断言内容是否在屏幕上.UI 测试为 XCUIElementQuery" rel="noreferrer">链接对 UIWebView 和 WKWebView 都有效.
You won't be able to tell which page is loaded, as in the actual URL that is being displayed. You can, however, check assert content is on the screen. UI Testing provides a XCUIElementQuery for links that works great with both UIWebView and WKWebView.
请记住,页面不会同步加载,因此您必须 等待实际元素出现.
Keep in mind that a page doesn't load synchronously, so you will have to 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()
还有一个 工作测试主机 与这两个链接一起使用如果你想深入研究代码.
There is also a working test host that goes along with the two links if you want to dig into the code.
这篇关于使用 Xcode UI 测试测试 UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Xcode UI 测试测试 UIWebView
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
