-
Notifications
You must be signed in to change notification settings - Fork 149
Add UI tests for high priority issues #819
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
Changes from all commits
3718e0a
42c7333
75c88f5
85422c0
0f9fde1
55398ef
84d4b27
d71268e
fbfb2f8
eebf314
aa209f9
818936c
01c6ba2
0f557ab
f822bc4
69b96f7
ee772cf
7496657
7e749be
cf32c02
19d2314
1563123
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,128 @@ | ||
| import XCTest | ||
|
|
||
| class HighPriorityIssuesTests: XCTestCase { | ||
|
|
||
| private var app: XCUIApplication! | ||
| private var richTextField: XCUIElement! | ||
|
|
||
| override func setUp() { | ||
| super.setUp() | ||
|
|
||
| // In UI tests it is usually best to stop immediately when a failure occurs. | ||
| continueAfterFailure = false | ||
| // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. | ||
| XCUIDevice.shared().orientation = .portrait | ||
| app = XCUIApplication() | ||
| app.launch() | ||
|
|
||
| let blogsPage = BlogsPage.init(appInstance: app) | ||
| blogsPage.gotoEmptyDemo() | ||
| } | ||
|
|
||
| override func tearDown() { | ||
| // Put teardown code here. This method is called after the invocation of each test method in the class. | ||
| super.tearDown() | ||
| } | ||
|
|
||
| // Github issue https://github.com/wordpress-mobile/AztecEditor-iOS/issues/385 | ||
| func testLongTitle() { | ||
| // Title line height is about 22px, so it might be useing for comparing the height difference should make it precise. | ||
| // But may be fragile due to different font sizes etc | ||
| let titleLineHeight = 22 | ||
| let titleTextView = app.textViews[elementStringIDs.titleTextField] | ||
| titleTextView.tap() | ||
| let oneLineTitleHeight = Int(titleTextView.frame.height) | ||
|
|
||
| // TODO: Move it into EditorPage | ||
| if (app.windows.element(boundBy: 0).horizontalSizeClass == .compact || app.windows.element(boundBy: 0).verticalSizeClass == .compact) { | ||
| titleTextView.typeText("very very very very very very long title in a galaxy not so far away") | ||
| } else { | ||
| titleTextView.typeText("very very very very very very long title in a galaxy not so far away very very very very very very long title in a galaxy not so far away") | ||
| } | ||
|
|
||
| let twoLineTitleHeight = Int(titleTextView.frame.height) | ||
| XCTAssert(twoLineTitleHeight - oneLineTitleHeight == titleLineHeight ) // XCTAssert(oneLineTitleHeight < twoLineTitleHeight) | ||
| } | ||
|
|
||
| // Github issue https://github.com/wordpress-mobile/AztecEditor-iOS/issues/675 | ||
| func testInfiniteLoopOnAssetDownload() { | ||
| switchContentView() | ||
| enterTextInHTML(text: "<img src=\"https://someinvalid.url/with-an-invalid-resource\">") | ||
| switchContentView() | ||
| gotoRootPage() | ||
|
|
||
| let editorDemoButton = app.tables.staticTexts[elementStringIDs.emptyDemo] | ||
| XCTAssert(editorDemoButton.exists, "Editor button not hittable. Are you on the right page?") | ||
| } | ||
|
|
||
| // Github issue https://github.com/wordpress-mobile/AztecEditor-iOS/issues/465 | ||
| func testTypeAfterInvalidHTML() { | ||
| switchContentView() | ||
| enterTextInHTML(text: "<qaz!>") | ||
| switchContentView() | ||
|
|
||
| let field = app.textViews[elementStringIDs.richTextField] | ||
| // Some magic to move caret to end of the text | ||
| let vector = CGVector(dx:field.frame.width, dy:field.frame.height - field.frame.minY) | ||
| field.coordinate(withNormalizedOffset:CGVector.zero).withOffset(vector).tap() | ||
| enterTextInField(text: "Some text after invalid HTML tag") | ||
|
|
||
| let text = getHTMLContent() | ||
| XCTAssertEqual(text, "<p><qaz></qaz>Some text after invalid HTML tag</p>") | ||
| } | ||
|
|
||
| // Github issue https://github.com/wordpress-mobile/AztecEditor-iOS/issues/768 | ||
| func testLooseStylesNoContent() { | ||
| let boldButton = app.scrollViews.otherElements.buttons[elementStringIDs.boldButton] | ||
| let italicButton = app.scrollViews.otherElements.buttons[elementStringIDs.italicButton] | ||
|
|
||
| XCTAssert(!boldButton.isSelected && !italicButton.isSelected) | ||
| boldButton.tap() | ||
| italicButton.tap() | ||
|
|
||
| enterTextInField(text: "q") | ||
| let deleteButton = app.keys["delete"] | ||
| deleteButton.tap() | ||
| deleteButton.tap() | ||
| XCTAssert(boldButton.isSelected && italicButton.isSelected) | ||
| } | ||
|
|
||
| // Github issue https://github.com/wordpress-mobile/AztecEditor-iOS/issues/771 | ||
| func testCopyPasteCrash() { | ||
| // gotoRootPage() | ||
| // let blogsPage = BlogsPage.init(appInstance: app) | ||
| // blogsPage.gotoDemo() | ||
|
|
||
| let text = "<h1>Sample HTML content</h1> <p>this is some text that is spread out across several lines but is rendered on a single line in a browser</p> <h2>Character Styles</h2> <p><strong>Bold text</strong><br><em>Italic text</em><br><u>Underlined text</u><br><del>Strikethrough</del><br><span style=\"color: #ff0000\">Colors</span><br><span style=\"text-decoration: underline\">Alternative underline text</span><br><a href=\"http://www.wordpress.com\">I'm a link!</a><br><!--more-->Text after the more break</p> <h2>Lists</h2> <h3>Unordered List:</h3> <ul> <li>One</li> <li>Two</li> <li>Three</li> </ul> <h3>Ordered List:</h3> <ol> <li>One</li> <li>Two</li> <li>Three</li> </ol> <p> <hr> </p>" | ||
|
|
||
| switchContentView() | ||
| // selectAllTextInHTMLField() | ||
| enterTextInHTML(text: text) | ||
|
|
||
| let htmlContentView = app.textViews[elementStringIDs.htmlTextField] | ||
| // let text = htmlContentView.value as! String | ||
|
|
||
| selectAllTextInHTMLField() | ||
| app.menuItems[elementStringIDs.copyButton].tap() | ||
| htmlContentView.swipeUp() | ||
| htmlContentView.swipeUp() | ||
| htmlContentView.swipeUp() | ||
|
|
||
| // determinating where to click to put caret to end of text | ||
| let frame = htmlContentView.frame | ||
| let buttonFrame = app.scrollViews.otherElements.buttons[elementStringIDs.mediaButton].frame.height | ||
| let vector = CGVector(dx: frame.width, dy: frame.height - (buttonFrame + 1)) | ||
|
|
||
| htmlContentView.coordinate(withNormalizedOffset:CGVector.zero).withOffset(vector).tap() | ||
| htmlContentView.typeText("\n\n") | ||
| htmlContentView.tap() | ||
| app.menuItems[elementStringIDs.pasteButton].tap() | ||
|
|
||
| sleep(3) // to make sure everything is updated | ||
| let newText = htmlContentView.value as! String | ||
|
|
||
| XCTAssertEqual(newText, text + "\n\n" + text) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import Foundation | ||
| import XCTest | ||
|
|
||
| class BasePage { | ||
| var app: XCUIApplication! | ||
| private var expectedElement: XCUIElement! | ||
| var waitTimeout: Double! | ||
|
|
||
| init(appInstance: XCUIApplication, element: XCUIElement) { | ||
| app = appInstance | ||
| expectedElement = element | ||
| waitTimeout = 20 | ||
| waitForPage() | ||
| } | ||
|
|
||
| func waitForPage() { | ||
| expectedElement.waitForExistence(timeout: waitTimeout) | ||
| } | ||
|
|
||
| func isLoaded() -> Bool { | ||
| return expectedElement.exists | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import Foundation | ||
| import XCTest | ||
|
|
||
|
|
||
| class BlogsPage: BasePage { | ||
|
|
||
| init(appInstance: XCUIApplication) { | ||
| let expectedElement = appInstance.tables.staticTexts[elementStringIDs.emptyDemo] | ||
| super.init(appInstance: appInstance, element: expectedElement) | ||
| } | ||
|
|
||
| func gotoEmptyDemo() { | ||
| app.staticTexts[elementStringIDs.emptyDemo].tap() | ||
|
|
||
| showOptionsStrip() | ||
| } | ||
|
|
||
| func gotoDemo() { | ||
| app.staticTexts[elementStringIDs.demo].tap() | ||
|
|
||
| showOptionsStrip() | ||
| } | ||
|
|
||
| func showOptionsStrip() -> Void { | ||
| app.textViews[elementStringIDs.richTextField].tap() | ||
| expandOptionsSctrip() | ||
| } | ||
|
|
||
| func expandOptionsSctrip() -> Void { | ||
|
Contributor
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. On larger devices (e.g. iPad Pro) this function is toggling the extended toolbar open/closed rather than always expanding it. We should check the status of the toolbar before tapping — otherwise the expanded toolbar is toggled off in every other test. If it isn't currently possible to check the status, we should open an issue to address that as it's also an accessibility issue. (VoiceOver users need to be aware of the toolbar status so they can expand it if needed, too.)
Contributor
Author
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. Created the ticket for that: #837
Contributor
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. For now, how about checking to see if the HTML button exists before toggling the extended toolbar? I'm thinking of something like this: That way we don't break the existing tests on iPads, and we can improve the check later once that issue is resolved.
Contributor
Author
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. That's nice solution, thanks! |
||
| let expandButton = app.children(matching: .window).element(boundBy: 1).children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .button).element | ||
| let htmlButton = app.scrollViews.otherElements.buttons[elementStringIDs.sourcecodeButton] | ||
|
|
||
| if expandButton.exists && expandButton.isHittable && !htmlButton.exists { | ||
| expandButton.tap() | ||
| } | ||
| } | ||
| } | ||
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.
This test is still failing on larger devices (e.g. iPad Pro). If there isn't a way to get it to work for both large and small devices, could we restrict it to only run when testing smaller devices?
Uh oh!
There was an error while loading. Please reload this page.
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.
I don't think its possible to tag which tests to run with current test runner (as it's done in wp-e2e-tests). The only solution I see is to move such tests to separate files and run them only for small screens. And in general, I think it would be better to address this issue once we'll have them running on multiple devices. I've created the ticket for that: #839
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.
I looked around and found these hints and tips that include conditional code for testing on iPhone v. iPad. I updated the example shown there and got it to work in this test like this: