Skip to content

Commit ac6f335

Browse files
author
Robert Bradley
committed
Adding nightly testing
1 parent bff44e3 commit ac6f335

File tree

3 files changed

+87
-60
lines changed

3 files changed

+87
-60
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@ updates:
1717
directory: "/"
1818
# Check for updates once a week
1919
schedule:
20-
interval: "weekly"
20+
interval: "daily"
21+
22+
- package-ecosystem: "github-actions"
23+
directory: "/"
24+
schedule:
25+
# Check for updates to GitHub Actions every week
26+
interval: "daily"

.github/workflows/tests.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- cron: '0 3 * * *' # Runs nightly at 3 AM UTC
77

88
jobs:
9-
build-and-test:
9+
run-tests:
1010
runs-on: ubuntu-latest
1111

1212
steps:
@@ -18,7 +18,6 @@ jobs:
1818
with:
1919
node-version: 22
2020

21-
# 1) Install Chrome so Selenium can run
2221
- name: Install Chrome
2322
run: |
2423
sudo apt-get update
@@ -27,11 +26,9 @@ jobs:
2726
- name: Install dependencies
2827
run: npm install
2928

30-
# 2) Spin up DynamoDB local on port 8000
3129
- name: Start DynamoDB Local
3230
run: docker run -d -p 8000:8000 amazon/dynamodb-local
3331

34-
# 3) Set environment vars so the AWS SDK points to local DynamoDB
3532
- name: Set up env vars
3633
run: |
3734
echo "AWS_ACCESS_KEY_ID=FAKE_KEY" >> $GITHUB_ENV
@@ -40,21 +37,18 @@ jobs:
4037
echo "DYNAMODB_ENDPOINT=http://127.0.0.1:8000" >> $GITHUB_ENV
4138
echo "DYNAMODB_TABLE_NAME=RoomsTest" >> $GITHUB_ENV
4239
# IMPORTANT: Make sure this matches the port your Express app uses
43-
# If your app listens on 8081, set this to http://localhost:8081
44-
echo "BASE_URL=http://localhost:3000" >> $GITHUB_ENV
40+
echo "BASE_URL=http://localhost:8081" >> $GITHUB_ENV
41+
echo "CI=true" >> $GITHUB_ENV
42+
4543
46-
# 4) Start your Express app in the background
47-
# By default your "npm start" runs on port 3000 or 8081—adjust sleep time as necessary
4844
- name: Start server
4945
run: |
5046
npm start &
5147
# Give the server a few seconds to spin up before running tests
5248
sleep 5
5349
54-
# 5) Run your Jest-based unit tests
5550
- name: Run unit tests
5651
run: npm run unit-test
5752

58-
# 6) Run your Selenium + Cucumber integration tests
5953
- name: Run integration tests
6054
run: npm run integration-tests
Lines changed: 76 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,142 @@
11
const { setDefaultTimeout, Given, When, Then, After } = require('@cucumber/cucumber');
22
const { Builder, By, until } = require('selenium-webdriver');
3+
const chrome = require('selenium-webdriver/chrome'); // <-- Add this import
34
const { openHomepage, verifyHomepageElements } = require('./helpers/homepageHelper');
4-
const { openAddRoomPage, fillAddRoomForm, verifyAddRoomSuccess, verifyAddRoomFormFields, verifySubmitButton } = require('./helpers/addRoomHelper');
5-
const { openRoomsPage, verifyRoomList, verifyRoomDetails, verifyTableColumns, verifyRoomsStoredAlert } = require('./helpers/roomsHelper');
5+
const {
6+
openAddRoomPage,
7+
fillAddRoomForm,
8+
verifyAddRoomSuccess,
9+
verifyAddRoomFormFields,
10+
verifySubmitButton
11+
} = require('./helpers/addRoomHelper');
12+
const {
13+
openRoomsPage,
14+
verifyRoomList,
15+
verifyRoomDetails,
16+
verifyTableColumns,
17+
verifyRoomsStoredAlert
18+
} = require('./helpers/roomsHelper');
619

