Skip to content

Commit 615df35

Browse files
authored
Expand the production sanity test (#814)
* Expand the production sanity E2E test * Post-review updates * Minor update: remove unused import and locator
1 parent 0e3596a commit 615df35

17 files changed

+419
-38
lines changed

.github/workflows/deploy-production.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ jobs:
242242
env:
243243
APPT_PROD_LOGIN_EMAIL: ${{ secrets.E2E_APPT_PROD_LOGIN_EMAIL }}
244244
APPT_PROD_LOGIN_PWORD: ${{ secrets.E2E_APPT_PROD_LOGIN_PASSWORD }}
245+
APPT_PROD_DISPLAY_NAME: ${{ secrets.E2E_APPT_PROD_DISPLAY_NAME }}
246+
APPT_PROD_MY_SHARE_LINK: ${{ secrets.E2E_APPT_PROD_MY_SHARE_LINK }}
247+
APPT_BOOKING_REQUESTER_EMAIL: ${{ secrets.E2E_APPT_PROD_BOOKING_REQUESTER_EMAIL }}
245248
steps:
246249
- uses: actions/checkout@v4
247250

.github/workflows/nightly-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
env:
2323
APPT_PROD_LOGIN_EMAIL: ${{ secrets.E2E_APPT_PROD_LOGIN_EMAIL }}
2424
APPT_PROD_LOGIN_PWORD: ${{ secrets.E2E_APPT_PROD_LOGIN_PASSWORD }}
25+
APPT_PROD_DISPLAY_NAME: ${{ secrets.E2E_APPT_PROD_DISPLAY_NAME }}
26+
APPT_PROD_MY_SHARE_LINK: ${{ secrets.E2E_APPT_PROD_MY_SHARE_LINK }}
27+
APPT_BOOKING_REQUESTER_EMAIL: ${{ secrets.E2E_APPT_PROD_BOOKING_REQUESTER_EMAIL }}
2528
steps:
2629
- uses: actions/checkout@v4
2730

test/e2e/.env.example

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22

33
# URLs
44
APPT_PROD_URL=https://appointment.day/
5+
APPT_PROD_SHORT_SHARE_LINK_PREFIX=https://apmt.day/
6+
APPT_PROD_LONG_SHARE_LINK_PREFIX=https://appointment.day/user/
57

68
# Production sign-in (FxA) credentials
79
APPT_PROD_LOGIN_EMAIL=
810
APPT_PROD_LOGIN_PWORD=
11+
12+
# Appointment user display name (settings => account => display name) for above user
13+
APPT_PROD_DISPLAY_NAME=
14+
15+
# Production booking share link for the existing user above (settings => account => my link)
16+
APPT_PROD_MY_SHARE_LINK=
17+
18+
# Booking requester's name and email address (used when a booking slot is requested via the
19+
# share link). Important: real appointment booking emails will be sent to the provided email.
20+
APPT_BOOKING_REQUESTER_NAME='Automated-Test-Bot'
21+
APPT_BOOKING_REQUESTER_EMAIL=

test/e2e/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
.env
22
node_modules/
3+
4+
# PlayWright logging etc.
35
/test-results/
46
/playwright-report/
57
/blob-report/
68
/playwright/.cache/
9+
10+
# BrowserStack logging
11+
/log

test/e2e/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Guide for running the Thunderbird Appointment E2E tests.
66

77
You must have a pre-existing Appointment user test account (using FxA credentials) on the platform where you are running the tests. ie. For the production sanity test you must have an Appointment test account on production (using production FxA credentials) already set up.
88

9+
The tests expect that default Appointment application settings exist for the provided test user; for example the user scheduling availability hasn't been changed from the default settings; and the default calendar view is the current month view. This is important so that the tests can find an available booking slot, etc.
10+
911
## Installation
1012

1113
First install the E2E suite (includes Playwright):
@@ -23,17 +25,25 @@ npx playwright install
2325

2426
## Running Locally
2527

26-
The E2E tests require credentials for an existing Appointment (FxA) account and reads these from your local env vars. First copy over the provided `.example.env` to a local `.env`:
28+
The E2E tests require credentials for an existing Appointment (FxA) account and reads these from your local env vars.
29+
This includes the existing Appointment account's email address, password, user's display name and share link.
30+
The display name is found in Appointment => Settings => Account => Display name.
31+
The share link is found in Appointment => Settings => Account => My Link.
32+
The tests also require an email address to be used when actually requesting bookings. This is the email address entered on the `Book selection` dialog (after an appoitment slot was selected on the booking share link page). Note that real Appointment emails will be sent to this email address.
33+
First copy over the provided `.example.env` to a local `.env`:
2734

2835
```bash
2936
cd test/e2e
3037
cp .env.example .env
3138
```
3239

33-
Then edit your local `.env` file and provide the credentials for your Appointment test account:
40+
Then edit your local `.env` file and provide the following values:
3441
```dotenv
3542
APPT_PROD_LOGIN_EMAIL=<existing-test-FxA-user-email>
3643
APPT_PROD_LOGIN_PWORD=<exisiting-test-FxA-user-password>
44+
APPT_PROD_DISPLAY_NAME=<appointment-user-display-name>
45+
APPT_PROD_MY_SHARE_LINK=<apointment-user-share-link>
46+
APPT_BOOKING_REQUESTER_EMAIL=<booking-requesters-email>
3747
```
3848

3949
To run the production sanity test headless (still in `test/e2e`):
@@ -60,11 +70,14 @@ You can run the E2E tests from your local machine but against browsers provided
6070

6171
<b>For security reasons when running the tests on BrowserStack I recommend that you use a dedicated test Appointment FxA account / credentials (NOT your own personal Appointment (FxA) credentials).</b>
6272

63-
Once you have credentials for an existing Appointemnt test account, edit your local `.env` file and add the credentials:
73+
Once you have credentials for an existing Appointemnt test account, edit your local `.env` file and add these details (more information found above):
6474

6575
```dotenv
6676
APPT_PROD_LOGIN_EMAIL=<existing-test-FxA-user-email>
6777
APPT_PROD_LOGIN_PWORD=<exisiting-test-FxA-user-password>
78+
APPT_PROD_DISPLAY_NAME=<appointment-user-display-name>
79+
APPT_PROD_MY_SHARE_LINK=<apointment-user-share-link>
80+
APPT_BOOKING_REQUESTER_EMAIL=<booking-requesters-email>
6881
```
6982

7083
Also in order to run on BrowserStack you need to provide your BrowserStack credentials. Sign into your BrowserStack account and navigate to your `User Profile` and find your auth username and access key. In your local terminal export the following env vars to set the BrowserStack credentials that the tests will use:

test/e2e/browserstack.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ platforms:
2929
osVersion: Sequoia
3030
browserName: playwright-firefox
3131
browserVersion: latest
32+
playwrightConfigOptions:
33+
name: Firefox-OSX
3234
- os: OS X
3335
osVersion: Sequoia
3436
browserName: playwright-chromium
3537
browserVersion: latest
38+
playwrightConfigOptions:
39+
name: Chromium-OSX
3640

3741
# =======================
3842
# Parallels per Platform
@@ -63,8 +67,7 @@ browserstackLocal: false # <boolean> (Default false)
6367
# ===================
6468
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
6569
networkLogs: false # <boolean> Set to true to enable HAR logs capturing; off as may contain sensitive info like login API requests
66-
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
67-
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)
70+
consoleLogs: info # <string> Remote browser's console debug levels to be printed (`disable`, `errors`, `warnings`, `info`, or `verbose`)
6871
framework: playwright
6972
browserstack.playwrightLogs: false # disable playwright logs appearing on browserstack builds as may contain sensitive info like credentials
7073
# CUSTOM_TAG_<INT>: # <string> (Default: parent folder name of the test file) Custom tag for your test suite

