I’m attempting to put in writing a UITest for SwiftUI hyperlink that I’ve arrange within the following method:
var physique: some View {
privacyPolicyLink
}
non-public func privacyPolicyLink(with url: URL) -> Textual content {
Textual content(.init("[privacy policy]((url))"))
.underline()
.applyStyling() // applies fonts and foreground shade
}
non-public var privacyPolicyURLView: Textual content {
textView(withDisplayText: "For extra data, please see our )
+ privacyPolicyLink(with: url)
+ textView(withDisplayText: ".")
}
non-public func textView(withDisplayText textual content: String) -> Textual content {
Textual content(textual content)
.applyStyling() // applies fonts and foreground shade
}
This renders wonderful and works as anticipated:
Nevertheless, I’m struggling to discover a strategy to faucet on the hyperlink in a UITest.
What I attempted:
-
Placing the three views in an HStack as an alternative of concatenating the textual content view. This does work, nonetheless, I am unable to go along with this method because the spacing turns into bizarre when the gadget font will increase and I must deal with it as a sentence moderately than 3 completely different components.
-
I attempted including an accessibilityIdentifier to the whole
Textual content
view after which tried discovering a hyperlink inside it
// Within the view
privacyPolicyURLView
.accessibilityIdentifier("privacyPolicyLabel")
// Within the take a look at
let privacyPolicyLabel: XCUIElementQuery = elementQuery(kind: .staticText, byIdentifier: "privacyPolicyLabel")
let privacyPolicyLink = privacyPolicyLabel.ingredient.hyperlinks["privacy policy"].firstMatch
privacyPolicyLink.faucet()
I get an error that No matches discovered.
I do one thing much like get hyperlinks through the app
let privacyPolicyLink = app.hyperlinks["privacy policy"].firstMatch
privacyPolicyLink.faucet()
I get an identical error Didn't faucet "privateness coverage" Hyperlink: No matches discovered for first question match sequence: Descendants matching kind Hyperlink -> Components matching predicate '"privateness coverage" IN identifiers', given enter App ingredient pid: 19868
Have you learnt any strategy to faucet the particular hyperlink inside a SwiftUI textual content view in a UITest ?