105 lines
2.7 KiB
TypeScript
105 lines
2.7 KiB
TypeScript
|
import { Page, Locator, expect } from "@playwright/test"
|
||
|
|
||
|
export class CredentialRequestPage {
|
||
|
readonly page: Page
|
||
|
readonly primaryTitle: Locator
|
||
|
readonly secondaryTitle: Locator
|
||
|
readonly drowdownDid: Locator
|
||
|
readonly dropdownCredential: Locator
|
||
|
readonly requestButton: Locator
|
||
|
readonly cancelButton: Locator
|
||
|
|
||
|
public constructor(page: Page) {
|
||
|
this.page = page;
|
||
|
this.primaryTitle = this.page.getByRole('heading', { name: 'My wallet' })
|
||
|
this.secondaryTitle = this.page.getByRole('heading', { name: ' Credential Request' })
|
||
|
this.drowdownDid = this.page.getByLabel('Did')
|
||
|
this.dropdownCredential = this.page.getByLabel('Credential')
|
||
|
this.requestButton = this.page.getByRole('button', { name: 'Request' })
|
||
|
this.cancelButton = this.page.getByRole('link', { name: 'Cancel' })
|
||
|
|
||
|
}
|
||
|
|
||
|
async getPrimaryTitle() {
|
||
|
try {
|
||
|
return await this.primaryTitle.innerText();
|
||
|
} catch (error) {
|
||
|
console.error("Failed to get primary title:", error);
|
||
|
throw error;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async getSecondaryTitle() {
|
||
|
try {
|
||
|
return await this.secondaryTitle.innerText();
|
||
|
} catch (error) {
|
||
|
console.error("Failed to get secondary title:", error);
|
||
|
throw error;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async getDropdownDid() {
|
||
|
try {
|
||
|
return this.drowdownDid;
|
||
|
} catch (error) {
|
||
|
console.error("Failed to get dropdown DID value:", error);
|
||
|
throw error;
|
||
|
}
|
||
|
}
|
||
|
async getDropdownCredential() {
|
||
|
try {
|
||
|
return this.dropdownCredential;
|
||
|
} catch (error) {
|
||
|
console.error("Failed to get dropdown Credential value:", error);
|
||
|
throw error;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async getRequestButton() {
|
||
|
try {
|
||
|
return this.requestButton;
|
||
|
} catch (error) {
|
||
|
console.error("Failed to get the 'Request' button:", error);
|
||
|
throw error;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async getCancelButton() {
|
||
|
try {
|
||
|
return this.cancelButton;
|
||
|
} catch (error) {
|
||
|
console.error("Failed to get the 'Cancel' button:", error);
|
||
|
throw error;
|
||
|
}
|
||
|
}
|
||
|
async clickRequestButton() {
|
||
|
try {
|
||
|
(await this.getRequestButton()).click();
|
||
|
} catch (error) {
|
||
|
console.error("Failed to click request button: ", error);
|
||
|
throw error;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async clickCancelButton() {
|
||
|
try {
|
||
|
(await this.getCancelButton()).click();
|
||
|
} catch (error) {
|
||
|
console.error("Failed to click cancel did: ", error);
|
||
|
throw error;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async requestCredential(did: string, credential: string) {
|
||
|
try {
|
||
|
console.log("DId", did);
|
||
|
(await this.getDropdownDid()).selectOption({ label: did });
|
||
|
(await this.getDropdownCredential()).selectOption({ label: credential });
|
||
|
(await this.clickRequestButton());
|
||
|
} catch (error) {
|
||
|
console.error("Failed to request a credential: ", error);
|
||
|
throw error;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|