test/e2e/const/constants.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
// appointment urls
2-
export const APPT_PROD_URL = process.env.APPT_PROD_URL;
2+
export const APPT_PROD_URL = String(process.env.APPT_PROD_URL);
3+
export const APPT_PROD_MY_SHARE_LINK = String(process.env.APPT_PROD_MY_SHARE_LINK);
4+
export const APPT_PROD_SHORT_SHARE_LINK_PREFIX = String(process.env.APPT_PROD_SHORT_SHARE_LINK_PREFIX);
5+
export const APPT_PROD_LONG_SHARE_LINK_PREFIX = String(process.env.APPT_PROD_LONG_SHARE_LINK_PREFIX);
36

47
// page titles
58
export const APPT_PAGE_TITLE = 'Thunderbird Appointment';
69
export const FXA_PAGE_TITLE = 'Mozilla accounts';
710

8-
// production sign-in credentials
9-
export const PROD_LOGIN_EMAIL = process.env.APPT_PROD_LOGIN_EMAIL;
10-
export const PROD_LOGIN_PWORD = process.env.APPT_PROD_LOGIN_PWORD;
11+
// production sign-in credentials and corresponding account display name
12+
export const PROD_LOGIN_EMAIL = String(process.env.APPT_PROD_LOGIN_EMAIL);
13+
export const PROD_LOGIN_PWORD = String(process.env.APPT_PROD_LOGIN_PWORD);
14+
15+
// appointment user display name (settings => account) for above user
16+
export const PROD_DISPLAY_NAME = String(process.env.APPT_PROD_DISPLAY_NAME);
17+
18+
// appointment requester's name and email address
19+
export const APPT_BOOKING_REQUESTER_NAME = String(process.env.APPT_BOOKING_REQUESTER_NAME);
20+
export const APPT_BOOKING_REQUESTER_EMAIL = String(process.env.APPT_BOOKING_REQUESTER_EMAIL);

