Skip to content
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

Fix #5858 - [XCUITests] Update tests after removing custom search engine icon #5948

Merged
merged 1 commit into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions XCUITests/FxScreenGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ class Action {
static let DisableTranslation = "DisableTranlation"
static let SelectGoogle = "SelectGoogle"
static let SelectBing = "SelectBing"

static let AddCustomSearchEngine = "AddCustomSearchEngine"
static let RemoveCustomSearchEngine = "RemoveCustomSearchEngine"

static let ExitMobileBookmarksFolder = "ExitMobileBookmarksFolder"
static let CloseBookmarkPanel = "CloseBookmarkPanel"
Expand Down Expand Up @@ -665,6 +668,13 @@ func createScreenGraph(for test: XCTestCase, with app: XCUIApplication) -> MMScr
let table = app.tables.element(boundBy: 0)
screenState.tap(table.cells["customEngineViewButton"], to: AddCustomSearchSettings)
screenState.backAction = navigationControllerBackAction
screenState.gesture(forAction: Action.RemoveCustomSearchEngine) {userSTate in
// Screengraph will go back to main Settings screen. Manually tap on settings
app.tables["AppSettingsTableViewController.tableView"].staticTexts["Google"].tap()
app.navigationBars["Search"].buttons["Edit"].tap()
app.tables.buttons["Delete Mozilla Engine"].tap()
app.tables.buttons["Delete"].tap()
}
}

map.addScreenState(SiriSettings) { screenState in
Expand Down Expand Up @@ -709,6 +719,19 @@ func createScreenGraph(for test: XCTestCase, with app: XCUIApplication) -> MMScr
}

map.addScreenState(AddCustomSearchSettings) { screenState in
screenState.gesture(forAction: Action.AddCustomSearchEngine) { userState in
app.tables.textViews["customEngineTitle"].staticTexts["Search Engine"].tap()
app.typeText("Mozilla Engine")
app.tables.textViews["customEngineUrl"].tap()

UIPasteboard.general.string = "https://developer.mozilla.org/search?q=%s"

let tablesQuery = app.tables
let customengineurlTextView = tablesQuery.textViews["customEngineUrl"]
sleep(1)
customengineurlTextView.press(forDuration: 1.0)
app.staticTexts["Paste"].tap()
}
screenState.backAction = navigationControllerBackAction
}

Expand Down
168 changes: 67 additions & 101 deletions XCUITests/ThirdPartySearchTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ class ThirdPartySearchTest: BaseTestCase {
}

