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] playwright gckey login test #11202

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions apps/playwright/.env.example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this won't work until #11265 is added.

Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
#TEST_TIMEOUT=30000
#EXPECT_TIMEOUT=5000
#BASE_URL=http://localhost:8000
#GCKEY_USERNAME=
#GCKEY_PASSWORD=
10 changes: 10 additions & 0 deletions apps/playwright/fixtures/SignInFixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { test as base } from "@playwright/test";

import { SignInPage } from "./SignInPage";

export const test = base.extend<{ signInPage: SignInPage }>({
signInPage: async ({ page }, use) => {
const signInPage = new SignInPage(page);
await use(signInPage);
},
});
35 changes: 35 additions & 0 deletions apps/playwright/fixtures/SignInPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { type Page, type Locator} from "@playwright/test";

export class SignInPage {
readonly page: Page;
readonly url: string = "https://talent.canada.ca/en/";
readonly usernameInputLocator: Locator;
readonly passwordInputLocator: Locator;
readonly signInButtonLocator: Locator;
readonly continueButtonLocator: Locator;

public constructor(page: Page) {
this.page = page;
this.usernameInputLocator = page.getByPlaceholder("Username");
this.passwordInputLocator = page.getByPlaceholder("Password");
this.signInButtonLocator = page.getByRole("link", { name: "Sign in" });
this.continueButtonLocator = page.locator('button:has-text("Continue")');
}
async visit() {
await this.page.goto(this.url);
}
async login(email: string, password: string) {
await this.usernameInputLocator.fill(email);
await this.passwordInputLocator.fill(password);
await this.signInButtonLocator.click();
}

async isSignedIn() {
const welcomeLocator = this.page.locator('div:has-text("welcome")');
return await welcomeLocator.isVisible();
}

async clickContinue() {
await this.continueButtonLocator.click();
}
}
12 changes: 11 additions & 1 deletion apps/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import { defineConfig, devices } from "@playwright/test";
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({

// Extend PlaywrightTestConfig to include custom properties
interface CustomTestConfig extends PlaywrightTestConfig {
gckeyUsername?: string;
gckeyPassword?: string;
}

export default defineConfig<CustomTestConfig>({
testDir: "./tests",
/* Run tests in files in parallel */
fullyParallel: true,
Expand All @@ -35,6 +42,9 @@ export default defineConfig({

/* ignore HTTPS errors when sending network requests */
ignoreHTTPSErrors: true,

gckeyUsername: process.env.GCKEY_USERNAME ?? "",
gckeyPassword: process.env.GCKEY_PASSWORD ?? "",
},

/* Configure projects for major browsers */
Expand Down
35 changes: 35 additions & 0 deletions apps/playwright/tests/gcKey-login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { test as base, expect } from "@playwright/test";

import { SignInPage } from "../fixtures/SignInPage";

export const test = base.extend<{ signInPage: SignInPage }>({
signInPage: async ({ page }, use) => {
const signInPage = new SignInPage(page);
await use(signInPage);
},
});

test("user signs in, sees welcome message, and navigates to dashboard", async ({
page,
}) => {
const signInPage = new SignInPage(page);

// Visit the login page
await signInPage.visit();

// Perform the login
await signInPage.login(
process.env.GCKEY_USERNAME,
process.env.GCKEY_USERNAME,
brindasasi marked this conversation as resolved.
Show resolved Hide resolved
);

// Assert that the user is signed in by checking the welcome message
const isSignedIn = await signInPage.isSignedIn();
expect(isSignedIn).toBe(true);

await signInPage.clickContinue();

const applicantDashboardUrl = process.env.BASE_URL + "/applicant";
await page.waitForURL(applicantDashboardUrl);
expect(page.url()).toBe(applicantDashboardUrl);
});
3 changes: 3 additions & 0 deletions infrastructure/azure-pipelines-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
- job: run_playwright_tests
displayName: Run Playwright tests
timeoutInMinutes: 30
env:
GCKEY_USERNAME: $(GCKEY_USERNAME)
GCKEY_PASSWORD: $(GCKEY_PASSWORD)
steps:
- checkout: self
clean: true
Expand Down
Loading