const username = process.env.USERNAME as string;
const password = process.env.PASSWORD as string;
test.beforeEach(async ({ page }) => {
await page.goto(neo_bank_portal_login);
await page.fill('[name="username"]', username);
await page.fill('[name="password"]', password);
const submitBtnSelector = "//button[contains(@class,'MuiButtonBase-root MuiButton-root')]"
await page.waitForSelector(submitBtnSelector)
const submitBtn = await page.$(submitBtnSelector)
const isSubmitBtnEnabled = await submitBtn!.isEnabled()
if (isSubmitBtnEnabled) {
await submitBtn!.click()
}
await page.waitForLoadState("networkidle");
await page.click("//p[text()='Artifacts']");
});
test.afterEach(async ({page}) => {
await page.close();
});
test.describe("Artifacts", () => {
test.only("Redirect Artifacts", async ({page}) => {
// Artifacts Url
const url = page.url();
expect(url).toEqual("https://neo-bank-portal.dev.dcx.apps.piestory.net/dcx/artifacts")
});
}
The issue here is that when i run this test case in my local machine it always passes and it's perfectly working, i also tried playwright's codegen just to make sure i'm getting the right xpath or its locator, but when i run Gitlab's Pipeline it always results to timeout and the locator can't be found.
This is my gitlab-ci.yml
stages:
- smoke-test
tests:
stage: smoke-test
image: mcr.microsoft.com/playwright:v1.32.0-focal
script:
- npm ci
- npx playwright install --with-deps
- export const USERNAME=$CI_USERNAME
- export const PASSWORD=$CI_PASSWORD
- npx playwright test
How can i Fix the error in pipeline? I also tried adding page.waitForTimeout just to make sure the page loads before interacting with its elements
I also switched the test browser from chromium to firefox, but there's no luck
Temporarily i'm storing my creds.env here
UPDATE:
So to simplify what i've been trying to do, i refactored the code
test.beforeEach(async ({ page }) => {
await page.goto(neo_bank_portal_login);
const username_field = await page.waitForSelector("//input[@class='MuiInputBase-input MuiInput-input']");
await username_field.fill(username);
const password_field = await page.waitForSelector("(//input[contains(@class,'MuiInputBase-input MuiInput-input')])[2]");
await password_field.fill(password);
const submitBtnSelector = "//button[contains(@class,'MuiButtonBase-root MuiButton-root')]"
await page.waitForSelector(submitBtnSelector)
const submitBtn = await page.$(submitBtnSelector)
const isSubmitBtnEnabled = await submitBtn!.isEnabled()
if (isSubmitBtnEnabled) {
await submitBtn!.click()
}
});
test.only("Redirect Artifacts", async ({page}) => {
const artifacts_sec = await page.waitForSelector("(//div[@class='MuiListItemText-root']//p)[12]")
await artifacts_sec.click();
const url = page.url();
expect(url).toEqual("link");
});
What i noticed is it only renders the login page await page.goto(portal_login);
The code inside beforeEach works but when i tried to submit or login, that's when the test Fails i think it doesn't even render the home after Logging In, and i don't have any idea why this happens, the code is perfectly executed but only timeouts in CI/CD, any idea why this happens?
test.beforeEach(async ({ page }) => {
await page.goto(portal_login);
});
test.only("Redirect Artifacts", async ({page}) => {
// Test in portal_login interface
});
I Tested the portal_login which is the url of the page i only verified it by testing small interface which successfully passed in CI/CD in less than 10 sec
But when executing the login scenario it always timeout, and it shouldn't since it passed less than 5 sec in Local. I also tried setting the timeout longer than the default, so it means that it's not slow, but it does not render at all.
In conclusion, it successfully renders the login page, but it cannot render the home page after a successful login?
UPDATE:
I resolved this with playwright trace, downloaded the result in Gitlab's CI.
The issue here was the Gitlab Variable i set was protected
i forgot to uncheck it, that's why it can't be accessed in unprotected branch.