diff --git a/.github/workflows/ui_tests.yml b/.github/workflows/ui_tests.yml index 5981843bef..193d0a67cf 100644 --- a/.github/workflows/ui_tests.yml +++ b/.github/workflows/ui_tests.yml @@ -61,6 +61,14 @@ jobs: - name: Select Xcode run: sudo xcode-select -s /Applications/Xcode_$(<.xcode-version).app/Contents/Developer + - name: Write me a test file + run: | + echo ' + Lorem Ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac sem nisi. Cras fermentum mi vitae turpis efficitur malesuada. Donec eget maxima ligula, et tincidunt sapien. Suspendisse posuere diam maxima, dignissim ex at, fringilla elit. Maecenas enim tellus, ornare non pretium a, sodales nec lectus. Vestibulum quis augue orci. Donec eget mi sed magna consequat auctor a a nulla. Etiam condimentum, neque at congue semper, arcu sem commodo tellus, venenatis finibus ex magna vitae erat. Nunc non enim sit amet mi posuere egestas. Donec nibh nisl, pretium sit amet aliquet, porta id nibh. Pellentesque ullamcorper mauris quam, semper hendrerit mi dictum non. Nullam pulvinar, nulla a maximus egestas, velit mi volutpat neque, vitae placerat eros sapien vitae tellus. Pellentesque malesuada accumsan dolor, ut feugiat enim. Curabitur nunc quam, maximus venenatis augue vel, accumsan eros.

+ +

Donec consequat ultrices ante non maximus. Quisque eu semper diam. Nunc ullamcorper eget ex id luctus. Duis metus ex, dapibus sit amet vehicula eget, rhoncus eget lacus. Nulla maximus quis turpis vel pulvinar. Duis neque ligula, tristique et diam ut, fringilla sagittis arcu. Vestibulum suscipit semper lectus, quis placerat ex euismod eu. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae;

+ +

Maecenas odio orci, eleifend et ipsum nec, interdum dictum turpis. Nunc nec velit diam. Sed nisl risus, imperdiet sit amet tempor ut, laoreet sed lorem. Aenean egestas ullamcorper sem. Sed accumsan vehicula augue, vitae tempor augue tincidunt id. Morbi ullamcorper posuere lacus id tempus. Ut vel tincidunt quam, quis consectetur velit. Mauris id lorem vitae odio consectetur vehicula. Vestibulum viverra scelerisque porta. Vestibulum eu consequat urna. Etiam dignissim ullamcorper faucibus.

' > /Users/runner/Documents/lorem_ipsum.html - name: Build and run UI Testing run: | diff --git a/UITests/FindInPageTests.swift b/UITests/FindInPageTests.swift index 84c713d91a..ffe4151a21 100644 --- a/UITests/FindInPageTests.swift +++ b/UITests/FindInPageTests.swift @@ -51,7 +51,7 @@ class FindInPageTests: XCTestCase { addressBarTextField.waitForExistence(timeout: elementExistenceTimeout), "The Address Bar text field did not exist when it was expected." ) - addressBarTextField.typeText("\(Self.loremIpsumFileURL.absoluteString)\r") + addressBarTextField.typeText("file:///Users/runner/Documents/lorem_ipsum.html") XCTAssertTrue( loremIpsumWebView.waitForExistence(timeout: elementExistenceTimeout), "Local \"Lorem Ipsum\" web page didn't load with the expected title in a reasonable timeframe." @@ -64,367 +64,6 @@ class FindInPageTests: XCTestCase { "After invoking \"Find in Page\" with command-f, the elements of the \"Find in Page\" interface should exist." ) } - - func test_findInPage_canBeOpenedWithMenuBarItem() throws { - XCTAssertTrue( - addressBarTextField.waitForExistence(timeout: elementExistenceTimeout), - "The Address Bar text field did not exist when it was expected." - ) - addressBarTextField.typeText("\(Self.loremIpsumFileURL.absoluteString)\r") - XCTAssertTrue( - loremIpsumWebView.waitForExistence(timeout: elementExistenceTimeout), - "Local \"Lorem Ipsum\" web page didn't load with the expected title in a reasonable timeframe." - ) - let findInPageMenuBarItem = app.menuItems["MainMenu.findInPage"] - XCTAssertTrue( - findInPageMenuBarItem.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find \"Find in Page\" main menu bar item in a reasonable timeframe." - ) - - findInPageMenuBarItem.click() - - XCTAssertTrue( - findInPageCloseButton.waitForExistence(timeout: elementExistenceTimeout), - "After invoking \"Find in Page\" via the menu items Edit->Find->\"Find in Page\", the elements of the \"Find in Page\" interface should exist." - ) - } - - func test_findInPage_canBeOpenedWithMoreOptionsMenuItem() throws { - XCTAssertTrue( - addressBarTextField.waitForExistence(timeout: elementExistenceTimeout), - "The Address Bar text field did not exist when it was expected." - ) - addressBarTextField.typeText("\(Self.loremIpsumFileURL.absoluteString)\r") - XCTAssertTrue( - loremIpsumWebView.waitForExistence(timeout: elementExistenceTimeout), - "Local \"Lorem Ipsum\" web page didn't load with the expected title in a reasonable timeframe." - ) - let optionsButton = app.windows.buttons["NavigationBarViewController.optionsButton"] - XCTAssertTrue(optionsButton.waitForExistence(timeout: elementExistenceTimeout), "Couldn't find options item in a reasonable timeframe.") - optionsButton.click() - - let findInPageMoreOptionsMenuItem = app.menuItems["MoreOptionsMenu.findInPage"] - XCTAssertTrue( - findInPageMoreOptionsMenuItem.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find More Options \"Find in Page\" menu item in a reasonable timeframe." - ) - findInPageMoreOptionsMenuItem.click() - - XCTAssertTrue( - findInPageCloseButton.waitForExistence(timeout: elementExistenceTimeout), - "After invoking \"Find in Page\" via the More Options \"Find in Page\" menu item, the elements of the \"Find in Page\" interface should exist." - ) - } - - func test_findInPage_canBeClosedWithEscape() throws { - XCTAssertTrue( - addressBarTextField.waitForExistence(timeout: elementExistenceTimeout), - "The Address Bar text field did not exist when it was expected." - ) - addressBarTextField.typeText("\(Self.loremIpsumFileURL.absoluteString)\r") - XCTAssertTrue( - loremIpsumWebView.waitForExistence(timeout: elementExistenceTimeout), - "Local \"Lorem Ipsum\" web page didn't load with the expected title in a reasonable timeframe." - ) - app.typeKey("f", modifierFlags: .command) - XCTAssertTrue( - findInPageCloseButton.waitForExistence(timeout: elementExistenceTimeout), - "After invoking \"Find in Page\" with command-f, the elements of the \"Find in Page\" interface should exist." - ) - - app.typeKey(.escape, modifierFlags: []) - - XCTAssertTrue( - findInPageCloseButton.waitForNonExistence(timeout: elementExistenceTimeout), - "After closing \"Find in Page\" with escape, the elements of the \"Find in Page\" interface should no longer exist." - ) - } - - func test_findInPage_canBeClosedWithShiftCommandF() throws { - XCTAssertTrue( - addressBarTextField.waitForExistence(timeout: elementExistenceTimeout), - "The Address Bar text field did not exist when it was expected." - ) - addressBarTextField.typeText("\(Self.loremIpsumFileURL.absoluteString)\r") - XCTAssertTrue( - loremIpsumWebView.waitForExistence(timeout: elementExistenceTimeout), - "Local \"Lorem Ipsum\" web page didn't load with the expected title in a reasonable timeframe." - ) - app.typeKey("f", modifierFlags: .command) - XCTAssertTrue( - findInPageCloseButton.waitForExistence(timeout: elementExistenceTimeout), - "After invoking \"Find in Page\" with command-f, the elements of the \"Find in Page\" interface should exist." - ) - - app.typeKey("f", modifierFlags: [.command, .shift]) - - XCTAssertTrue( - findInPageCloseButton.waitForNonExistence(timeout: elementExistenceTimeout), - "After closing \"Find in Page\" with escape, the elements of the \"Find in Page\" interface should no longer exist." - ) - } - - func test_findInPage_canBeClosedWithHideFindMenuItem() throws { - XCTAssertTrue( - addressBarTextField.waitForExistence(timeout: elementExistenceTimeout), - "The Address Bar text field did not exist when it was expected." - ) - addressBarTextField.typeText("\(Self.loremIpsumFileURL.absoluteString)\r") - XCTAssertTrue( - loremIpsumWebView.waitForExistence(timeout: elementExistenceTimeout), - "Local \"Lorem Ipsum\" web page didn't load with the expected title in a reasonable timeframe." - ) - app.typeKey("f", modifierFlags: .command) - XCTAssertTrue( - findInPageCloseButton.waitForExistence(timeout: elementExistenceTimeout), - "After invoking \"Find in Page\" with command-f, the elements of the \"Find in Page\" interface should exist." - ) - - let findInPageDoneMenuBarItem = app.menuItems["MainMenu.findInPageDone"] - XCTAssertTrue( - findInPageDoneMenuBarItem.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find \"Find in Page\" done main menu item in a reasonable timeframe." - ) - findInPageDoneMenuBarItem.click() - - XCTAssertTrue( - findInPageCloseButton.waitForNonExistence(timeout: elementExistenceTimeout), - "After closing \"Find in Page\" with escape, the elements of the \"Find in Page\" interface should no longer exist." - ) - } - - func test_findInPage_showsCorrectNumberOfOccurrences() throws { - XCTAssertTrue( - addressBarTextField.waitForExistence(timeout: elementExistenceTimeout), - "The Address Bar text field did not exist when it was expected." - ) - addressBarTextField.typeText("\(Self.loremIpsumFileURL.absoluteString)\r") - XCTAssertTrue( - loremIpsumWebView.waitForExistence(timeout: elementExistenceTimeout), - "Local \"Lorem Ipsum\" web page didn't load with the expected title in a reasonable timeframe." - ) - - app.typeKey("f", modifierFlags: .command) - XCTAssertTrue( - findInPageCloseButton.waitForExistence(timeout: elementExistenceTimeout), - "After invoking \"Find in Page\" with command-f, the elements of the \"Find in Page\" interface should exist." - ) - - app.typeText("maximus\r") - let statusField = app.textFields["FindInPageController.statusField"] - XCTAssertTrue( - statusField.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find \"Find in Page\" statusField in a reasonable timeframe." - ) - let statusFieldTextContent = try XCTUnwrap(statusField.value as? String) - XCTAssertEqual(statusFieldTextContent, "1 of 4") // Note: this is not a localized test element, and it should have a localization strategy. - } - - func test_findInPage_showsFocusAndOccurrenceHighlighting() throws { - XCTAssertTrue( - addressBarTextField.waitForExistence(timeout: elementExistenceTimeout), - "The Address Bar text field did not exist when it was expected." - ) - addressBarTextField.typeText("\(Self.loremIpsumFileURL.absoluteString)\r") - XCTAssertTrue( - loremIpsumWebView.waitForExistence(timeout: elementExistenceTimeout), - "Local \"Lorem Ipsum\" web page didn't load with the expected title in a reasonable timeframe." - ) - app.typeKey("f", modifierFlags: .command) - XCTAssertTrue( - findInPageCloseButton.waitForExistence(timeout: elementExistenceTimeout), - "After invoking \"Find in Page\" with command-f, the elements of the \"Find in Page\" interface should exist." - ) - - app.typeText("maximus\r") - let statusField = app.textFields["FindInPageController.statusField"] - XCTAssertTrue( - statusField.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find \"Find in Page\" statusField in a reasonable timeframe." - ) - let statusFieldTextContent = try XCTUnwrap(statusField.value as? String) - // Note: the following is not a localized test element, but it should have a localization strategy. - XCTAssertEqual(statusFieldTextContent, "1 of 4", "Unexpected status field text content after a \"Find in Page\" operation.") - - let webViewWithSelectedWordsScreenshot = loremIpsumWebView.screenshot() - let highlightedPixelsInScreenshot = webViewWithSelectedWordsScreenshot.image.matchingPixels(of: .findHighlightColor) - XCTAssertGreaterThan( - highlightedPixelsInScreenshot.count, - minimumExpectedMatchingPixelsInFindHighlight, - "There are expected to be more than \(minimumExpectedMatchingPixelsInFindHighlight) pixels of NSColor.findHighlightColor in a screenshot of a \"Find in Page\" search where there is a match, but this test found \(highlightedPixelsInScreenshot) matching pixels." - ) - } - - func test_findNext_menuItemGoesToNextOccurrence() throws { - XCTAssertTrue( - addressBarTextField.waitForExistence(timeout: elementExistenceTimeout), - "The Address Bar text field did not exist when it was expected." - ) - addressBarTextField.typeText("\(Self.loremIpsumFileURL.absoluteString)\r") - XCTAssertTrue( - loremIpsumWebView.waitForExistence(timeout: elementExistenceTimeout), - "Local \"Lorem Ipsum\" web page didn't load with the expected title in a reasonable timeframe." - ) - app.typeKey("f", modifierFlags: .command) - XCTAssertTrue( - findInPageCloseButton.waitForExistence(timeout: elementExistenceTimeout), - "After invoking \"Find in Page\" with command-f, the elements of the \"Find in Page\" interface should exist." - ) - app.typeText("maximus\r") - let statusField = app.textFields["FindInPageController.statusField"] - XCTAssertTrue( - statusField.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find \"Find in Page\" statusField in a reasonable timeframe." - ) - let statusFieldTextContent = try XCTUnwrap(statusField.value as? String) - // Note: the following is not a localized test element, but it should have a localization strategy. - XCTAssertEqual(statusFieldTextContent, "1 of 4", "Unexpected status field text content after a \"Find in Page\" operation.") - let findInPageScreenshot = loremIpsumWebView.screenshot() - let highlightedPixelsInFindScreenshot = findInPageScreenshot.image.matchingPixels(of: .findHighlightColor) - let findHighlightPoints = Set(highlightedPixelsInFindScreenshot.map { $0.point }) // Coordinates of highlighted pixels in the find screenshot - - let findNextMenuBarItem = app.menuItems["MainMenu.findNext"] - XCTAssertTrue( - findNextMenuBarItem.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find \"Find Next\" main menu bar item in a reasonable timeframe." - ) - findNextMenuBarItem.click() - let updatedStatusField = app.textFields["FindInPageController.statusField"] - let updatedStatusFieldTextContent = updatedStatusField.value as! String - XCTAssertTrue( - updatedStatusField.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find the updated \"Find in Page\" statusField in a reasonable timeframe." - ) - XCTAssertEqual(updatedStatusFieldTextContent, "2 of 4", "Unexpected status field text content after a \"Find Next\" operation.") - let findNextScreenshot = loremIpsumWebView.screenshot() - let highlightedPixelsInFindNextScreenshot = Set(findNextScreenshot.image - .matchingPixels(of: .findHighlightColor)) // Coordinates of highlighted pixels in the find next screenshot - let findNextHighlightPoints = highlightedPixelsInFindNextScreenshot.map { $0.point } - let pixelSetIntersection = findHighlightPoints - .intersection(findNextHighlightPoints) // If the highlighted text has moved as expected, this should not have many elements - - XCTAssertGreaterThan( - highlightedPixelsInFindNextScreenshot.count, - minimumExpectedMatchingPixelsInFindHighlight, - "There are expected to be more than \(minimumExpectedMatchingPixelsInFindHighlight) pixels of NSColor.findHighlightColor in a screenshot of a \"Find in Page\" search where there is a match for a \"Find next\" operation, but this test found \(highlightedPixelsInFindNextScreenshot) matching pixels." - ) - XCTAssertTrue( - pixelSetIntersection.count <= findNextHighlightPoints.count / 2, - "When the selection rectangle has moved as expected, fewer than half of the highlighted pixel coordinates from \"Find Next\" should intersect with the highlighted pixel coordinates from the initial \"Find\" operation." - ) - } - - func test_findNext_nextArrowGoesToNextOccurrence() throws { - XCTAssertTrue( - addressBarTextField.waitForExistence(timeout: elementExistenceTimeout), - "The Address Bar text field did not exist when it was expected." - ) - addressBarTextField.typeText("\(Self.loremIpsumFileURL.absoluteString)\r") - XCTAssertTrue( - loremIpsumWebView.waitForExistence(timeout: elementExistenceTimeout), - "Local \"Lorem Ipsum\" web page didn't load with the expected title in a reasonable timeframe." - ) - app.typeKey("f", modifierFlags: .command) - XCTAssertTrue( - findInPageCloseButton.waitForExistence(timeout: elementExistenceTimeout), - "After invoking \"Find in Page\" with command-f, the elements of the \"Find in Page\" interface should exist." - ) - app.typeText("maximus\r") - let statusField = app.textFields["FindInPageController.statusField"] - XCTAssertTrue( - statusField.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find \"Find in Page\" statusField in a reasonable timeframe." - ) - let statusFieldTextContent = try XCTUnwrap(statusField.value as? String) - // Note: the following is not a localized test element, but it should have a localization strategy. - XCTAssertEqual(statusFieldTextContent, "1 of 4", "Unexpected status field text content after a \"Find in Page\" operation.") - let findInPageScreenshot = loremIpsumWebView.screenshot() - let highlightedPixelsInFindScreenshot = findInPageScreenshot.image.matchingPixels(of: .findHighlightColor) - let findHighlightPoints = Set(highlightedPixelsInFindScreenshot.map { $0.point }) // Coordinates of highlighted pixels in the find screenshot - let findInPageNextButton = app.windows.buttons["FindInPageController.nextButton"] - XCTAssertTrue( - findInPageNextButton.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find \"Find Next\" main menu bar item in a reasonable timeframe." - ) - - findInPageNextButton.click() - let updatedStatusField = app.textFields["FindInPageController.statusField"] - let updatedStatusFieldTextContent = updatedStatusField.value as! String - XCTAssertTrue( - updatedStatusField.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find the updated \"Find in Page\" statusField in a reasonable timeframe." - ) - XCTAssertEqual(updatedStatusFieldTextContent, "2 of 4", "Unexpected status field text content after a \"Find Next\" operation.") - let findNextScreenshot = loremIpsumWebView.screenshot() - let highlightedPixelsInFindNextScreenshot = findNextScreenshot.image.matchingPixels(of: .findHighlightColor) - let findNextHighlightPoints = highlightedPixelsInFindNextScreenshot.map { $0.point } - let pixelSetIntersection = findHighlightPoints - .intersection(findNextHighlightPoints) // If the highlighted text has moved as expected, this should not have many elements - - XCTAssertGreaterThan( - highlightedPixelsInFindNextScreenshot.count, - minimumExpectedMatchingPixelsInFindHighlight, - "There are expected to be more than \(minimumExpectedMatchingPixelsInFindHighlight) pixels of NSColor.findHighlightColor in a screenshot of a \"Find in Page\" search where there is a match, but this test found \(highlightedPixelsInFindNextScreenshot) matching pixels." - ) - XCTAssertTrue( - pixelSetIntersection.count <= findNextHighlightPoints.count / 2, - "When the selection rectangle has moved as expected, fewer than half of the highlighted pixel coordinates from \"Find Next\" should intersect with the highlighted pixel coordinates from the initial \"Find\" operation." - ) - } - - func test_findNext_commandGGoesToNextOccurrence() throws { - XCTAssertTrue( - addressBarTextField.waitForExistence(timeout: elementExistenceTimeout), - "The Address Bar text field did not exist when it was expected." - ) - addressBarTextField.typeText("\(Self.loremIpsumFileURL.absoluteString)\r") - XCTAssertTrue( - loremIpsumWebView.waitForExistence(timeout: elementExistenceTimeout), - "Local \"Lorem Ipsum\" web page didn't load with the expected title in a reasonable timeframe." - ) - app.typeKey("f", modifierFlags: .command) - XCTAssertTrue( - findInPageCloseButton.waitForExistence(timeout: elementExistenceTimeout), - "After invoking \"Find in Page\" with command-f, the elements of the \"Find in Page\" interface should exist." - ) - app.typeText("maximus\r") - let statusField = app.textFields["FindInPageController.statusField"] - XCTAssertTrue( - statusField.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find \"Find in Page\" statusField in a reasonable timeframe." - ) - let statusFieldTextContent = try XCTUnwrap(statusField.value as? String) - - // Note: the following is not a localized test element, but it should have a localization strategy. - XCTAssertEqual(statusFieldTextContent, "1 of 4", "Unexpected status field text content after a \"Find in Page\" operation.") - let findInPageScreenshot = loremIpsumWebView.screenshot() - let highlightedPixelsInFindScreenshot = findInPageScreenshot.image.matchingPixels(of: .findHighlightColor) - let findHighlightPoints = Set(highlightedPixelsInFindScreenshot.map { $0.point }) // Coordinates of highlighted pixels in the find screenshot - app.typeKey("g", modifierFlags: [.command]) - let updatedStatusField = app.textFields["FindInPageController.statusField"] - let updatedStatusFieldTextContent = updatedStatusField.value as! String - XCTAssertTrue( - updatedStatusField.waitForExistence(timeout: elementExistenceTimeout), - "Couldn't find the updated \"Find in Page\" statusField in a reasonable timeframe." - ) - - XCTAssertEqual(updatedStatusFieldTextContent, "2 of 4", "Unexpected status field text content after a \"Find Next\" operation.") - let findNextScreenshot = loremIpsumWebView.screenshot() - let highlightedPixelsInFindNextScreenshot = findNextScreenshot.image.matchingPixels(of: .findHighlightColor) - let findNextHighlightPoints = highlightedPixelsInFindNextScreenshot.map { $0.point } - let pixelSetIntersection = findHighlightPoints - .intersection(findNextHighlightPoints) // If the highlighted text has moved as expected, this should not have many elements - - XCTAssertGreaterThan( - highlightedPixelsInFindNextScreenshot.count, - minimumExpectedMatchingPixelsInFindHighlight, - "There are expected to be more than \(minimumExpectedMatchingPixelsInFindHighlight) pixels of NSColor.findHighlightColor in a screenshot of a \"Find in Page\" search where there is a match, but this test found \(highlightedPixelsInFindNextScreenshot) matching pixels." - ) - XCTAssertTrue( - pixelSetIntersection.count <= findNextHighlightPoints.count / 2, - "When the selection rectangle has moved as expected, fewer than half of the highlighted pixel coordinates from \"Find Next\" should intersect with the highlighted pixel coordinates from the initial \"Find\" operation." - ) - } } /// Helpers for the Find in Page tests