-
-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(user-feedback): ui tests to display form, submit, cancel #4536
base: main
Are you sure you want to change the base?
Changes from 15 commits
508d736
2144d8f
114a2f5
214fa41
b2b1eba
78689e1
b88e5f0
4d611fb
06dbae0
82d63df
ed478f5
f24bd66
9b41727
c26038e
7b084a4
71a2c54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
//swiftlint:disable todo | ||
|
||
import XCTest | ||
|
||
class UserFeedbackUITests: BaseUITest { | ||
override var automaticallyLaunchAndTerminateApp: Bool { false } | ||
|
||
override func setUp() { | ||
super.setUp() | ||
app.launchArguments.append(contentsOf: [ | ||
"--io.sentry.iOS-Swift.auto-inject-user-feedback-widget", | ||
"--io.sentry.iOS-Swift.user-feedback.all-defaults" | ||
]) | ||
launchApp() | ||
} | ||
|
||
func testSubmitFullyFilledForm() throws { | ||
let widgetButton: XCUIElement = app.staticTexts["Report a Bug"] | ||
widgetButton.tap() | ||
|
||
let nameField: XCUIElement = app.textFields["Your Name"] | ||
nameField.tap() | ||
nameField.typeText("Andrew") | ||
|
||
let emailField: XCUIElement = app.textFields["[email protected]"] | ||
emailField.tap() | ||
emailField.typeText("[email protected]") | ||
|
||
let messageTextView: XCUIElement = app.textViews["What's the bug? What did you expect?"] | ||
messageTextView.tap() | ||
messageTextView.typeText("UITest user feedback") | ||
|
||
app.staticTexts["Send Bug Report"].tap() | ||
|
||
// displaying the form again ensures the widget button still works afterwards; also assert that the fields are in their default state to ensure the entered data is not persisted between displays | ||
|
||
widgetButton.tap() | ||
|
||
// the placeholder text is returned for XCUIElement.value | ||
XCTAssertEqual(try XCTUnwrap(nameField.value as? String), "Your Name") | ||
XCTAssertEqual(try XCTUnwrap(emailField.value as? String), "[email protected]") | ||
|
||
// the UITextView doesn't hav a placeholder, it's a label on top of it. so it is actually empty | ||
XCTAssertEqual(try XCTUnwrap(messageTextView.value as? String), "") | ||
} | ||
|
||
func testSubmitWithNoFieldsFilled() throws { | ||
throw XCTSkip("Needs error state implementation") | ||
|
||
let widgetButton: XCUIElement = app.staticTexts["Report a Bug"] | ||
widgetButton.tap() | ||
|
||
app.staticTexts["Send Bug Report"].tap() | ||
|
||
// TODO: need to implement some kind of error dialog and then assert for it | ||
} | ||
Comment on lines
+47
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's implemented in #4544 |
||
|
||
func testSubmitWithOnlyRequiredFieldsFilled() { | ||
let widgetButton: XCUIElement = app.staticTexts["Report a Bug"] | ||
widgetButton.tap() | ||
|
||
let messageTextView: XCUIElement = app.textViews["What's the bug? What did you expect?"] | ||
messageTextView.tap() | ||
messageTextView.typeText("UITest user feedback") | ||
|
||
app.staticTexts["Send Bug Report"].tap() | ||
|
||
XCTAssert(widgetButton.waitForExistence(timeout: 1)) | ||
} | ||
|
||
func testSubmitOnlyWithOptionalFieldsFilled() throws { | ||
throw XCTSkip("Needs error state implementation") | ||
|
||
let widgetButton: XCUIElement = app.staticTexts["Report a Bug"] | ||
widgetButton.tap() | ||
|
||
let nameField: XCUIElement = app.textFields["Your Name"] | ||
nameField.tap() | ||
nameField.typeText("Andrew") | ||
|
||
let emailField: XCUIElement = app.textFields["[email protected]"] | ||
emailField.tap() | ||
emailField.typeText("[email protected]") | ||
|
||
app.staticTexts["Send Bug Report"].tap() | ||
|
||
// TODO: need to implement some kind of error dialog and then assert for it | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't do it until validation and error states are implemented in #4544 |
||
} | ||
|
||
func testCancelFromFormByButton() { | ||
let widgetButton: XCUIElement = app.staticTexts["Report a Bug"] | ||
|
||
widgetButton.tap() | ||
|
||
// fill out the fields; we'll assert later that the entered data does not reappear on subsequent displays | ||
let nameField: XCUIElement = app.textFields["Your Name"] | ||
nameField.tap() | ||
nameField.typeText("Andrew") | ||
|
||
let emailField: XCUIElement = app.textFields["[email protected]"] | ||
emailField.tap() | ||
emailField.typeText("[email protected]") | ||
|
||
let messageTextView: XCUIElement = app.textViews["What's the bug? What did you expect?"] | ||
messageTextView.tap() | ||
messageTextView.typeText("UITest user feedback") | ||
|
||
let cancelButton: XCUIElement = app.staticTexts["Cancel"] | ||
cancelButton.tap() | ||
|
||
// displaying the form again ensures the widget button still works afterwards; also assert that the fields are in their default state to ensure the entered data is not persisted between displays | ||
|
||
widgetButton.tap() | ||
|
||
// the placeholder text is returned for XCUIElement.value | ||
XCTAssertEqual(try XCTUnwrap(nameField.value as? String), "Your Name") | ||
XCTAssertEqual(try XCTUnwrap(emailField.value as? String), "[email protected]") | ||
|
||
// the UITextView doesn't hav a placeholder, it's a label on top of it. so it is actually empty | ||
XCTAssertEqual(try XCTUnwrap(messageTextView.value as? String), "") | ||
} | ||
|
||
func testCancelFromFormBySwipeDown() { | ||
let widgetButton: XCUIElement = app.staticTexts["Report a Bug"] | ||
|
||
widgetButton.tap() | ||
|
||
// fill out the fields; we'll assert later that the entered data does not reappear on subsequent displays | ||
let nameField: XCUIElement = app.textFields["Your Name"] | ||
nameField.tap() | ||
nameField.typeText("Andrew") | ||
|
||
let emailField: XCUIElement = app.textFields["[email protected]"] | ||
emailField.tap() | ||
emailField.typeText("[email protected]") | ||
|
||
let messageTextView: XCUIElement = app.textViews["What's the bug? What did you expect?"] | ||
messageTextView.tap() | ||
messageTextView.typeText("UITest user feedback") | ||
|
||
// the cancel gesture | ||
app.swipeDown(velocity: .fast) | ||
|
||
// displaying the form again ensures the widget button still works afterwards; also assert that the fields are in their default state to ensure the entered data is not persisted between displays | ||
|
||
XCTAssert(widgetButton.waitForExistence(timeout: 1)) | ||
widgetButton.tap() | ||
|
||
// the placeholder text is returned for XCUIElement.value | ||
XCTAssertEqual(try XCTUnwrap(nameField.value as? String), "Your Name") | ||
XCTAssertEqual(try XCTUnwrap(emailField.value as? String), "[email protected]") | ||
|
||
// the UITextView doesn't hav a placeholder, it's a label on top of it. so it is actually empty | ||
XCTAssertEqual(try XCTUnwrap(messageTextView.value as? String), "") | ||
} | ||
} | ||
|
||
//swiftlint:enable todo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m
: Is there any reason we can't use accessibility identifiers to find the button? These usually don't change that often, and they also work when you add localization, so it makes the test less brittle.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair