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 #2138

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

test #2138

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
23 changes: 9 additions & 14 deletions e2e-tests/playwright/e2e/catalog-scaffolded-from-link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,29 @@ test.describe.serial("Link Scaffolded Templates to Catalog Items", () => {
await uiHelper.openSidebar("Catalog");
await uiHelper.clickByDataTestId("user-picker-all");
await uiHelper.searchInputPlaceholder("scaffoldedfromlink-\n");
await clickOnScaffoldedFromLink();
await catalogImport.clickOnScaffoldedFromLink();

await uiHelper.clickTab("Dependencies");

// Define selectors for labels and nodes
const labelSelector = 'g[data-testid="label"]'; // Selector for labels
const nodeSelector = 'g[data-testid="node"]'; // Selector for nodes

await page.waitForSelector(labelSelector);
await page.waitForSelector(nodeSelector);
// Verify text inside the 'label' selector
await uiHelper.verifyTextInSelector(labelSelector, "ownerOf");
await uiHelper.verifyTextInSelector(labelSelector, "/ ownedBy");
await uiHelper.verifyTextInSelector(labelSelector, "scaffoldedFrom");
await catalogImport.verifyTextInSelector(labelSelector, "ownerOf");
await catalogImport.verifyTextInSelector(labelSelector, "/ ownedBy");
await catalogImport.verifyTextInSelector(labelSelector, "scaffoldedFrom");

// Verify text inside the 'node' selector
await uiHelper.verifyPartialTextInSelector(
await catalogImport.verifyTextInSelector(
nodeSelector,
reactAppDetails.componentPartialName,
false
);

await uiHelper.verifyTextInSelector(
await catalogImport.verifyTextInSelector(
nodeSelector,
"Create React App Template",
);
Expand Down Expand Up @@ -145,12 +148,4 @@ test.describe.serial("Link Scaffolded Templates to Catalog Items", () => {
await page.close();
});

async function clickOnScaffoldedFromLink() {
const selector =
'a[href*="/catalog/default/component/test-scaffoldedfromlink-"]';
await page.locator(selector).first().waitFor({ state: "visible" });
const link = await page.locator(selector).first();
await expect(link).toBeVisible();
await link.click();
}
});
53 changes: 53 additions & 0 deletions e2e-tests/playwright/support/pages/catalog-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,58 @@ export class CatalogImport {
await expect(this.page.getByTestId("code-snippet")).toContainText(text);
await this.uiHelper.clickButton("Close");
}

async clickOnScaffoldedFromLink() {
const selector =
'a[href*="/catalog/default/component/test-scaffoldedfromlink-"]';
await this.page.locator(selector).first().waitFor({ state: "visible" });
const link = this.page.locator(selector).first();
await expect(link).toBeVisible();
await link.click();
}

async verifyTextInSelector(
selector: string,
expectedText: string,
exactMatch: boolean = true,
) {
const elements = this.page.locator(selector);
const count = await elements.count();

for (let i = 0; i < count; i++) {
const element = elements.nth(i);

await element.waitFor({ state: 'visible', timeout: 10000 });

const textContent = await element.textContent();

if (textContent) {
const isMatch = exactMatch
? textContent.trim() === expectedText.trim()
: textContent.includes(expectedText);

if (isMatch) {
expect(textContent).toContain(expectedText); // Playwright assertion
console.log(
`Text "${expectedText}" verified successfully in selector: ${selector}`,
);
return;
}
}
}

// If no matching element was found, it throws an error directly
const allTextContent = await elements.allTextContents();
console.error(
`Verification failed for text: Expected "${expectedText}". Selector content: ${allTextContent.join(", ")}`,
);
throw new Error(
exactMatch
? `Expected exact text "${expectedText}" not found in selector "${selector}".`
: `Expected partial text "${expectedText}" not found in selector "${selector}".`,
);
}

}

export class BackstageShowcase {
Expand Down Expand Up @@ -145,4 +197,5 @@ export class BackstageShowcase {
await this.uiHelper.verifyRowsInTable([allPRs[i].title], false);
}
}

}
101 changes: 47 additions & 54 deletions e2e-tests/playwright/utils/ui-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,60 +218,53 @@ export class UIhelper {
await expect(elementLocator).toBeVisible();
}

async verifyTextInSelector(selector: string, expectedText: string) {
const elementLocator = this.page
.locator(selector)
.getByText(expectedText, { exact: true });

try {
await elementLocator.waitFor({ state: "visible", timeout: 10000 });
const actualText = (await elementLocator.textContent()) || "No content";

if (actualText.trim() !== expectedText.trim()) {
console.error(
`Verification failed for text: Expected "${expectedText}", but got "${actualText}"`,
);
throw new Error(
`Expected text "${expectedText}" not found. Actual content: "${actualText}".`,
);
}
console.log(
`Text "${expectedText}" verified successfully in selector: ${selector}`,
);
} catch (error) {
const allTextContent = await this.page
.locator(selector)
.allTextContents();
console.error(
`Verification failed for text: Expected "${expectedText}". Selector content: ${allTextContent.join(", ")}`,
);
throw error;
}
}

async verifyPartialTextInSelector(selector: string, partialText: string) {
try {
const elements = await this.page.locator(selector);
const count = await elements.count();

for (let i = 0; i < count; i++) {
const textContent = await elements.nth(i).textContent();
if (textContent && textContent.includes(partialText)) {
console.log(
`Found partial text: ${partialText} in element: ${textContent}`,
);
return;
}
}

throw new Error(
`Verification failed: Partial text "${partialText}" not found in any elements matching selector "${selector}".`,
);
} catch (error) {
console.error(error.message);
throw error;
}
}
// async verifyTextInSelector(selector: string, expectedText: string) {
// const elementLocator = this.page
// .locator(selector)
// .getByText(expectedText, { exact: true });
//
// try {
// await elementLocator.waitFor({ state: "visible", timeout: 10000 });
// const actualText = (await elementLocator.textContent()) || "No content";
//
// if (actualText.trim() !== expectedText.trim()) {
// console.error(
// `Verification failed for text: Expected "${expectedText}", but got "${actualText}"`,
// );
// throw new Error(
// `Expected text "${expectedText}" not found. Actual content: "${actualText}".`,
// );
// }
// console.log(
// `Text "${expectedText}" verified successfully in selector: ${selector}`,
// );
// } catch (error) {
// const allTextContent = await this.page
// .locator(selector)
// .allTextContents();
// console.error(
// `Verification failed for text: Expected "${expectedText}". Selector content: ${allTextContent.join(", ")}`,
// );
// throw error;
// }
// }
//
// async verifyPartialTextInSelector(selector: string, partialText: string) {
// const elements = this.page.locator(selector);
// const count = await elements.count();
//
// for (let i = 0; i < count; i++) {
// const textContent = await elements.nth(i).textContent();
// if (textContent?.includes(partialText)) {
// expect(textContent).toContain(partialText);
// return;
// }
// }
//
// throw new Error(
// `Expected to find at least one element containing partial text "${partialText}" within selector "${selector}", but none were found.`,
// );
// }

async verifyColumnHeading(
rowTexts: string[] | RegExp[],
Expand Down
Loading