test/e2e/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"devDependencies": {
1818
"@playwright/test": "^1.49.0",
1919
"@types/node": "^22.10.1",
20-
"browserstack-node-sdk": "^1.34.29",
20+
"browserstack-node-sdk": "^1.34.34",
2121
"dotenv": "^16.3.1"
2222
}
2323
}

test/e2e/pages/booking-page.ts

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import { expect } from '@playwright/test';
2+
import { type Page, type Locator } from '@playwright/test';
3+
import { APPT_PROD_MY_SHARE_LINK, APPT_PROD_SHORT_SHARE_LINK_PREFIX, APPT_PROD_LONG_SHARE_LINK_PREFIX } from '../const/constants';
4+
5+
export class BookingPage {
6+
readonly page: Page;
7+
readonly titleText: Locator;
8+
readonly invitingText: Locator;
9+
readonly confirmBtn: Locator;
10+
readonly bookingCalendar: Locator;
11+
readonly calendarHeader: Locator;
12+
readonly nextMonthArrow: Locator;
13+
readonly availableBookingSlot: Locator;
14+
readonly bookSelectionNameInput: Locator;
15+
readonly bookSelectionEmailInput: Locator;
16+
readonly bookSelectionBookBtn: Locator;
17+
readonly requestSentTitleText: Locator;
18+
readonly requestSentAvailabilityText: Locator;
19+
readonly requestSentCloseBtn: Locator;
20+
21+
constructor(page: Page) {
22+
this.page = page;
23+
this.titleText = this.page.getByTestId('booking-view-title-text');
24+
this.invitingText = this.page.getByTestId('booking-view-inviting-you-text');
25+
this.bookingCalendar = this.page.getByTestId('booking-view-calendar-div');
26+
this.confirmBtn = this.page.getByTestId('booking-view-confirm-selection-button');
27+
this.calendarHeader = this.page.locator('.calendar-header__period-name');
28+
this.nextMonthArrow = this.page.locator('[data-icon="chevron-right"]');
29+
this.availableBookingSlot = this.page.locator('[data-test="day-event"]', { hasNotText: 'Busy'});
30+
this.bookSelectionNameInput = this.page.getByPlaceholder('First and last name');
31+
this.bookSelectionEmailInput = this.page.getByPlaceholder('john.doe@example.com');
32+
this.bookSelectionBookBtn = this.page.getByRole('button', { name: 'Book' });
33+
this.requestSentTitleText = this.page.getByText('Booking request sent');
34+
this.requestSentAvailabilityText = this.page.getByText("'s Availability");
35+
this.requestSentCloseBtn = this.page.getByRole('button', { name: 'Close' });
36+
}
37+
38+
/**
39+
* Navigate to the booking page using the share link short URL.
40+
*/
41+
async gotoBookingPageShortUrl() {
42+
// the default share link is a short URL
43+
await this.page.goto(APPT_PROD_MY_SHARE_LINK);
44+
await this.page.waitForLoadState('domcontentloaded');
45+
}
46+
47+
/**
48+
* Navigatge to the booking page using the share link long URL.
49+
*/
50+
async gotoBookingPageLongUrl() {
51+
// the share link is short by default; build the corresponding long link first
52+
const prodShareLinkUser: string = APPT_PROD_MY_SHARE_LINK.split(APPT_PROD_SHORT_SHARE_LINK_PREFIX)[1];
53+
const longLink: string = `${APPT_PROD_LONG_SHARE_LINK_PREFIX}${prodShareLinkUser}`;
54+
await this.page.goto(longLink);
55+
await this.page.waitForLoadState('domcontentloaded');
56+
}
57+
58+
/**
59+
* Go to the booking page week view (via the booking share link)
60+
*/
61+
async gotoBookingPageWeekView() {
62+
const weekLink: string = `${APPT_PROD_MY_SHARE_LINK}#week`;
63+
await this.page.goto(weekLink);
64+
await this.page.waitForLoadState('domcontentloaded');
65+
await expect(this.confirmBtn).toBeVisible({ timeout: 30_000 });
66+
}
67+
68+
/**
69+
* With the booking page week view already displayed, go forward to the next week.
70+
*/
71+
async goForwardOneWeek() {
72+
await this.nextMonthArrow.click();
73+
await this.page.waitForLoadState('domcontentloaded');
74+
await expect(this.confirmBtn).toBeVisible({ timeout: 30_000 });
75+
}
76+
77+
/**
78+
* With the booking page week view already displayed, select the first available booking slot.
79+
* If there is no slot available on the current week, this methond will skip to the next week
80+
* and look for slots there. If no slots are avaible on the next week either, then an error
81+
* will be raised.
82+
* @param userDisplayName String containing the display name of the Appointment user
83+
* @returns String containing the reference text for the time slot that was requested
84+
* as retrieved from the DOM ie. 'event-2025-01-08 09:30'.
85+
*/
86+
async selectAvailableBookingSlot(userDisplayName: string): Promise<string> {
87+
// let's check if a non-busy appointment slot exists in the current week view
88+
const slotCount: number = await this.availableBookingSlot.count();
89+
console.log(`available slot count: ${slotCount}`);
90+
91+
// if no slots are available in current week view then fast forward to next week
92+
if (slotCount === 0) {
93+
console.log('no slots available in current week, skipping ahead to the next week');
94+
await this.goForwardOneWeek();
95+
// now check again for available slots; if none then fail out the test (safety catch but shouldn't happen)
96+
const newSlotCount: number = await this.availableBookingSlot.count();
97+
console.log(`available slot count: ${newSlotCount}`);
98+
expect(newSlotCount, `no booking slots available, please check availability settings for ${userDisplayName}`).toBeGreaterThan(0);
99+
}
100+
101+
// slots are available in current week view so get the first one
102+
const firstSlot: Locator = this.availableBookingSlot.first();
103+
let slotRef = await firstSlot.getAttribute('data-ref'); // ie. 'event-2025-01-08 09:30'
104+
if (!slotRef)
105+
slotRef = 'none';
106+
expect(slotRef).toContain('event-');
107+
108+
// now that we've found an availalbe slot select it and confirm
109+
await firstSlot.click();
110+
return slotRef;
111+
}
112+
113+
/**
114+
* Fill out the 'book selection' dialog with the given values.
115+
* The 'book selection' dialog appears after an appointment slot has been selected (on the
116+
* booking page provided by the share link). This method will fill in the booking requester's
117+
* name and email address and then click the 'book' button to finalize the booking request.
118+
* @param bookerName String to fill in as the booking requester's name
119+
* @param bookerEmail String to fill in as the booking requester's email
120+
*/
121+
async finishBooking(bookerName: string, bookerEmail: string) {
122+
await this.bookSelectionNameInput.fill(bookerName);
123+
await this.bookSelectionEmailInput.fill(bookerEmail);
124+
await this.bookSelectionBookBtn.click();
125+
}
126+
127+
/**
128+
* Verify the given appointment time slot text is displayed in the current page
129+
* @param expSlotDateStr Expected slot date string formatted as 'Friday, January 10, 2025'
130+
* @param expSlotTimeStr Expected time slot time string formatted as '14:30' (24 hr time)
131+
*/
132+
async verifyRequestedSlotTextDisplayed(expSlotDateStr: string, expSlotTimeStr: string) {
133+
// due to the way the element is we must locate by the date text only
134+
const slotDisplayText: Locator = this.page.getByText(expSlotDateStr);
135+
await expect(slotDisplayText).toBeVisible();
136+
// the slot text has been found so now verify it contains both the given date and time
137+
await expect(slotDisplayText).toHaveText(`${expSlotDateStr} ${expSlotTimeStr}`);
138+
}
139+
140+
/**
141+
* Utility to return a string containing the date abstracted from a given time slot string
142+
* @param timeSlotString Slot string read from DOM (ie. 'event-2025-01-14 14:30')
143+
* @returns Formatted date string (ie. 'Tuesday, January 14, 2025')
144+
*/
145+
async getDateFromSlotString(timeSlotString: string): Promise<string> {
146+
const selectedSlotDateTime = new Date(timeSlotString.substring(6));
147+
return selectedSlotDateTime.toLocaleDateString('default', { dateStyle: 'full' });
148+
}
149+
150+
/**
151+
* Utility to return a string containg the time abstracted from a given time slot string.
152+
* The time in the given time slot string is in 24 hour format (i.e. 14:30), but we want
153+
* it to be like '02:30 PM'
154+
* @param timeSlotString Slot string read from DOM (ie. 'event-2025-01-14 14:30')
155+
* @returns Formatted time string (ie. '02:30 PM')
156+
*/
157+
async getTimeFromSlotString(timeSlotString: string): Promise<string> {
158+
const selectedSlotDateTime = new Date(timeSlotString.substring(6));
159+
const expTimeStr = selectedSlotDateTime.toLocaleTimeString('default', { hour12: true, hour: '2-digit', minute: '2-digit' });
160+
// now expTimeStr looks like this, for example: '04:30 p.m.' but need it to be like '04:30 PM'
161+
return expTimeStr.toUpperCase().replace('.', '').replace('.', '');
162+
}
163+
}

0 commit comments

Comments
 (0)