720
let driver;
821

922
setDefaultTimeout(120 * 1000); // needed for the time it takes to spin up the remote web driver if used
1023

1124
// Function to build and return a WebDriver instance
1225
const buildDriver = async () => {
13-
const gridUrl = process.env.GRID_URL || null;
14-
15-
if (gridUrl) {
16-
console.log(`Using Selenium Grid at: ${gridUrl}`);
17-
driver = await new Builder()
18-
.usingServer(gridUrl) // Use the Selenium Grid URL here
19-
.forBrowser('chrome')
20-
.build();
21-
} else {
22-
// If no GRID_URL is set, run the browser locally
23-
driver = await new Builder().forBrowser('chrome').build();
26+
const gridUrl = process.env.GRID_URL || null;
27+
28+
if (gridUrl) {
29+
console.log(`Using Selenium Grid at: ${gridUrl}`);
30+
driver = await new Builder()
31+
.usingServer(gridUrl) // Use the Selenium Grid URL here
32+
.forBrowser('chrome')
33+
.build();
34+
} else {
35+
// If no GRID_URL is set, run the browser locally
36+
let options = new chrome.Options();
37+
38+
if (process.env.CI) {
39+
// Running in CI: add headless flags
40+
options = options
41+
.headless()
42+
.addArguments('--disable-gpu')
43+
.addArguments('--no-sandbox')
44+
.addArguments('--disable-dev-shm-usage');
2445
}
2546

26-
// Common settings for the driver
27-
await driver.manage().setTimeouts({ implicit: 10000 });
28-
await driver.manage().window().setRect({ width: 1920, height: 1080 }); // Full HD resolution
47+
driver = await new Builder()
48+
.forBrowser('chrome')
49+
.setChromeOptions(options)
50+
.build();
51+
}
52+
53+
// Common settings for the driver
54+
await driver.manage().setTimeouts({ implicit: 10000 });
55+
await driver.manage().window().setRect({ width: 1920, height: 1080 }); // Full HD resolution
2956
};
3057

3158
// Step Definitions
3259
Given('I am on the homepage', async function () {
33-
await buildDriver(); // Create WebDriver instance
34-
const baseUrl = process.env.BASE_URL || 'http://localhost:3000';
35-
await openHomepage(driver, baseUrl); // Use helper function to open the homepage
60+
await buildDriver(); // Create WebDriver instance
61+
const baseUrl = process.env.BASE_URL || 'http://localhost:3000';
62+
await openHomepage(driver, baseUrl); // Use helper function to open the homepage
3663
});
3764

3865
Then('I should see the page title {string}', async function (title) {
39-
await verifyHomepageElements(driver, 'title', title); // Use helper function to verify the title
66+
await verifyHomepageElements(driver, 'title', title); // Use helper function to verify the title
4067
});
4168

4269
Then('I should see a navbar with {string}, {string}, and {string} options', async function (home, rooms, add) {
43-
await verifyHomepageElements(driver, 'navbar'); // Use helper function to verify the navbar with the given options
70+
await verifyHomepageElements(driver, 'navbar'); // Use helper function to verify the navbar
4471
});
4572

4673
Then('I should see the heading {string}', async function (headingText) {
47-
await verifyHomepageElements(driver, 'heading', headingText); // Use helper function to verify the heading
74+
await verifyHomepageElements(driver, 'heading', headingText); // Use helper function to verify the heading
4875
});
4976

5077
When('I click on {string} in the navbar', async function (linkText) {
51-
if (linkText === "Rooms") {
52-
await openRoomsPage(driver); // Use helper to open the Rooms page
53-
} else if (linkText === "Add") {
54-
await openAddRoomPage(driver); // Use helper to open the Add Room page
55-
} else {
56-
throw new Error(`Link text ${linkText} is not supported.`);
57-
}
78+
if (linkText === "Rooms") {
79+
await openRoomsPage(driver); // Use helper to open the Rooms page
80+
} else if (linkText === "Add") {
81+
await openAddRoomPage(driver); // Use helper to open the Add Room page
82+
} else {
83+
throw new Error(`Link text ${linkText} is not supported.`);
84+
}
5885
});
5986

6087
Then('I should be on the {string} page', async function (pageTitle) {
61-
await verifyRoomList(driver, 'title', pageTitle); // Use helper function to verify the page title
88+
await verifyRoomList(driver, 'title', pageTitle); // Use helper function to verify the page title
6289
});
6390

6491
Then('I should see a table with the list of rooms', async function () {
65-
await verifyRoomList(driver, 'room_table'); // Use helper function to verify room table is present
92+
await verifyRoomList(driver, 'room_table'); // Use helper function to verify room table is present
6693
});
6794

6895
Then('the table should contain columns for {string}, {string}, and {string}', async function (column1, column2, column3) {
69-
await verifyTableColumns(driver); // Use helper function to verify table columns
96+
await verifyTableColumns(driver); // Use helper function to verify table columns
7097
});
7198

7299
When('I enter {string} in the {string} field', async function (value, fieldName) {
73-
if (fieldName === "Room number") {
74-
await fillAddRoomForm(driver, "room_number", value);
75-
} else if (fieldName === "Floor number") {
76-
await fillAddRoomForm(driver, "floor_number", value);
77-
} else {
78-
throw new Error(`Unsupported field name: ${fieldName}`);
79-
}
100+
if (fieldName === "Room number") {
101+
await fillAddRoomForm(driver, "room_number", value);
102+
} else if (fieldName === "Floor number") {
103+
await fillAddRoomForm(driver, "floor_number", value);
104+
} else {
105+
throw new Error(`Unsupported field name: ${fieldName}`);
106+
}
80107
});
81108

82109
When('I select {string} from the "Good View" dropdown', async function (value) {
83-
await fillAddRoomForm(driver, "good_view", value);
110+
await fillAddRoomForm(driver, "good_view", value);
84111
});
85112

86113
When('I click the "Add room" button', async function () {
87-
await fillAddRoomForm(driver, "submit");
114+
await fillAddRoomForm(driver, "submit");
88115
});
89116

90117
Then('the new room should be added successfully', async function () {
91-
await verifyAddRoomSuccess(driver);
118+
await verifyAddRoomSuccess(driver);
92119
});
93120

94121
Then('I should see a room with the room number {string}, on floor {string}, with {string} under Good View', async function (roomNumber, floorNumber, viewStatus) {
95-
await verifyRoomDetails(driver, roomNumber, floorNumber, viewStatus);
122+
await verifyRoomDetails(driver, roomNumber, floorNumber, viewStatus);
96123
});
97124

98125
Then('I should see an alert displaying the number of rooms stored in the database', async function () {
99-
await verifyRoomsStoredAlert(driver);
126+
await verifyRoomsStoredAlert(driver);
100127
});
101128

102129
Then('I should see a form with fields for {string}, {string}, and {string}', { timeout: 20000 }, async function (field1, field2, field3) {
103-
await verifyAddRoomFormFields(driver);
130+
await verifyAddRoomFormFields(driver);
104131
});
105132

106133
Then('I should see a submit button labeled {string}', { timeout: 20000 }, async function (buttonLabel) {
107-
await verifySubmitButton(driver, buttonLabel);
134+
await verifySubmitButton(driver, buttonLabel);
108135
});
109136

110137
// Tear Down
111138
After(async function () {
112-
if (driver) {
113-
await driver.quit();
114-
}
139+
if (driver) {
140+
await driver.quit();
141+
}
115142
});

0 commit comments

Comments
 (0)