简体   繁体   English

在 Swift 的 UITests 中关闭应用内 AppStore 评级

[英]Dismiss In-App AppStore rating in UITests in Swift

Hello dear developers,你好亲爱的开发者,

I'm currently stuck due to a problem with In-App AppStore rating (SKStoreReviewController).由于应用内 AppStore 评级 (SKStoreReviewController) 的问题,我目前陷入困境。 Here is the situation, I've a screen "FirstScreen" with a button.这是情况,我有一个带有按钮的屏幕“FirstScreen” When I tap on it, I'm going to the next screen "SecondScreen" and an in app alert for AppStore rating pop over.当我点击它时,我将进入下一个屏幕“SecondScreen” ,并弹出 AppStore 评级的应用程序内警报。

I'm trying to find a solution for my UITests in order to dismiss this Alert.我正在尝试为我的 UITests 找到解决方案以消除此警报。 I tried many solutions but I'm looking for one which do not depends on string (I don't want to localize the content of this Alert):我尝试了许多解决方案,但我正在寻找一种不依赖于字符串的解决方案(我不想本地化此警报的内容):

override func setUp() {
    app = XCUIApplication()
    app.launch()

    addUIInterruptionMonitor(withDescription: "System Dialog") { (alert) -> Bool in
        let allowButton = alert.buttons.element(boundBy: 1)
        if allowButton.exists {
            allowButton.tap()
        }
    }
}

I also tried to add an interaction ("app.swipeUp()") when I'm coming to "SecondScreen" in order to trigger this handler.当我来到“SecondScreen”时,我还尝试添加交互(“app.swipeUp()”)以触发此处理程序。

I've also tried another solution, as I know when this alert will be triggered:我还尝试了另一种解决方案,因为我知道何时会触发此警报:

let dismissButton = XCUIApplication(bundleIdentifier: "com.apple.springboard").buttons.element(boundBy: 1)
if dismissButton.exists {
    dismissButton.tap()
}

No one worked and I'm still stuck:( Does anybody found a solution in order to dismiss this alert?没有人工作,我仍然被困住:(有没有人找到解决方案来消除这个警报?

Thanks谢谢

Swiping up doesn't work but ironically swiping down does.向上滑动不起作用,但具有讽刺意味的是向下滑动。 Here is a very simplistic example这是一个非常简单的例子

import UIKit
import StoreKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) {
            SKStoreReviewController.requestReview()
        }
    }

}
import XCTest

class UITests: XCTestCase {

    override func setUp() {
        continueAfterFailure = false
    }

    func test() {
        let app = XCUIApplication()
        app.launch()

        sleep(5)
        app.swipeDown()
        sleep(3)
    }
}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM