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

update(playwright): add settings profile tests in playwright #77

Merged
merged 6 commits into from
Jul 12, 2024
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
3 changes: 2 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { defineConfig, devices } from "@playwright/test";
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./playwright",
testDir: "./playwright/specs",
snapshotPathTemplate: "./playwright/snapshots/{testFilePath}/{arg}{ext}",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
Expand Down
9 changes: 6 additions & 3 deletions playwright/PageObjects/LoginPin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ export class LoginPinPage extends MainPage {
}

async enterPin(pin: string) {
for (const digit of pin.split("")) {
await this.page.locator(`[data-cy='button-pin-${digit}']`).click();
}
await this.page.keyboard.type(pin, { delay: 100 });
}

async enterDefaultPin() {
await this.page.keyboard.type("123456", { delay: 100 });
await this.pinButtonConfirm.click();
}

async goToPinSettings() {
Expand Down
63 changes: 63 additions & 0 deletions playwright/PageObjects/MainPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ export default class MainPage {
this.toastNotificationText = page.getByTestId("toast-notification-text");
}

async assertInputTextSelected(selector: string) {
// Locate the input field
const inputField = this.page.locator(selector);

// Get the value of the input field
await inputField.click();
const inputValue = await inputField.inputValue();

// Explicitly select the text in the input field
await this.page.evaluate((selector) => {
const input = document.querySelector(selector) as HTMLInputElement;
input.select();
}, selector);

// Evaluate the selection start and end
const selectionRange = await this.page.evaluate((selector) => {
const input = document.querySelector(selector) as HTMLInputElement;
return {
selectionStart: input.selectionStart,
selectionEnd: input.selectionEnd,
};
}, selector);

// Assert that the whole text is selected
expect(selectionRange.selectionStart).toBe(0);
expect(selectionRange.selectionEnd).toBe(inputValue.length);
}

async ensureSidebarIsDisplayed() {
const hasVerticalClass: boolean = await this.navigationBar.evaluate((el) =>
el.classList.contains("vertical"),
Expand Down Expand Up @@ -93,4 +121,39 @@ export default class MainPage {
return await navigator.clipboard.readText();
});
}

async validatePseudoElementContent(
selector: string,
expectedContent: string,
) {
// Hover over the element to trigger the pseudo-element
await this.page.hover(selector);

// Evaluate the content of the ::after pseudo-element
const content = await this.page.evaluate((selector) => {
const element = document.querySelector(selector);
if (element) {
const style = window.getComputedStyle(element, "::after");
return style.content;
}
return null;
}, selector);

// Validate the content
expect(content).toBe(`"${expectedContent}"`);
}

async validateTooltipAttribute(
selector: string,
expectedTooltipText: string,
) {
// Locate the element that should have the data-tooltip attribute
const element = this.page.locator(selector);

// Get the value of the data-tooltip attribute
const tooltipText = await element.getAttribute("data-tooltip");

// Validate that the data-tooltip attribute has the expected value
expect(tooltipText).toBe(expectedTooltipText);
}
}
Loading
Loading