-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Playwright tests with image comparison for profile page --------- Co-authored-by: Farhad Alizada <falizada@microsoft.com>
- Loading branch information
Showing
47 changed files
with
1,552 additions
and
895 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
retries: 2, | ||
use: { | ||
video: 'retain-on-failure' | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"environment": "validation", | ||
"isLocalRun": true, | ||
"root": "http://localhost:8080", | ||
"urls": { | ||
"home": "/", | ||
|
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Locator, Page } from "playwright"; | ||
|
||
export class HomePageWidget { | ||
constructor(private readonly page: Page) { } | ||
|
||
public async waitRuntimeInit(): Promise<void> { | ||
await this.getWelcomeMessageLocator().waitFor(); | ||
} | ||
|
||
public getWelcomeMessageLocator(): Locator { | ||
return this.page.locator("h1 span").filter({ hasText: "Welcome to Contoso!" }); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,24 @@ | ||
import { Page } from "puppeteer"; | ||
import { Page } from "playwright"; | ||
|
||
export class ProductseWidget { | ||
constructor(private readonly page: Page) { } | ||
|
||
public async products(): Promise<void> { | ||
await this.page.waitForSelector("product-list-runtime div.table div.table-body div.table-row"); | ||
public async waitRuntimeInit(): Promise<void> { | ||
await this.page.locator("product-list-runtime").waitFor(); | ||
} | ||
|
||
public async getProductsCount(): Promise<number | undefined> { | ||
return await this.page.evaluate(() => | ||
document.querySelector("product-list-runtime div.table div.table-body div.table-row")?.parentElement?.childElementCount | ||
); | ||
public async getProductByName(productName: string): Promise<string | null> { | ||
return await this.page.locator('product-list-runtime div.table div.table-body div.table-row a').filter({ hasText: productName }).first().innerText(); | ||
} | ||
|
||
public async goToProductPage(baseUrl, productId: string): Promise<void>{ | ||
await this.page.goto(`${baseUrl}/product#product=${productId}`, { waitUntil: 'domcontentloaded' }); | ||
} | ||
|
||
public async subscribeToProduct(baseUrl, productId: string, subscriptionName: string): Promise<void> { | ||
await this.goToProductPage(baseUrl, productId); | ||
await this.page.waitForSelector("product-subscribe-runtime form button"); | ||
await this.page.type("product-subscribe-runtime form input", subscriptionName); | ||
await this.page.click("product-subscribe-runtime form button"); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,86 @@ | ||
import { Page } from "puppeteer"; | ||
import { Locator, Page } from "playwright"; | ||
|
||
export class ProfileWidget { | ||
constructor(private readonly page: Page) { } | ||
|
||
public async profile(): Promise<void> { | ||
public async waitRuntimeInit(): Promise<void> { | ||
await this.page.waitForSelector("profile-runtime .row"); | ||
await this.page.waitForSelector("subscriptions-runtime .table-row"); | ||
} | ||
|
||
public async getUserEmail(): Promise<string | undefined | null> { | ||
await this.page.waitForSelector("[data-bind='text: user().email']"); | ||
return await this.page.evaluate(() =>document.querySelector("[data-bind='text: user().email']")?.textContent); | ||
public getUserEmailLocator(): Locator { | ||
return this.page.locator("profile-runtime [data-bind='text: user().email']").first(); | ||
} | ||
|
||
public async getUserEmail(): Promise<string> { | ||
return await this.getUserEmailLocator().innerText(); | ||
} | ||
|
||
public getUserFirstNameLocator(): Locator { | ||
return this.page.locator("profile-runtime [data-bind='text: user().firstName']").first(); | ||
} | ||
|
||
public async getUserFirstName(): Promise<string > { | ||
return await this.getUserFirstNameLocator().innerText(); | ||
} | ||
|
||
public getUserLastNameLocator(): Locator { | ||
return this.page.locator("profile-runtime [data-bind='text: user().lastName']").first(); | ||
} | ||
|
||
public async getUserLastName(): Promise<string > { | ||
return await this.getUserLastNameLocator().innerText(); | ||
} | ||
|
||
public getUserRegistrationDataLocator(): Locator { | ||
return this.page.locator("profile-runtime [data-bind='text: registrationDate']").first(); | ||
} | ||
|
||
public async getUserRegistrationDate(): Promise<string> { | ||
return await this.getUserRegistrationDataLocator().innerText(); | ||
} | ||
|
||
public getSubscriptionRow(subscriptionName: string): Locator { | ||
return this.page.locator("subscriptions-runtime div.table div.table-body div.table-row", { has: this.page.locator("div.row span[data-bind='text: model.name']").filter({ hasText: subscriptionName })}); | ||
} | ||
|
||
public async getSubscriptioPrimarynKey(subscriptionName: string): Promise<string | null> { | ||
var subscriptionRow = this.getSubscriptionRow(subscriptionName); | ||
const primaryKeyElement = subscriptionRow.locator('code[data-bind="text: primaryKey"]').first(); | ||
return await primaryKeyElement.textContent(); | ||
} | ||
|
||
public async getSubscriptioSecondarynKey(subscriptionName: string): Promise<string | null> { | ||
var subscriptionRow = this.getSubscriptionRow(subscriptionName); | ||
const primaryKeyElement = subscriptionRow?.locator('code[data-bind="text: secondaryKey"]').first(); | ||
return await primaryKeyElement.textContent(); | ||
} | ||
|
||
public async togglePrimarySubscriptionKey(subscriptionName: string): Promise<void> { | ||
var subscriptionRow = this.getSubscriptionRow(subscriptionName); | ||
await subscriptionRow?.locator("a.btn-link[aria-label='Show primary key']", { hasText: "Show" }).click(); | ||
} | ||
|
||
public async toggleSecondarySubscriptionKey(subscriptionName: string): Promise<void> { | ||
var subscriptionRow = this.getSubscriptionRow(subscriptionName); | ||
await subscriptionRow?.locator("a.btn-link[aria-label='Show Secondary key']", { hasText: "Show" }).click(); | ||
} | ||
|
||
public async getListOfLocatorsToHide(): Promise<Locator[] | undefined> { | ||
const primaryKeyElements = await this.page.locator('code[data-bind="text: primaryKey"]').all(); | ||
const secondaryKeyElements = await this.page.locator('code[data-bind="text: secondaryKey"]').all(); | ||
const productNames = this.page.locator('span[data-bind="text: model.productName"]'); | ||
const subscriptionNames = this.page.locator('span[data-bind="text: model.name"]'); | ||
const subscriptionStartDates = this.page.locator('span[data-bind="text: $parent.timeToString(model.startDate)"]'); | ||
return primaryKeyElements.concat(secondaryKeyElements).concat(productNames).concat(this.getUserProfileData()).concat(subscriptionNames).concat(subscriptionStartDates); | ||
} | ||
|
||
public getUserProfileData(): Locator[] { | ||
return [ | ||
this.getUserEmailLocator(), | ||
this.getUserFirstNameLocator(), | ||
this.getUserLastNameLocator(), | ||
this.getUserRegistrationDataLocator() | ||
]; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { Page } from "puppeteer"; | ||
import { Page } from "playwright"; | ||
import { User } from "../../mocks/collection/user"; | ||
|
||
export class SignInBasicWidget { | ||
constructor(private readonly page: Page) { } | ||
constructor(private readonly page: Page, private readonly configuration: object) { } | ||
|
||
public async signInWithBasic(): Promise<void> { | ||
await this.page.type("#email", "foo@bar.com"); | ||
await this.page.type("#password", "password"); | ||
public async signInWithBasic(userInfo: User): Promise<void> { | ||
await this.page.goto(this.configuration['urls']['signin'], { waitUntil: 'domcontentloaded' }); | ||
|
||
await this.page.type("#email", userInfo.email); | ||
await this.page.type("#password", userInfo.password); | ||
await this.page.click("#signin"); | ||
await this.page.waitForNavigation({ waitUntil: "domcontentloaded" }); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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.