加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 如何在Xcode中编写覆盖Facebook登录的UI测试?

发布时间:2020-12-14 17:51:51 所属栏目:百科 来源:网络整理
导读:我想在 Xcode中编写一个UI测试,覆盖 FBDSKLoginKit 的登录. 但是,Facebook iOS SDK uses SFSafariViewController 提交给用户以便对她进行身份验证,不幸的是,there’s no way how to interact with SFSafariViewController in UI tests in Xcode 7. 任何想法
我想在 Xcode中编写一个UI测试,覆盖 FBDSKLoginKit的登录.

但是,Facebook iOS SDK uses SFSafariViewController提交给用户以便对她进行身份验证,不幸的是,there’s no way how to interact with SFSafariViewController in UI tests in Xcode 7.

任何想法如何测试Facebook登录而不与SFSafariViewController交互?

解决方法

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()
    }
}

}

经过测试和验证,效果很好!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读