Dismiss In-App AppStore rating in UITests in Swift

414 Views Asked by At

Hello dear developers,

I'm currently stuck due to a problem with In-App AppStore rating (SKStoreReviewController). Here is the situation, I've a screen "FirstScreen" with a button. When I tap on it, I'm going to the next screen "SecondScreen" and an in app alert for AppStore rating pop over.

I'm trying to find a solution for my UITests in order to dismiss this Alert. 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.

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

1

There are 1 best solutions below

1
On

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

enter image description here