-
Notifications
You must be signed in to change notification settings - Fork 197
feat(e2e): add tests for GitHub plugins (PR statistics & security insights) #2998
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
base: main
Are you sure you want to change the base?
feat(e2e): add tests for GitHub plugins (PR statistics & security insights) #2998
Conversation
Hi @guyoron1. Thanks for your PR. I'm waiting for a redhat-developer member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
The image is available at: |
/ok-to-test |
my_changes.diff
Outdated
@@ -0,0 +1,66 @@ | |||
diff --git a/.ibm/pipelines/value_files/values_showcase.yaml b/.ibm/pipelines/value_files/values_showcase.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you commit this file?
e2e-tests/playwright/utils/common.ts
Outdated
await githubPage.fill('input[name="login"]', username); | ||
await githubPage.fill('input[name="password"]', password); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can reuse uiHelper.fillTextInputByLabel for all those page.fill
await uiHelper.openSidebar("Catalog"); | ||
// Step 3: Search and click 'Backstage Showcase' | ||
await page.fill('input[placeholder="Search"]', repoName); | ||
await page.waitForSelector('a:has-text("Backstage Showcase")', { timeout: 20000 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await catalog.goToByName("Backstage Showcase");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export class CatalogHelper {
private page: Page;
private uiHelper: UIhelper;
constructor(page: Page) {
this.page = page;
this.uiHelper = new UIhelper(page);
}
async goToByName(name: string): Promise {
await this.uiHelper.openSidebar("Catalog");
await this.page.fill('input[placeholder="Search"]', name);
await this.page.waitForSelector(a:has-text("${name}")
, { timeout: 20000 });
await this.uiHelper.clickLink(name);
}
}
and then it would be easier to maintain and much clearer
await page.fill('input[placeholder="Search"]', repoName); | ||
await page.waitForSelector('a:has-text("Backstage Showcase")', { timeout: 20000 }); | ||
await uiHelper.clickLink(repoName); | ||
await page.waitForLoadState("networkidle"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use await page.waitForLoadState("networkidle");
// Step 5: Click 'Sign in' inside the PR statistics card | ||
await uiHelper.clickBtnInCard('GitHub Pull Requests Statistics', 'Sign in', true); | ||
// Wait for the login modal to appear | ||
const modalLoginButton = page.locator('button:has-text("Log in")'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uiHelper.isBtnVisible
uiHelper.getButtonSelector
e2e-tests/playwright/utils/common.ts
Outdated
]); | ||
await githubPage.waitForLoadState(); | ||
await githubPage.waitForSelector('input[name="login"]', { timeout: 30000 }); | ||
await githubPage.fill('input[name="login"]', username); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uiHelper.fillTextInputByLabel
e2e-tests/playwright/utils/common.ts
Outdated
|
||
// Handle 2FA | ||
let otpSelector = null; | ||
if (await githubPage.isVisible('input[name="otp"]', { timeout: 10000 }).catch(() => false)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can use uiHelper.isElementVisible
|
||
async GetChildGroupsDisplayed(): Promise<string[]> { | ||
await this.page.waitForSelector("p:has-text('Child Groups')"); | ||
const parent = await this.page |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private async getGroupLinksByLabel(label: string): Promise<string[]> {
const section = this.page.locator(`p:has-text("${label}")`).first();
await section.waitFor({ state: "visible" });
return await section.locator("..").locator("a").allInnerTexts();
}
async getParentGroupsDisplayed(): Promise<string[]> {
return await this.getGroupLinksByLabel("Parent Group");
}
async getChildGroupsDisplayed(): Promise<string[]> {
return await this.getGroupLinksByLabel("Child Groups");
}
.filter((u) => u.spec.profile && u.spec.profile.displayName) | ||
.map((u) => u.spec.profile.displayName); | ||
LOGGER.info( | ||
`Checking ${JSON.stringify(catalogUsersDisplayNames)} contains users ${JSON.stringify(users)}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type EntityWithDisplay = { spec?: { profile?: { displayName?: string } } };
export class CatalogVerifier {
private api: APIHelper;
constructor(token: string) {
this.api = new APIHelper();
this.api.UseStaticToken(token);
}
async assertUsersInCatalog(expected: string[]): Promise<void> {
await this.assertEntities(
() => this.api.getAllCatalogUsersFromAPI(),
expected,
'users',
);
}
async assertGroupsInCatalog(expected: string[]): Promise<void> {
await this.assertEntities(
() => this.api.getAllCatalogGroupsFromAPI(),
expected,
'groups',
);
}
private async assertEntities(
fetch: () => Promise<{ items?: EntityWithDisplay[] }>,
expected: string[],
label: string,
): Promise<void> {
const { items = [] } = await fetch();
expect(items.length).toBeGreaterThan(0);
const displayNames = items
.flatMap(e => e.spec?.profile?.displayName ?? []);
const catalogSet = new Set(displayNames);
const missing = expected.filter(name => !catalogSet.has(name));
LOGGER.info(
`Catalog ${label}: [${displayNames.join(', ')}] – expecting [${expected.join(', ')}]`,
);
expect(missing, `Missing ${label}: ${missing.join(', ')}`).toHaveLength(0);
}
}
e2e-tests/playwright/utils/common.ts
Outdated
const secret = secrets[userid]; | ||
if (!secret) { | ||
throw new Error("Invalid User ID"); | ||
async githubLoginPopUpModal(context, username, password, otpSecret) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async function githubLoginPopUpModal(
context: BrowserContext,
username: string,
password: string,
otpSecret: string
): Promise {
const [githubPage] = await Promise.all([
context.waitForEvent('page'),
]);
await githubPage.waitForLoadState('domcontentloaded');
await githubPage.fill('input[name="login"]', username);
await githubPage.fill('input[name="password"]', password);
await githubPage.click('button[type="submit"], input[type="submit"]');
const otpSelector = await findOtpSelector(githubPage);
if (otpSelector) {
if (githubPage.isClosed()) return;
await githubPage.waitForSelector(otpSelector, { timeout: 10000 });
if (githubPage.isClosed()) return;
const otp = authenticator.generate(otpSecret);
await githubPage.fill(otpSelector, otp);
if (githubPage.isClosed()) return;
await Promise.race([
githubPage.waitForEvent('close', { timeout: 20000 }),
githubPage.click('button[type="submit"], input[type="submit"]'),
]);
} else {
await githubPage.waitForEvent('close', { timeout: 20000 });
}
}
async function findOtpSelector(page: Page): Promise<string | null> {
const selectors = ['input[name="otp"]', '#app_totp'];
for (const selector of selectors) {
try {
if (await page.isVisible(selector, { timeout: 5000 })) {
return selector;
}
} catch {
// Ignore visibility timeout errors
}
}
return null;
}
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -213,6 +213,9 @@ global: | |||
disabled: false | |||
- package: ./dynamic-plugins/dist/red-hat-developer-hub-backstage-plugin-global-floating-action-button | |||
disabled: false | |||
# Enable Security Insights plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Please remove this comment. It's clear that it's enabling security insights plugin based on the name of the imported plugin name
e2e-tests/package.json
Outdated
"prettier": "3.5.3", | ||
"typescript": "5.8.3" | ||
}, | ||
"dependencies": { | ||
"@azure/identity": "4.9.1", | ||
"@backstage/catalog-model": "^1.7.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need to import this library. You are importing this lib only to type a field as far as I could see
|
||
await common.loginAsKeycloakUser(process.env.GH_USER_ID, process.env.GH_USER_PASS); | ||
await uiHelper.openSidebar("Catalog"); | ||
await page.fill('input[placeholder="Search"]', repoName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use uiHelper.searchInputPlaceholder. Please replace all occurrences with it.
e2e-tests/playwright/utils/common.ts
Outdated
await githubPage.waitForLoadState('domcontentloaded'); | ||
|
||
await githubPage.getByLabel('Username or email address').fill(username); | ||
await githubPage.getByLabel('Password').fill(password); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uiHelper.fillTextInputByLabel replace all occurrences with it
|
||
await githubPage.getByLabel('Username or email address').fill(username); | ||
await githubPage.getByLabel('Password').fill(password); | ||
await githubPage.click('button[type="submit"], input[type="submit"]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uiHelper.clickButton replace all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update this one
The image is available at: |
1925ab6
to
dcc2cf2
Compare
e2e-tests/playwright/utils/common.ts
Outdated
const [githubPage] = await Promise.all([ | ||
context.waitForEvent('page'), | ||
]); | ||
await githubPage.waitForLoadState('domcontentloaded'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to use specific locators instead of load state.
for example: await page.waitForSelector('text=something');
|
||
await githubPage.getByLabel('Username or email address').fill(username); | ||
await githubPage.getByLabel('Password').fill(password); | ||
await githubPage.click('button[type="submit"], input[type="submit"]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update this one
if (githubPage.isClosed()) return; | ||
await Promise.race([ | ||
githubPage.waitForEvent('close', { timeout: 20000 }), | ||
githubPage.click('button[type="submit"], input[type="submit"]'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uiHelper.clickButton
e2e-tests/playwright/utils/common.ts
Outdated
for (const selector of selectors) { | ||
try { | ||
if (await page.isVisible(selector, { timeout: 5000 })) { | ||
return selector; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The silent catch could lead to false positives. If a timeout or other issue occurs, it gets ignored and the function may return null even when something went wrong. Might be worth adding logging or refining the error handling.
/**
* Looks for an OTP input field and returns its selector.
* Throws if no field becomes visible within the overall timeout.
*/
async function findOtpSelector(page: Page): Promise<string> {
const selectors = ['input[name="otp"]', '#app_totp'];
for (const sel of selectors) {
try {
// Wait until the element is visible (up to 10 s)
await page.locator(sel).waitFor({ state: 'visible', timeout: 10_000 });
return sel; // Found a visible OTP field
} catch (err) {
// Timeout for this selector — log and try the next one
console.debug(`Selector ${sel} not visible yet, continuing…`);
}
}
// None of the selectors became visible in time
throw new Error('OTP field not found on the page within 10 s');
}
The image is available at: |
The image is available at: |
/test e2e-tests |
125e042
to
82bc0bf
Compare
The image is available at: |
/ok-to-test |
/test e2e-tests |
82bc0bf
to
f7c8913
Compare
/test e2e-tests |
f504e33
to
940639a
Compare
The image is available at: |
/test e2e-tests |
940639a
to
f6f4286
Compare
The image is available at: |
/test e2e-tests |
42f4517
to
f6f4286
Compare
…lugins - Created Playwright spec files for GitHub PR statistics and security insights plugins - Enabled the plugins in values_showcase.yaml - Added new GitHub sign-in logic using popup modal
…login, address review feedback
…omments: use only UIhelper methods for Backstage UI, robust popup handling, CatalogVerifier, and code clarity
6d3bcf0
to
1b0406c
Compare
The image is available at: |
The image is available at: |
@guyoron1: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Description
This PR adds end-to-end tests for two GitHub-related plugins in RHDH:
Key changes:
e2e-tests/playwright/e2e/plugins/github-pull-requests.spec.ts
: Tests PR statistics functionality including metrics like average PR time, merge ratio, etc.e2e-tests/playwright/e2e/plugins/github-security-insights.spec.ts
: Tests security insights functionality including Dependabot alerts severity levelscommon.ts
with improved GitHub authentication:githubLoginPopUpModal
function to handle GitHub login in a popup contextThe new authentication approach improves test reliability by handling the GitHub login flow in a popup modal without navigating away from the main application context.
Which issue(s) does this PR fix
PR acceptance criteria
How to test changes / Special notes to the reviewer
To run the tests locally:
The tests verify:
GitHub PR Statistics:
Security Insights: