作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想在 Xcode 中编写一个 UI 测试,涵盖使用 FBDSKLoginKit
登录.
然而,Facebook iOS SDK uses SFSafariViewController
呈现给用户以验证她的身份,不幸的是,there's no way how to interact with SFSafariViewController
in UI tests in Xcode 7 .
有什么想法可以在不与 SFSafariViewController
交互的情况下测试 facebook 登录吗?
最佳答案
Swift 3 Xcode 8 解决方案
func testFacebookLogin() {
let app = XCUIApplication()
// set up an expectation predicate to test whether elements exist
let exists = NSPredicate(format: "exists == true")
// as soon as your sign in button shows up, press it
let facebookSignInButton = app.buttons["Login With Facebook"]
expectation(for: exists, evaluatedWith: facebookSignInButton, handler: nil)
facebookSignInButton.tap()
// wait for the "Confirm" title at the top of facebook's sign in screen
let confirmTitle = app.staticTexts["Confirm"]
expectation(for: exists, evaluatedWith: confirmTitle, handler: nil)
// create a reference to the button through the webView and press it
let webView = app.descendants(matching: .webView)
webView.buttons["OK"].tap()
// wait for your app to return and test for expected behavior here
self.waitForExpectations(timeout: 10, handler: nil)
}
扩展名:
extension XCUIElement {
func forceTap() {
if self.isHittable {
self.tap()
} else {
let coordinate: XCUICoordinate = self.coordinate(withNormalizedOffset: .zero)
coordinate.tap()
}
}
}
经过测试和验证,效果很好!
关于ios - 如何在 Xcode 中编写涵盖使用 Facebook 登录的 UI 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36770289/
我是一名优秀的程序员,十分优秀!