Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
Fix intermittent e2e test failure (MetaMask#7873)
Browse files Browse the repository at this point in the history
The 'can retype the seed phrase' test would fail sometimes when one of
the words in the seed phrase was a subset of another word (e.g. 'issue'
and 'tissue'). This is because the selector used to find the word
looked for the first element that contained the text, rather than an
exact match.

To simplify the selector and make it more reliable, test ids were added
to each seed phrase word. The selector now uses CSS instead of XPath,
and it only finds exact matches.

A test id was also added to the div containing the shuffled seed words
to select from, so that the chosen seed words wouldn't be selected
in place of the real target when the same word appears twice.
  • Loading branch information
Gudahtt authored and yqrashawn committed Feb 3, 2020
1 parent dfd6b78 commit 9a3fabe
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
7 changes: 5 additions & 2 deletions test/e2e/address-book.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,11 @@ describe('MetaMask', function () {
})

async function clickWordAndWait (word) {
const xpath = `//div[contains(@class, 'confirm-seed-phrase__seed-word--shuffled') and not(contains(@class, 'confirm-seed-phrase__seed-word--selected')) and contains(text(), '${word}')]`
await driver.clickElement(By.xpath(xpath))
await driver.clickElement(
By.css(
`[data-testid="seed-phrase-shuffled"] [data-testid="draggable-seed-${word}"]`
)
)
await driver.delay(tinyDelayMs)
}

Expand Down
7 changes: 5 additions & 2 deletions test/e2e/incremental-security.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,11 @@ describe('MetaMask', function () {
})

async function clickWordAndWait (word) {
const xpath = `//div[contains(@class, 'confirm-seed-phrase__seed-word--shuffled') and not(contains(@class, 'confirm-seed-phrase__seed-word--selected')) and contains(text(), '${word}')]`
await driver.clickElement(By.xpath(xpath))
await driver.clickElement(
By.css(
`[data-testid="seed-phrase-shuffled"] [data-testid="draggable-seed-${word}"]`
)
)
await driver.delay(tinyDelayMs)
}

Expand Down
7 changes: 5 additions & 2 deletions test/e2e/metamask-responsive-ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ describe('MetaMask', function () {
})

async function clickWordAndWait (word) {
const xpath = `//div[contains(@class, 'confirm-seed-phrase__seed-word--shuffled') and not(contains(@class, 'confirm-seed-phrase__seed-word--selected')) and contains(text(), '${word}')]`
await driver.clickElement(By.xpath(xpath))
await driver.clickElement(
By.css(
`[data-testid="seed-phrase-shuffled"] [data-testid="draggable-seed-${word}"]`
)
)
await driver.delay(tinyDelayMs)
}

Expand Down
7 changes: 5 additions & 2 deletions test/e2e/metamask-ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ describe('MetaMask', function () {
})

async function clickWordAndWait (word) {
const xpath = `//div[contains(@class, 'confirm-seed-phrase__seed-word--shuffled') and not(contains(@class, 'confirm-seed-phrase__seed-word--selected')) and contains(text(), '${word}')]`
await driver.clickElement(By.xpath(xpath))
await driver.clickElement(
By.css(
`[data-testid="seed-phrase-shuffled"] [data-testid="draggable-seed-${word}"]`
)
)
await driver.delay(tinyDelayMs)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ export default class ConfirmSeedPhrase extends PureComponent {
{this.renderPendingSeeds()}
{this.renderSelectedSeeds()}
</div>
<div className="confirm-seed-phrase__shuffled-seed-words">
<div
className="confirm-seed-phrase__shuffled-seed-words"
data-testid="seed-phrase-shuffled"
>
{shuffledSeedWords.map((word, index) => {
const isSelected = selectedSeedIndices.includes(index)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class DraggableSeed extends Component {
}
)}
onClick={onClick}
data-testid={`draggable-seed-${selected ? 'selected-' : ''}${word}`}
>
{word}
</div>
Expand Down

0 comments on commit 9a3fabe

Please sign in to comment.