Skip to content

Commit

Permalink
Merge branch 'development' into SFR-2400/remove-cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
jackiequach committed Jan 6, 2025
2 parents 76e0580 + 4135086 commit 155e54f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 10 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/Playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ jobs:
with:
node-version-file: ".nvmrc"

- name: Set environment for branch
run: |
if [[ $GITHUB_REF_NAME == 'production' ]]; then
echo "BASE_URL=https://drb-qa.nypl.org/" >> "$GITHUB_ENV"
else
echo "BASE_URL=http://local.nypl.org:3000/" >> "$GITHUB_ENV"
fi
- name: Add hosts to /etc/hosts
if: github.ref != 'production'
run: |
sudo echo "127.0.0.1 local.nypl.org" | sudo tee -a /etc/hosts
- name: Install Test Dependencies
run: npm i @playwright/[email protected]

Expand All @@ -25,13 +38,17 @@ jobs:
run: NODE_ENV=test npm run build

- name: Start the app
if: github.ref != 'production'
run: |
NODE_ENV=test npm start &
sleep 5
shell: bash

- name: Run your tests
run: npm run playwright
env:
CATALOG_USERNAME: ${{ secrets.CATALOG_USERNAME }}
CATALOG_USER_PIN: ${{ secrets.CATALOG_USER_PIN }}

- name: Slack Notification
if: ${{ always() }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Prerelease]

- Replace Cucumber with Playwright Page Object Model tests
- Update GH action to run tests against local.nypl.org and QA for prod PRs

## [0.18.10]

Expand Down
2 changes: 1 addition & 1 deletion mocks/mockEnv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const NYPL_LOGIN_URL = "https://login.nypl.org/auth/login?redirect_uri=";
export const NYPL_LOGIN_URL = "login.nypl.org";
export const API_URL = "https://backend.msw";
export const FULFILL_PATH = "/fulfill/9351827";
export const LIMITED_ACCESS_EDITION_PATH = "/edition/6977884";
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const config: PlaywrightTestConfig = {
use: {
headless: true,
// Base URL to use in actions like `await page.goto('/')`.
baseURL: "http://localhost:3000",
baseURL: "http://local.nypl.org:3000",

/* When running tests locally, record a trace for each test, but remove it from successful runs.
* On CI, turn this feature off. See https://playwright.dev/docs/trace-viewer */
Expand Down
14 changes: 7 additions & 7 deletions playwright/integration/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ test.afterEach(() => server.resetHandlers());
test.afterAll(() => server.close());

test.describe("Cookie authentication", () => {
test("redirects to NYPL log in page with no cookie", async ({ page }) => {
test("redirects to NYPL login page with no cookie", async ({ page }) => {
await page.goto(`${LIMITED_ACCESS_EDITION_PATH}`);
await page.getByTestId(LOGIN_TO_READ_TEST_ID).click();
await page.waitForURL(`**${NYPL_LOGIN_URL}**`);
await page.waitForURL(/.*login.nypl.org.*/);
const url = new URL(page.url());
const redirectUri = url.searchParams.get("redirect_uri");
const service = url.searchParams.get("service");

expect(redirectUri).toContain(LIMITED_ACCESS_EDITION_PATH);
expect(service).toContain(NYPL_LOGIN_URL);
});

test("redirects to NYPL login page with expired cookie", async ({
Expand All @@ -34,11 +34,11 @@ test.describe("Cookie authentication", () => {

await page.goto(`${LIMITED_ACCESS_EDITION_PATH}`);
await page.getByTestId(LOGIN_TO_READ_TEST_ID).click();
await page.waitForURL(`**${NYPL_LOGIN_URL}**`);
await page.waitForURL(/.*login.nypl.org.*/);
const url = new URL(page.url());
const redirectUri = url.searchParams.get("redirect_uri");
const service = url.searchParams.get("service");

expect(redirectUri).toContain(LIMITED_ACCESS_EDITION_PATH);
expect(service).toContain(NYPL_LOGIN_URL);
});

// TODO: logging in from localhost does not work
Expand Down
42 changes: 42 additions & 0 deletions playwright/search-page/search-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ class SearchPage {

readonly requestableCheckbox: Locator;
readonly firstLoginForOptionsButton: Locator;
readonly usernameField: Locator;
readonly passwordField: Locator;
readonly loginButton: Locator;
readonly firstRequestButton: Locator;
readonly deliveryLocationHeading: Locator;

readonly governmentDocumentsCheckbox: Locator;
readonly firstGovernmentDocumentAuthor: Locator;

Expand Down Expand Up @@ -44,6 +50,14 @@ class SearchPage {
this.firstLoginForOptionsButton = page.locator(
"a:text('Log in to request scan') >> nth=0"
);
this.usernameField = page.locator("#code");
this.passwordField = page.locator("#pin");
this.loginButton = page.locator("[value='Submit']");
this.firstRequestButton = page.locator("a:text('Request scan') >> nth=0");
this.deliveryLocationHeading = page.locator(
"h2:text('Choose a delivery location')"
);

this.governmentDocumentsCheckbox = page.locator(
"span:text('Show only US government documents')"
);
Expand Down Expand Up @@ -110,6 +124,34 @@ class SearchPage {
await this.requestableCheckbox.click();
}

async clickFirstLoginForOptionsButton() {
await this.firstLoginForOptionsButton.click();
}

async fillUsernameField(username: string) {
await this.usernameField.fill(username);
}

async fillPasswordField(password: string) {
await this.passwordField.fill(password);
}

async clickLoginButton() {
await this.loginButton.click();
}

async verifyFirstRequestButtonVisible() {
await expect(this.firstRequestButton).toBeVisible();
}

async clickFirstRequestButton() {
await this.firstRequestButton.click();
}

async verifyDeliveryLocationHeadingVisible() {
await expect(this.deliveryLocationHeading).toBeVisible();
}

async verifyFirstLoginForOptionsButtonVisible() {
await expect(this.firstLoginForOptionsButton).toBeVisible();
}
Expand Down
8 changes: 7 additions & 1 deletion playwright/search-page/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ test.describe("EDD Request Process", () => {
await searchPage.fillSearchBox("Africa");
await searchPage.clickSearchButton();
await searchPage.clickRequestableCheckbox();
await searchPage.verifyFirstLoginForOptionsButtonVisible();
await searchPage.clickFirstLoginForOptionsButton();
await searchPage.fillUsernameField(process.env.CATALOG_USERNAME);
await searchPage.fillPasswordField(process.env.CATALOG_USER_PIN);
await searchPage.clickLoginButton();
await searchPage.verifyFirstRequestButtonVisible();
await searchPage.clickFirstRequestButton();
await searchPage.verifyDeliveryLocationHeadingVisible();
});
});

Expand Down

0 comments on commit 155e54f

Please sign in to comment.