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

Add MTE-1520 [v119] Add simple test for Fakespot #16405

Merged
merged 15 commits into from
Oct 3, 2023
Merged

Add MTE-1520 [v119] Add simple test for Fakespot #16405

merged 15 commits into from
Oct 3, 2023

Conversation

clarmso
Copy link
Collaborator

@clarmso clarmso commented Sep 15, 2023

📜 Tickets

Jira ticket

💡 Description

Fakespot has been enabled on Amazon.com. Let me write a new test to ensure that Fakespot is present.

📝 Checklist

You have to check all boxes before merging

  • Filled in the above information (tickets numbers and description of your work)
  • Updated the PR name to follow our PR naming guidelines
  • Wrote unit tests and/or ensured the tests suite is passing
  • When working on UI, I checked and implemented accessibility (minimum Dynamic Text and VoiceOver)
  • If needed I updated documentation / comments for complex code and public methods

@mobiletest-ci-bot
Copy link

mobiletest-ci-bot commented Sep 15, 2023

Messages
📖 Edited 9 files
📖 Created 1 files

Generated by 🚫 Danger Swift against 9c50036

import XCTest

class FakespotTests: BaseTestCase {
func testFakespotAvailable() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add the testrail link before the test

Copy link
Contributor

Choose a reason for hiding this comment

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

If not created yet, we should create the tests there, I already talked to @abodea about this and he agrees on having the test suite there with this basic test for now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have created the test on TestRail.

// Tap shopping cart icon on Awesome bar
// Note: I can't find the label for the shopping cart icon.
// Workaround: Tap somewhere left of the "Share" button
waitForExistence(app.buttons["TabLocationView.shareButton"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use the accessibility ids to look for view elements? The id for the button is AccessibilityIdentifiers.Toolbar.shoppingButton.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The app.debugDescription does not show AccessibilityIdentifiers.Toolbar.shoppingButton in the awesome bar. Such an icon is displayed and can be tapped. Here is the debugDescription:

                        Other, 0x7ff510a1bb60, {{7.0, 53.0}, {376.0, 42.0}}
                          TextField, 0x7ff510a3e0d0, {{48.0, 63.0}, {215.0, 22.0}}, identifier: 'url', label: 'Address Bar', placeholderValue: 'Search or enter address', value: www.amazon.com/gp/...
                          Button, 0x7ff510a3a870, {{343.0, 54.0}, {40.0, 40.0}}, identifier: 'TabLocationView.reloadButton', label: 'Reload page'
                          Button, 0x7ff510a3ac20, {{7.0, 54.0}, {40.0, 40.0}}, identifier: 'TabLocationView.trackingProtectionButton', label: 'Secure connection'
                          Button, 0x7ff510a3afd0, {{303.0, 54.0}, {40.0, 40.0}}, identifier: 'TabLocationView.shareButton', label: 'Share this page'

Copy link
Contributor

@isabelrios isabelrios Sep 18, 2023

Choose a reason for hiding this comment

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

@thatswinnie has that icon changed the ID, wondering why @clarmso cannot see it when printing the elements... I will give this a try later today

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't see it either... only Tracking Protection, Share and Reload button are available via print(app.debugDescription)
Screenshot 2023-09-18 at 11 41 05

Copy link
Collaborator Author

@clarmso clarmso Sep 18, 2023

Choose a reason for hiding this comment

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

Relying on the coordinates to tap on the shoppingButton (via tapAtPoint) is flaky on my end. I would not merge this PR before debugDescription could see the icon. 😢

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed... that coordinates are specific to a device's screen size.. better to have the ID...

waitForExistence(app.buttons["TabLocationView.shareButton"])
app.buttons["TabLocationView.shareButton"].tapAtPoint(CGPoint(x: -10, y: 0))
waitForExistence(app.otherElements["PopoverDismissRegion"])
waitForExistence(app.staticTexts["Shopping.Sheet.HeaderTitle"])
Copy link
Contributor

Choose a reason for hiding this comment

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

The title has the a11y id AccessibilityIdentifiers.Shopping.sheetHeaderTitle.

@isabelrios
Copy link
Contributor

I run the test locally and it works consistently. Good job here!
I agree that the best place to start with is running it on the Full Functional, we can move it to block PRs on the smoketest when we feel confident about it and the feature not changing.

// Workaround: Tap somewhere left of the "Share" button
waitForExistence(app.buttons[AccessibilityIdentifiers.Toolbar.shareButton])
waitUntilPageLoad()
app.buttons[AccessibilityIdentifiers.Toolbar.shareButton].tapAtPoint(CGPoint(x: -10, y: 0))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using the coordinates to tap the shopping icon is flaky.

@clarmso
Copy link
Collaborator Author

clarmso commented Sep 26, 2023

The test fails intermittently because Amazon may issue a Captcha-like challenge when the site is hit repeatedly. If we don't run the test repeatedly, the intermittent failures are avoidable.

Screenshot 2023-09-26 at 3 53 58 PM Screenshot 2023-09-26 at 3 54 08 PM


// Tap the shopping cart icon
waitUntilPageLoad()
mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.shoppingButton])
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

Tests/XCUITests/FakespotTests.swift Outdated Show resolved Hide resolved
Tests/XCUITests/FakespotTests.swift Outdated Show resolved Hide resolved
bitrise.yml Outdated
@@ -102,6 +102,7 @@ workflows:

echo "bitrise_xcode"
COUNT_XCUI=$(./test-fixtures/generate-metrics.sh /Users/vagrant/git/xcodebuild_fennec.log all)
cat /Users/vagrant/git/xcodebuild_fennec.log
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious why do we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was trying to debug the lint warning/error.

@isabelrios
Copy link
Contributor

This is looking great @clarmso! Once the IDs are added as @thatswinnie commented, this could be ready to land.
I would not worry for the # of test executions for now because this will run as part of the Full Functional. That said, I think we need to think of a way, if possible, to avoid that issue, let's explore which options we would have.
Thanks both for your work with this PR! 🙏

@isabelrios
Copy link
Contributor

Bitrise is red due to the increase in warnings. There is a new warning added in this PR:

/Users/vagrant/git/Tests/XCUITests/FakespotTests.swift:5:8: implicit import of bridging header 'Shared-Bridging-Header.h' via module 'Shared' is deprecated and will be removed in a later version of Swift
import Shared

@clarmso
Copy link
Collaborator Author

clarmso commented Sep 27, 2023

This is looking great @clarmso! Once the IDs are added as @thatswinnie commented, this could be ready to land. I would not worry for the # of test executions for now because this will run as part of the Full Functional. That said, I think we need to think of a way, if possible, to avoid that issue, let's explore which options we would have. Thanks both for your work with this PR! 🙏

@isabelrios The test fails about 5-6 times out of 100 consecutive test runs. If we only run the test once every few minutes, we may be ok. 🤔

mozWaitForElementToExist(app.buttons[AccessibilityIdentifiers.Toolbar.shoppingButton])
app.buttons[AccessibilityIdentifiers.Toolbar.shoppingButton].tap()
mozWaitForElementToExist(app.staticTexts[AccessibilityIdentifiers.Shopping.sheetHeaderTitle])
XCTAssertEqual(app.staticTexts[AccessibilityIdentifiers.Shopping.sheetHeaderTitle].label, String.Shopping.SheetHeaderTitle)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@thatswinnie String.Shopping.SheetHeaderTitle is not recognized. Please help. 😞

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like we need import Shared for that to be recognized but then there is the new warning...

Copy link
Contributor

Choose a reason for hiding this comment

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

@clarmso if you add the dependency here, it may not warn you ... we did something similar with Common and there is not a warning for that (not sure if this is why though)
Screenshot 2023-09-27 at 16 24 22

app.buttons[AccessibilityIdentifiers.Toolbar.shoppingButton].tap()
mozWaitForElementToExist(app.staticTexts[AccessibilityIdentifiers.Shopping.sheetHeaderTitle])
XCTAssertEqual(app.staticTexts[AccessibilityIdentifiers.Shopping.sheetHeaderTitle].label, .Shopping.SheetHeaderTitle)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I followed the same style as in the source code here.

label.text = .Shopping.SheetHeaderTitle

// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import XCTest
import Shared
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

import Shared is giving me a new warning but the identifier does not work without this import. 🤔

⚠️  /Users/vagrant/git/Tests/XCUITests/FakespotTests.swift:5:8: implicit import of bridging header 'Shared-Bridging-Header.h' via module 'Shared' is deprecated and will be removed in a later version of Swift
import Shared

Copy link
Contributor

@isabelrios isabelrios Sep 27, 2023

Choose a reason for hiding this comment

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

@clarmso we should try to fix this warning before merging, otherwise we will be close to threshold again... I can try to help you with that

@isabelrios
Copy link
Contributor

@clarmso please rebase latest main, unit tests failures should be gone with that and we could land this PR

@isabelrios isabelrios merged commit e260331 into mozilla-mobile:main Oct 3, 2023
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants