-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat e2e convert to pw suite coinmarket (#16065)
* feat(e2e): Convert to playwright new suite: buy-coins.tests.ts adds commented invity data mocking that needs to be fixed first visual comparison in tests * refactor(e2e): Cleans up paramaeters of playwright fixtures * refactor(e2e): Cleans up the new buy-coins.test.ts Remove invity unfunctional mocks improve visual verification minor other refactoring * feat(e2e): Enable @other group and nightly web PW test runs * fix(e2e): Fix proper mask of visual comparison in buy-coins.test.ts * fix(e2e): Wrong test group * fix(e2e): Sets default resolution and reverts one locator needed by cy tests refactor waiting for offer sync * fix(e2e): Solves breakdown problems of electron improves waits for offer sync * fix(e2e): Disable snapshots for Desktop project minor refactoring and tuning of buy-coin.tests.ts * chore(e2e): Removes refactored test from cy * fix(e2e): Solve default currency issue in buy-coin.tests.ts improves stability of settings tests * fix(e2e): Solves delayed best offer and geolocation * fix(e2e): Rework waiting for offer sync and disables snapshots for web * fix(e2e): Attempt to enable snapshots on web tests
- Loading branch information
Showing
26 changed files
with
298 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+45.9 KB
...e2e/snapshots/web/coin-market/buy-coins.test.ts/best-offer-buy-confirmation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+30.4 KB
...sktop-core/e2e/snapshots/web/coin-market/buy-coins.test.ts/buy-coins-layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.9 KB
...napshots/web/coin-market/buy-coins.test.ts/compared-offers-buy-confirmation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
packages/suite-desktop-core/e2e/support/pageActions/marketActions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { Locator, Page, expect } from '@playwright/test'; | ||
|
||
import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link'; | ||
import { FiatCurrencyCode } from '@suite-common/suite-config'; | ||
import regional from '@trezor/suite/src/constants/wallet/coinmarket/regional'; | ||
|
||
const getCountryLabel = (country: string) => { | ||
const labelWithFlag = regional.countriesMap.get(country); | ||
if (!labelWithFlag) { | ||
throw new Error(`Country ${country} not found in the countries map`); | ||
} | ||
|
||
return labelWithFlag.substring(labelWithFlag.indexOf(' ') + 1); | ||
}; | ||
|
||
export class MarketActions { | ||
readonly offerSpinner: Locator; | ||
readonly layout: Locator; | ||
readonly form: Locator; | ||
readonly bestOfferProvider: Locator; | ||
readonly bestOfferYouGet: Locator; | ||
readonly bestOfferAmount: Locator; | ||
readonly buyBestOfferButton: Locator; | ||
readonly youPayInput: Locator; | ||
readonly youPayCurrencyDropdown: Locator; | ||
readonly youPayCurrencyOption = (currency: FiatCurrencyCode) => | ||
this.page.getByTestId(`@coinmarket/form/fiat-currency-select/option/${currency}`); | ||
readonly countryOfResidenceDropdown: Locator; | ||
readonly buyOffersPage: Locator; | ||
readonly compareButton: Locator; | ||
readonly quotes: Locator; | ||
readonly quoteOfProvider = (provider: string) => | ||
this.page.getByTestId(`@coinmarket/offers/quote-${provider}`); | ||
readonly quoteProvider: Locator; | ||
readonly quoteAmount: Locator; | ||
readonly selectThisQuoteButton: Locator; | ||
readonly modal: Locator; | ||
readonly buyTermsConfirmButton: Locator; | ||
readonly confirmOnTrezorButton: Locator; | ||
readonly confirmOnDevicePrompt: Locator; | ||
readonly tradeConfirmation: Locator; | ||
readonly tradeConfirmationCryptoAmount: Locator; | ||
readonly tradeConfirmationProvider: Locator; | ||
readonly tradeConfirmationContinueButton: Locator; | ||
|
||
constructor(private page: Page) { | ||
this.offerSpinner = this.page.getByTestId('@coinmarket/offers/loading-spinner'); | ||
this.layout = this.page.getByTestId('@coinmarket'); | ||
this.form = this.page.getByTestId('@coinmarket/form'); | ||
this.bestOfferProvider = this.page.getByTestId('@coinmarket/offers/quote/provider'); | ||
this.bestOfferYouGet = this.page.getByTestId('@coinmarket/best-offer/amount'); | ||
this.bestOfferAmount = this.page.getByTestId('@coinmarket/form/offer/crypto-amount'); | ||
this.buyBestOfferButton = this.page.getByTestId('@coinmarket/form/buy-button'); | ||
this.youPayInput = this.page.getByTestId('@coinmarket/form/fiat-input'); | ||
this.youPayCurrencyDropdown = this.page.getByTestId( | ||
'@coinmarket/form/fiat-currency-select/input', | ||
); | ||
this.countryOfResidenceDropdown = this.page.getByTestId( | ||
'@coinmarket/form/country-select/input', | ||
); | ||
this.buyOffersPage = this.page.getByTestId('@coinmarket/buy-offers'); | ||
this.compareButton = this.page.getByTestId('@coinmarket/form/compare-button'); | ||
this.quotes = this.page.getByTestId('@coinmarket/offers/quote'); | ||
this.quoteProvider = this.page.getByTestId('@coinmarket/offers/quote/provider'); | ||
this.quoteAmount = this.page.getByTestId('@coinmarket/offers/quote/crypto-amount'); | ||
this.selectThisQuoteButton = this.page.getByTestId( | ||
'@coinmarket/offers/get-this-deal-button', | ||
); | ||
this.modal = this.page.getByTestId('@modal'); | ||
this.buyTermsConfirmButton = this.page.getByTestId( | ||
'@coinmarket/buy/offers/buy-terms-confirm-button', | ||
); | ||
this.confirmOnTrezorButton = this.page.getByTestId( | ||
'@coinmarket/offer/confirm-on-trezor-button', | ||
); | ||
this.confirmOnDevicePrompt = this.page.getByTestId('@prompts/confirm-on-device'); | ||
this.tradeConfirmation = this.page.getByTestId('@coinmarket/selected-offer'); | ||
this.tradeConfirmationCryptoAmount = this.page.getByTestId( | ||
'@coinmarket/form/info/crypto-amount', | ||
); | ||
this.tradeConfirmationProvider = this.page.getByTestId('@coinmarket/form/info/provider'); | ||
this.tradeConfirmationContinueButton = this.page.getByTestId( | ||
'@coinmarket/offer/continue-transaction-button', | ||
); | ||
} | ||
|
||
waitForOffersSyncToFinish = async () => { | ||
await expect(this.offerSpinner).toBeHidden({ timeout: 30000 }); | ||
//Even though the offer sync is finished, the best offer might not be displayed correctly yet and show 0 BTC | ||
await expect(this.bestOfferAmount).not.toHaveText('0 BTC'); | ||
await expect(this.buyBestOfferButton).toBeEnabled(); | ||
}; | ||
|
||
selectCountryOfResidence = async (country: string) => { | ||
const countryLabel = getCountryLabel(country); | ||
const currentCountry = await this.countryOfResidenceDropdown.textContent(); | ||
if (currentCountry === countryLabel) { | ||
return; | ||
} | ||
await this.countryOfResidenceDropdown.click(); | ||
await this.countryOfResidenceDropdown.getByRole('combobox').fill(countryLabel); | ||
await this.page.getByTestId(`@coinmarket/form/country-select/option/${country}`).click(); | ||
}; | ||
|
||
selectFiatCurrency = async (currency: FiatCurrencyCode) => { | ||
const currentCurrency = await this.youPayCurrencyDropdown.textContent(); | ||
if (currentCurrency === currency.toUpperCase()) { | ||
return; | ||
} | ||
await this.youPayCurrencyDropdown.click(); | ||
await this.youPayCurrencyOption(currency).click(); | ||
}; | ||
|
||
setYouPayAmount = async ( | ||
amount: string, | ||
currency: FiatCurrencyCode = 'czk', | ||
country: string = 'CZ', | ||
) => { | ||
//Warning: the field is initialized empty and gets default value after the first offer sync | ||
await expect(this.youPayInput).not.toHaveValue(''); | ||
await this.selectCountryOfResidence(country); | ||
await this.selectFiatCurrency(currency); | ||
await this.youPayInput.fill(amount); | ||
//Warning: Bug #16054, as a workaround we wait for offer sync after setting the amount | ||
await this.waitForOffersSyncToFinish(); | ||
}; | ||
|
||
confirmTrade = async () => { | ||
await expect(this.modal).toBeVisible(); | ||
await this.buyTermsConfirmButton.click(); | ||
await this.confirmOnTrezorButton.click(); | ||
await expect(this.confirmOnDevicePrompt).toBeVisible(); | ||
await TrezorUserEnvLink.pressYes(); | ||
await expect(this.confirmOnDevicePrompt).not.toBeVisible(); | ||
}; | ||
|
||
readBestOfferValues = async () => { | ||
await expect(this.bestOfferAmount).not.toHaveText('0 BTC'); | ||
const amount = await this.bestOfferAmount.textContent(); | ||
const provider = await this.bestOfferProvider.textContent(); | ||
if (!amount || !provider) { | ||
throw new Error( | ||
`Test was not able to extract amount or provider from the page. Amount: ${amount}, Provider: ${provider}`, | ||
); | ||
} | ||
|
||
return { amount, provider }; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.