From cca5743f8ecfe61cb0bb8947f00d08988ddbad12 Mon Sep 17 00:00:00 2001 From: Hemanth Date: Tue, 12 Nov 2024 17:19:45 -0500 Subject: [PATCH] Refactor FXIOS-10492 UITests > Fix skipped flakey tests (#22987) * fix tests * revert clear and type function * Update website to fix flakiness due to different webpage title in different regions * use localhost url --- .../Tests/XCUITests/JumpBackInTests.swift | 185 +++++++++--------- .../Tests/XCUITests/NavigationTest.swift | 63 +++--- 2 files changed, 123 insertions(+), 125 deletions(-) diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/JumpBackInTests.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/JumpBackInTests.swift index 416a971d5e5c..74716dd14583 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/JumpBackInTests.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/JumpBackInTests.swift @@ -52,99 +52,98 @@ class JumpBackInTests: BaseTestCase { // https://mozilla.testrail.io/index.php?/cases/view/2306920 // Smoketest func testPrivateTab() throws { - throw XCTSkip("This test is flaky") -// // Visit https://www.twitter.com -// navigator.openURL("https://www.twitter.com") -// waitUntilPageLoad() -// -// // Open a new tab and check the "Jump Back In" section -// navigator.goto(TabTray) -// mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.TabTray.newTabButton], timeout: TIMEOUT) -// navigator.performAction(Action.OpenNewTabFromTabTray) -// closeKeyboard() -// -// // Twitter tab is visible in the "Jump Back In" section -// scrollDown() -// mozWaitForElementToExist(app.cells["JumpBackInCell"].firstMatch) -// mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Twitter"]) -// -// // Open private browsing -// navigator.goto(TabTray) -// navigator.toggleOn(userState.isPrivate, withAction: Action.TogglePrivateMode) -// -// // Visit YouTube in private browsing -// navigator.performAction(Action.OpenNewTabFromTabTray) -// navigator.openURL("https://www.youtube.com") -// waitUntilPageLoad() -// -// // Open a new tab in normal browsing and check the "Jump Back In" section -// navigator.toggleOff(userState.isPrivate, withAction: Action.ToggleRegularMode) -// navigator.goto(NewTabScreen) -// closeKeyboard() -// -// // Twitter should be in "Jump Back In" -// scrollDown() -// mozWaitForElementToExist(app.cells["JumpBackInCell"].firstMatch) -// mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Twitter"]) -// mozWaitForElementToNotExist(app.cells["JumpBackInCell"].staticTexts["YouTube"]) -// -// // Visit "amazon.com" and check the "Jump Back In" section -// navigator.openURL("https://www.amazon.com") -// waitUntilPageLoad() -// -// navigator.goto(TabTray) -// mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.TabTray.newTabButton], timeout: TIMEOUT) -// navigator.performAction(Action.OpenNewTabFromTabTray) -// closeKeyboard() -// -// // Amazon and Twitter are visible in the "Jump Back In" section -// scrollDown() -// mozWaitForElementToExist(app.cells["JumpBackInCell"].firstMatch) -// mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Amazon"]) -// mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Twitter"]) -// mozWaitForElementToNotExist(app.cells["JumpBackInCell"].staticTexts["YouTube"]) -// -// // Tap on Twitter from "Jump Back In" -// app.cells["JumpBackInCell"].staticTexts["Twitter"].tap() -// -// // The view is switched to the twitter tab -// let url = app.textFields[AccessibilityIdentifiers.Browser.UrlBar.url].value as! String -// XCTAssertEqual(url, "twitter.com/i/flow/login") -// -// // Open a new tab in normal browsing -// navigator.goto(TabTray) -// mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.TabTray.newTabButton], timeout: TIMEOUT) -// navigator.performAction(Action.OpenNewTabFromTabTray) -// closeKeyboard() -// -// // Check the "Jump Back In Section" -// scrollDown() -// mozWaitForElementToExist(app.cells["JumpBackInCell"].firstMatch) -// -// // Amazon is visible in "Jump Back In" -// mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Amazon"]) -// -// // Close the amazon tab -// navigator.goto(TabTray) -// if isTablet { -// mozWaitForElementToExist(app.navigationBars.segmentedControls["navBarTabTray"]) -// } else { -// mozWaitForElementToExist(app.navigationBars.staticTexts["Open Tabs"]) -// } -// app.cells["Amazon.com. Spend less. Smile more."].buttons[StandardImageIdentifiers.Large.cross].tap() -// -// // Revisit the "Jump Back In" section -// mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.TabTray.newTabButton], timeout: TIMEOUT) -// navigator.performAction(Action.OpenNewTabFromTabTray) -// closeKeyboard() -// -// // The "Jump Back In" section is still here with twitter listed -// scrollDown() -// mozWaitForElementToExist(app.cells["JumpBackInCell"].firstMatch) -// // FXIOS-5448 - Amazon should not be listed because we've closed the Amazon tab -// // mozWaitForElementToNotExist(app.cells["JumpBackInCell"].staticTexts["Amazon"]) -// mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Twitter"]) -// mozWaitForElementToNotExist(app.cells["JumpBackInCell"].staticTexts["YouTube"]) + // Visit https://www.wikipedia.org + navigator.openURL("https://www.wikipedia.org") + waitUntilPageLoad() + + // Open a new tab and check the "Jump Back In" section + navigator.goto(TabTray) + mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.TabTray.newTabButton], timeout: TIMEOUT) + navigator.performAction(Action.OpenNewTabFromTabTray) + closeKeyboard() + + // Twitter tab is visible in the "Jump Back In" section + scrollDown() + mozWaitForElementToExist(app.cells["JumpBackInCell"].firstMatch) + mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Wikipedia"]) + + // Open private browsing + navigator.goto(TabTray) + navigator.toggleOn(userState.isPrivate, withAction: Action.TogglePrivateMode) + + // Visit YouTube in private browsing + navigator.performAction(Action.OpenNewTabFromTabTray) + navigator.openURL("https://www.youtube.com") + waitUntilPageLoad() + + // Open a new tab in normal browsing and check the "Jump Back In" section + navigator.toggleOff(userState.isPrivate, withAction: Action.ToggleRegularMode) + navigator.goto(NewTabScreen) + closeKeyboard() + + // Twitter should be in "Jump Back In" + scrollDown() + mozWaitForElementToExist(app.cells["JumpBackInCell"].firstMatch) + mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Wikipedia"]) + mozWaitForElementToNotExist(app.cells["JumpBackInCell"].staticTexts["YouTube"]) + + // Visit "mozilla.org" and check the "Jump Back In" section + navigator.openURL("http://localhost:\(serverPort)/test-fixture/test-example.html") + waitUntilPageLoad() + + navigator.goto(TabTray) + mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.TabTray.newTabButton], timeout: TIMEOUT) + navigator.performAction(Action.OpenNewTabFromTabTray) + closeKeyboard() + + // Amazon and Twitter are visible in the "Jump Back In" section + scrollDown() + mozWaitForElementToExist(app.cells["JumpBackInCell"].firstMatch) + mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Example Domain"]) + mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Wikipedia"]) + mozWaitForElementToNotExist(app.cells["JumpBackInCell"].staticTexts["YouTube"]) + + // Tap on Twitter from "Jump Back In" + app.cells["JumpBackInCell"].staticTexts["Wikipedia"].firstMatch.tap() + + // The view is switched to the twitter tab + let url = app.textFields[AccessibilityIdentifiers.Browser.UrlBar.url].value as! String + XCTAssertEqual(url, "www.wikipedia.org/") + + // Open a new tab in normal browsing + navigator.goto(TabTray) + mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.TabTray.newTabButton], timeout: TIMEOUT) + navigator.performAction(Action.OpenNewTabFromTabTray) + closeKeyboard() + + // Check the "Jump Back In Section" + scrollDown() + mozWaitForElementToExist(app.cells["JumpBackInCell"].firstMatch) + + // Amazon is visible in "Jump Back In" + mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Example Domain"]) + + // Close the amazon tab + navigator.goto(TabTray) + if isTablet { + mozWaitForElementToExist(app.navigationBars.segmentedControls["navBarTabTray"]) + } else { + mozWaitForElementToExist(app.navigationBars.staticTexts["Open Tabs"]) + } + app.cells["Example Domain"].buttons[StandardImageIdentifiers.Large.cross].tap() + + // Revisit the "Jump Back In" section + mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.TabTray.newTabButton], timeout: TIMEOUT) + navigator.performAction(Action.OpenNewTabFromTabTray) + closeKeyboard() + + // The "Jump Back In" section is still here with twitter listed + scrollDown() + mozWaitForElementToExist(app.cells["JumpBackInCell"].firstMatch) + // FXIOS-5448 - Amazon should not be listed because we've closed the Amazon tab + // mozWaitForElementToNotExist(app.cells["JumpBackInCell"].staticTexts["Example Domain"]) + mozWaitForElementToExist(app.cells["JumpBackInCell"].staticTexts["Wikipedia"]) + mozWaitForElementToNotExist(app.cells["JumpBackInCell"].staticTexts["YouTube"]) } // https://mozilla.testrail.io/index.php?/cases/view/2445811 diff --git a/firefox-ios/firefox-ios-tests/Tests/XCUITests/NavigationTest.swift b/firefox-ios/firefox-ios-tests/Tests/XCUITests/NavigationTest.swift index 2d43bc19a04d..db9bf9ee6545 100644 --- a/firefox-ios/firefox-ios-tests/Tests/XCUITests/NavigationTest.swift +++ b/firefox-ios/firefox-ios-tests/Tests/XCUITests/NavigationTest.swift @@ -340,38 +340,37 @@ class NavigationTest: BaseTestCase { // https://mozilla.testrail.io/index.php?/cases/view/2441776 // Smoketest func testPopUpBlocker() throws { - throw XCTSkip("This test is flakey") -// // Check that it is enabled by default -// navigator.nowAt(BrowserTab) -// mozWaitForElementToExist(app.buttons["TabToolbar.menuButton"], timeout: TIMEOUT) -// navigator.goto(SettingsScreen) -// mozWaitForElementToExist(app.tables[AccessibilityIdentifiers.Settings.tableViewController]) -// let switchBlockPopUps = app.tables.cells.switches["blockPopups"] -// let switchValue = switchBlockPopUps.value! -// XCTAssertEqual(switchValue as? String, "1") -// -// // Check that there are no pop ups -// navigator.openURL(popUpTestUrl) -// mozWaitForValueContains(app.textFields[AccessibilityIdentifiers.Browser.UrlBar.url], value: "blocker.html") -// mozWaitForElementToExist(app.webViews.staticTexts["Blocked Element"]) -// -// let numTabs = app.buttons["Show Tabs"].value -// XCTAssertEqual("1", numTabs as? String, "There should be only on tab") -// -// // Now disable the Block PopUps option -// navigator.goto(BrowserTabMenu) -// navigator.goto(SettingsScreen) -// mozWaitForElementToExist(switchBlockPopUps, timeout: TIMEOUT) -// switchBlockPopUps.tap() -// let switchValueAfter = switchBlockPopUps.value! -// XCTAssertEqual(switchValueAfter as? String, "0") -// -// // Check that now pop ups are shown, two sites loaded -// navigator.openURL(popUpTestUrl) -// waitUntilPageLoad() -// mozWaitForValueContains(app.textFields[AccessibilityIdentifiers.Browser.UrlBar.url], value: "example.com") -// let numTabsAfter = app.buttons["Show Tabs"].value -// XCTAssertNotEqual("1", numTabsAfter as? String, "Several tabs are open") + // Check that it is enabled by default + navigator.nowAt(BrowserTab) + mozWaitForElementToExist(app.buttons["TabToolbar.menuButton"], timeout: TIMEOUT) + navigator.goto(SettingsScreen) + mozWaitForElementToExist(app.tables[AccessibilityIdentifiers.Settings.tableViewController]) + let switchBlockPopUps = app.tables.cells.switches["blockPopups"] + let switchValue = switchBlockPopUps.value! + XCTAssertEqual(switchValue as? String, "1") + + // Check that there are no pop ups + navigator.openURL(popUpTestUrl) + mozWaitForValueContains(app.textFields[AccessibilityIdentifiers.Browser.UrlBar.url], value: "blocker.html") + mozWaitForElementToExist(app.webViews.staticTexts["Blocked Element"]) + + let numTabs = app.buttons["Show Tabs"].value + XCTAssertEqual("1", numTabs as? String, "There should be only on tab") + + // Now disable the Block PopUps option + navigator.goto(BrowserTabMenu) + navigator.goto(SettingsScreen) + mozWaitForElementToExist(switchBlockPopUps, timeout: TIMEOUT) + switchBlockPopUps.tap() + let switchValueAfter = switchBlockPopUps.value! + XCTAssertEqual(switchValueAfter as? String, "0") + + // Check that now pop ups are shown, two sites loaded + navigator.openURL(popUpTestUrl) + waitUntilPageLoad() + mozWaitForValueContains(app.textFields[AccessibilityIdentifiers.Browser.UrlBar.url], value: "example.com") + let numTabsAfter = app.buttons["Show Tabs"].value + XCTAssertNotEqual("1", numTabsAfter as? String, "Several tabs are open") } // https://mozilla.testrail.io/index.php?/cases/view/2306858