func testCustomSearchEngines() {
// Visit MDN to add a custom search engine
loadWebPage(mozDeveloperWebsite, waitForLoadToFinish: true)
addSearchProvider()

if !isTablet {
dismissKeyboardAssistant(forApp: app)
}

navigator.performAction(Action.AddCustomSearchEngine)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this line we would need to add:

waitForExistence(app.buttons["customEngineSaveButton"], timeout: 3)
app.buttons["customEngineSaveButton"].tap()

waitForExistence(app.buttons["customEngineSaveButton"], timeout: 3)
app.buttons["customEngineSaveButton"].tap()

waitForExistence(app.navigationBars["Search"].buttons["Settings"], timeout: 3)
app.navigationBars["Search"].buttons["Settings"].tap()
app.navigationBars["Settings"].buttons["AppSettingsTableViewController.navigationItem.leftBarButtonItem"].tap()
// Perform a search using a custom search engine
tabTrayButton(forApp: app).tap()
app.buttons["TabTrayController.addTabButton"].tap()
waitForExistence(app.textFields["url"], timeout: 3)
app.textFields["url"].tap()
waitForExistence(app.buttons["urlBar-cancel"])
app.typeText("window")
app.scrollViews.otherElements.buttons["developer.mozilla.org search"].tap()
UIPasteboard.general.string = "window"
app.textFields.firstMatch.press(forDuration: 1)
app.staticTexts["Paste"].tap()
app.scrollViews.otherElements.buttons["Mozilla Engine search"].tap()
waitUntilPageLoad()

var url = app.textFields["url"].value as! String
if url.hasPrefix("https://") == false {
Expand All @@ -37,22 +37,25 @@ class ThirdPartySearchTest: BaseTestCase {
}

func testCustomSearchEngineAsDefault() {
// Visit MDN to add a custom search engine
loadWebPage(mozDeveloperWebsite, waitForLoadToFinish: true)
addSearchProvider()

if !isTablet {
dismissKeyboardAssistant(forApp: app)
}
navigator.performAction(Action.AddCustomSearchEngine)
waitForExistence(app.buttons["customEngineSaveButton"], timeout: 3)
app.buttons["customEngineSaveButton"].tap()

// Go to settings and set MDN as the default
navigator.goto(SearchSettings)
app.tables.cells.element(boundBy: 0).tap()
app.tables.staticTexts["developer.mozilla.org"].tap()
navigator.goto(BrowserTab)
waitForExistence(app.tables.staticTexts["Google"])
app.tables.staticTexts["Google"].tap()
waitForExistence(app.tables.staticTexts["Mozilla Engine"])
app.tables.staticTexts["Mozilla Engine"].tap()
DismissSearchScreen()

// Perform a search to check
navigator.openNewURL(urlString:"window")
app.textFields["url"].tap()

UIPasteboard.general.string = "window"
app.textFields.firstMatch.press(forDuration: 1)
app.staticTexts["Paste & Go"].tap()

waitUntilPageLoad()

// Ensure that the default search is MDN
var url = app.textFields["url"].value as! String
Expand All @@ -63,98 +66,61 @@ class ThirdPartySearchTest: BaseTestCase {
}

func testCustomSearchEngineDeletion() {
// Visit MDN to add a custom search engine
loadWebPage(mozDeveloperWebsite, waitForLoadToFinish: true)
addSearchProvider()
navigator.performAction(Action.AddCustomSearchEngine)
waitForExistence(app.buttons["customEngineSaveButton"], timeout: 3)
app.buttons["customEngineSaveButton"].tap()

if !isTablet {
dismissKeyboardAssistant(forApp: app)
}
waitForExistence(app.navigationBars["Search"].buttons["Settings"], timeout: 3)

let tabTrayButton = self.tabTrayButton(forApp: app)
tabTrayButton.tap()
app.buttons["TabTrayController.addTabButton"].tap()
waitForExistence(app.textFields["url"], timeout: 3)
app.navigationBars["Search"].buttons["Settings"].tap()
app.navigationBars["Settings"].buttons["AppSettingsTableViewController.navigationItem.leftBarButtonItem"].tap()
app.textFields["url"].tap()
waitForExistence(app.buttons["urlBar-cancel"])
app.typeText("window")

// For timing issue, we need a wait statement
waitForExistence(app.scrollViews.otherElements.buttons["developer.mozilla.org search"])
XCTAssert(app.scrollViews.otherElements.buttons["developer.mozilla.org search"].exists)
app.typeText("\r")

// Go to settings and set MDN as the default
waitUntilPageLoad()
waitForNoExistence(app.alerts.buttons["Don't Allow"], timeoutValue: 15)
waitForTabsButton()

// Workaround for iOS13, can't go directly to BrowserTabMenu
UIPasteboard.general.string = "window"
app.textFields.firstMatch.press(forDuration: 1)
app.staticTexts["Paste"].tap()
waitForExistence(app.scrollViews.otherElements.buttons["Mozilla Engine search"])
XCTAssertTrue(app.scrollViews.otherElements.buttons["Mozilla Engine search"].exists)

// Need to go step by step to Search Settings. The ScreenGraph will fail to go to the Search Settings Screen
app.buttons["urlBar-cancel"].tap()
app.buttons["TabToolbar.menuButton"].tap()
navigator.goto(SearchSettings)

app.navigationBars["Search"].buttons["Edit"].tap()
app.tables.buttons["Delete developer.mozilla.org"].tap()
app.tables.buttons["Delete"].tap()

navigator.goto(BrowserTab)

app.tables["Context Menu"].staticTexts["Settings"].tap()
app.tables.staticTexts["Google"].tap()
navigator.performAction(Action.RemoveCustomSearchEngine)
DismissSearchScreen()

// Perform a search to check
tabTrayButton.tap(force: true)
app.buttons["TabTrayController.addTabButton"].tap()
waitForExistence(app.textFields["url"], timeout: 3)
app.textFields["url"].tap()
waitForExistence(app.buttons["urlBar-cancel"])
app.typeText("window")
waitForNoExistence(app.scrollViews.otherElements.buttons["developer.mozilla.org search"])
XCTAssertFalse(app.scrollViews.otherElements.buttons["developer.mozilla.org search"].exists)
}
UIPasteboard.general.string = "window"
app.textFields.firstMatch.press(forDuration: 1)
app.staticTexts["Paste"].tap()

private func addSearchProvider() {
// Tap on the search field
app.webViews.searchFields.element(boundBy: 0).tap()
// Workaround due to issue #5442
if isTablet {
app.buttons["Reload"].tap()
waitUntilPageLoad()
app.webViews.searchFields.element(boundBy: 0).tap()
}
app.buttons["AddSearch"].tap()
app.alerts["Add Search Provider?"].buttons["OK"].tap()
waitForExistence(app.buttons["AddSearch"], timeout: 3)
XCTAssertFalse(app.buttons["AddSearch"].isEnabled)
waitForNoExistence(app.scrollViews.otherElements.buttons["Mozilla Engine search"])
XCTAssertFalse(app.scrollViews.otherElements.buttons["Mozilla Engine search"].exists)
}

func testCustomEngineFromCorrectTemplate() {
navigator.goto(SearchSettings)
app.tables.cells["customEngineViewButton"].tap()

app.textViews["customEngineTitle"].tap()
app.typeText("Ask")
app.textViews["customEngineUrl"].tap()
app.typeText("http://www.ask.com/web?q=%s")
app.navigationBars.buttons["customEngineSaveButton"].tap()

// Perform a search using a custom search engine
waitForExistence(app.tables.staticTexts["Ask"])
navigator.goto(HomePanelsScreen)
app.textFields["url"].tap()
app.typeText("strange charm")
app.scrollViews.otherElements.buttons["Ask search"].tap()

// Ensure that correct search is done
let url = app.textFields["url"].value as! String
XCTAssert(url.hasPrefix("www.ask.com"), "The URL should indicate that the search was performed using ask")

private func DismissSearchScreen() {
waitForExistence(app.navigationBars["Search"].buttons["Settings"])
app.navigationBars["Search"].buttons["Settings"].tap()
app.navigationBars["Settings"].buttons["AppSettingsTableViewController.navigationItem.leftBarButtonItem"].tap()
}

func testCustomEngineFromIncorrectTemplate() {
navigator.goto(SearchSettings)
app.tables.cells["customEngineViewButton"].tap()
navigator.goto(AddCustomSearchSettings)
app.textViews["customEngineTitle"].tap()
app.typeText("Feeling Lucky")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here, we need to use the workaround again:

        UIPasteboard.general.string = "http://www.google.com/search?q=&btnI"
        
        let tablesQuery = app.tables
        let customengineurlTextView = tablesQuery.textViews["customEngineUrl"]
        customengineurlTextView.staticTexts["URL (Replace Query with %s)"].tap()
        customengineurlTextView.press(forDuration: 1.0)
        app.staticTexts["Paste"].tap()

app.textViews["customEngineUrl"].tap()
app.typeText("http://www.google.com/search?q=&btnI") //Occurunces of %s != 1


UIPasteboard.general.string = "http://www.google.com/search?q=&btnI"

let tablesQuery = app.tables
let customengineurlTextView = tablesQuery.textViews["customEngineUrl"]
customengineurlTextView.staticTexts["URL (Replace Query with %s)"].tap()
customengineurlTextView.press(forDuration: 1.0)
app.staticTexts["Paste"].tap()
sleep(2)
app.navigationBars.buttons["customEngineSaveButton"].tap()

waitForExistence(app.alerts.element(boundBy: 0))
Expand Down