gpt4 book ai didi

ios - 如何在 Xcode 中编写涵盖使用 Facebook 登录的 UI 测试?

转载 作者:可可西里 更新时间:2023-11-01 04:41:02 24 4
gpt4 key购买 nike

我想在 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/

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