Skip to content

Commit

Permalink
Refactor FXIOS-10492 UITests > Fix skipped flakey tests (#22987)
Browse files Browse the repository at this point in the history
* fix tests

* revert clear and type function

* Update website to fix flakiness due to different webpage title in different regions

* use localhost url
  • Loading branch information
hemche authored Nov 12, 2024
1 parent 9073440 commit cca5743
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 125 deletions.
185 changes: 92 additions & 93 deletions firefox-ios/firefox-ios-tests/Tests/XCUITests/JumpBackInTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 31 additions & 32 deletions firefox-ios/firefox-ios-tests/Tests/XCUITests/NavigationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cca5743

Please sign in to comment.