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

test: Enhance Snap home page #29765

Merged
merged 6 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 26 additions & 0 deletions test/e2e/page-objects/pages/snap-list-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ class SnapListPage {
// this selector needs to be combined with snap name to be unique.
private readonly snapListItem = '.snap-list-item';

private readonly defaultSnap = {
Copy link
Member

Choose a reason for hiding this comment

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

"Default Snap" should probably be named "Home Page Snap" as we add more Snaps to this page object

text: 'Home Page Example Snap',
tag: 'p',
};

private readonly title = {
hjetpoluru marked this conversation as resolved.
Show resolved Hide resolved
text: 'Welcome to my Snap home page!',
tag: 'p',
};

constructor(driver: Driver) {
this.driver = driver;
}
Expand Down Expand Up @@ -75,6 +85,22 @@ class SnapListPage {
console.log('Verifying no snaps is installed for current account');
await this.driver.waitForSelector(this.noSnapInstalledMessage);
}

async clickDefaultSnap(): Promise<void> {
console.log('Clicking default snap');
await this.driver.waitForSelector(this.defaultSnap);
await this.driver.clickElement(this.defaultSnap);
}

async check_title(): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
async check_title(): Promise<void> {
async checkHomePageTitle(): Promise<void> {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @hmalik88 will address them

try {
await this.driver.waitForSelector(this.title);
Copy link
Contributor

Choose a reason for hiding this comment

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

The waitForSelector throws when the element is not located, the try catch is a bit redundant here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, agreed with you and I will make the change.

} catch (e) {
console.log('Timeout while waiting for title to be loaded', e);
throw e;
}
console.log('Title is loaded');
}
}

export default SnapListPage;
56 changes: 44 additions & 12 deletions test/e2e/page-objects/pages/test-snaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ export class TestSnaps {

private readonly dialogsSnapConfirmationButton = '#sendConfirmationButton';

private readonly dialogConnectButton = {
text: 'Connect',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we need both text and data-test-id as the selector? Just the data-testid should be enough right?

Copy link
Contributor Author

@hjetpoluru hjetpoluru Jan 28, 2025

Choose a reason for hiding this comment

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

Thanks for pointing that out. The reason I used it was for readability as the same [data-testid="page-container-footer-next"] is used for the different cases(Connect, Ok, Confirm).

Screenshot 2025-01-28 at 9 22 32 AM

tag: 'button',
css: '[data-testid="page-container-footer-next"]',
};

private readonly dialogConfirmButton = {
text: 'Confirm',
tag: 'button',
css: '[data-testid="page-container-footer-next"]',
};

private readonly dialogOkButton = {
text: 'OK',
tag: 'button',
css: '[data-testid="page-container-footer-next"]',
};

private readonly connectHomePage = '#connecthomepage';

constructor(driver: Driver) {
this.driver = driver;
}
Expand All @@ -36,21 +56,33 @@ export class TestSnaps {
async completeSnapInstallConfirmation() {
await this.driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await this.driver.clickElement({
text: 'Connect',
tag: 'button',
});
await this.driver.waitForSelector(this.dialogConnectButton);

await this.driver.clickElement(this.dialogConnectButton);

await this.driver.waitForSelector(this.dialogConfirmButton);

await this.driver.clickElement({
text: 'Confirm',
tag: 'button',
});
await this.driver.clickElement(this.dialogConfirmButton);

await this.driver.clickElement({
text: 'OK',
tag: 'button',
});
await this.driver.waitForSelector(this.dialogOkButton);

await this.driver.clickElement(this.dialogOkButton);

await this.driver.switchToWindowWithTitle(WINDOW_TITLES.TestSnaps);
}

async clickConnectHomePage() {
// find and scroll to the homepage snap
const connectHomePageButton = await this.driver.findElement(
this.connectHomePage,
);
await this.driver.scrollToElement(connectHomePageButton);

// added delay for firefox
await this.driver.delayFirefox(1000);

// wait for and click connect
await this.driver.waitForSelector(this.connectHomePage);
await this.driver.clickElement(this.connectHomePage);
}
}
108 changes: 0 additions & 108 deletions test/e2e/snaps/test-snap-homepage.spec.js

This file was deleted.

41 changes: 41 additions & 0 deletions test/e2e/snaps/test-snap-homepage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Suite } from 'mocha';
import { Driver } from '../webdriver/driver';
import { withFixtures, WINDOW_TITLES } from '../helpers';
import FixtureBuilder from '../fixture-builder';
import { TestSnaps } from '../page-objects/pages/test-snaps';
import HeaderNavbar from '../page-objects/pages/header-navbar';
import SnapListPage from '../page-objects/pages/snap-list-page';
import { loginWithoutBalanceValidation } from '../page-objects/flows/login.flow';

describe('Test Snap Homepage', function (this: Suite) {
it('tests snap home page functionality', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder().build(),
title: this.test?.fullTitle(),
},
async ({ driver }: { driver: Driver }) => {
await loginWithoutBalanceValidation(driver);

const testSnaps = new TestSnaps(driver);
const headerNavbar = new HeaderNavbar(driver);
const snapListPage = new SnapListPage(driver);

await testSnaps.openPage();
await testSnaps.clickConnectHomePage();
await testSnaps.completeSnapInstallConfirmation();

// switch to metamask page and open the three dots menu
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);

await headerNavbar.openSnapListPage();
await snapListPage.clickDefaultSnap();

// check that the home page appears and contains the right info
await snapListPage.check_title();
},
);
});
});
Loading