11const { setDefaultTimeout, Given, When, Then, After } = require ( '@cucumber/cucumber' ) ;
22const { Builder, By, until } = require ( 'selenium-webdriver' ) ;
3- const chrome = require ( 'selenium-webdriver/chrome' ) ; // <-- Add this import
3+ const chrome = require ( 'selenium-webdriver/chrome' ) ;
44const { openHomepage, verifyHomepageElements } = require ( './helpers/homepageHelper' ) ;
55const {
66 openAddRoomPage,
@@ -36,12 +36,13 @@ const buildDriver = async () => {
3636 let options = new chrome . Options ( ) ;
3737
3838 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' ) ;
39+ console . log ( 'Running in CI, enabling headless mode for Chrome' ) ;
40+ options . addArguments (
41+ '--headless' , // Run in headless mode
42+ '--disable-gpu' ,
43+ '--no-sandbox' ,
44+ '--disable-dev-shm-usage'
45+ ) ;
4546 }
4647
4748 driver = await new Builder ( )
@@ -63,70 +64,70 @@ Given('I am on the homepage', async function () {
6364} ) ;
6465
6566Then ( 'I should see the page title {string}' , async function ( title ) {
66- await verifyHomepageElements ( driver , 'title' , title ) ; // Use helper function to verify the title
67+ await verifyHomepageElements ( driver , 'title' , title ) ; // Use helper function
6768} ) ;
6869
6970Then ( 'I should see a navbar with {string}, {string}, and {string} options' , async function ( home , rooms , add ) {
70- await verifyHomepageElements ( driver , 'navbar' ) ; // Use helper function to verify the navbar
71+ await verifyHomepageElements ( driver , 'navbar' ) ;
7172} ) ;
7273
7374Then ( 'I should see the heading {string}' , async function ( headingText ) {
74- await verifyHomepageElements ( driver , 'heading' , headingText ) ; // Use helper function to verify the heading
75+ await verifyHomepageElements ( driver , 'heading' , headingText ) ;
7576} ) ;
7677
7778When ( 'I click on {string} in the navbar' , async function ( linkText ) {
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
79+ if ( linkText === ' Rooms' ) {
80+ await openRoomsPage ( driver ) ;
81+ } else if ( linkText === ' Add' ) {
82+ await openAddRoomPage ( driver ) ;
8283 } else {
8384 throw new Error ( `Link text ${ linkText } is not supported.` ) ;
8485 }
8586} ) ;
8687
8788Then ( 'I should be on the {string} page' , async function ( pageTitle ) {
88- await verifyRoomList ( driver , 'title' , pageTitle ) ; // Use helper function to verify the page title
89+ await verifyRoomList ( driver , 'title' , pageTitle ) ;
8990} ) ;
9091
9192Then ( 'I should see a table with the list of rooms' , async function ( ) {
92- await verifyRoomList ( driver , 'room_table' ) ; // Use helper function to verify room table is present
93+ await verifyRoomList ( driver , 'room_table' ) ;
9394} ) ;
9495
95- Then ( 'the table should contain columns for {string}, {string}, and {string}' , async function ( column1 , column2 , column3 ) {
96- await verifyTableColumns ( driver ) ; // Use helper function to verify table columns
96+ Then ( 'the table should contain columns for {string}, {string}, and {string}' , async function ( c1 , c2 , c3 ) {
97+ await verifyTableColumns ( driver ) ;
9798} ) ;
9899
99100When ( 'I enter {string} in the {string} field' , async function ( value , fieldName ) {
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 ) ;
101+ if ( fieldName === ' Room number' ) {
102+ await fillAddRoomForm ( driver , ' room_number' , value ) ;
103+ } else if ( fieldName === ' Floor number' ) {
104+ await fillAddRoomForm ( driver , ' floor_number' , value ) ;
104105 } else {
105106 throw new Error ( `Unsupported field name: ${ fieldName } ` ) ;
106107 }
107108} ) ;
108109
109110When ( 'I select {string} from the "Good View" dropdown' , async function ( value ) {
110- await fillAddRoomForm ( driver , " good_view" , value ) ;
111+ await fillAddRoomForm ( driver , ' good_view' , value ) ;
111112} ) ;
112113
113114When ( 'I click the "Add room" button' , async function ( ) {
114- await fillAddRoomForm ( driver , " submit" ) ;
115+ await fillAddRoomForm ( driver , ' submit' ) ;
115116} ) ;
116117
117118Then ( 'the new room should be added successfully' , async function ( ) {
118119 await verifyAddRoomSuccess ( driver ) ;
119120} ) ;
120121
121- Then ( 'I should see a room with the room number {string}, on floor {string}, with {string} under Good View' , async function ( roomNumber , floorNumber , viewStatus ) {
122- await verifyRoomDetails ( driver , roomNumber , floorNumber , viewStatus ) ;
122+ Then ( 'I should see a room with the room number {string}, on floor {string}, with {string} under Good View' , async function ( rNumber , fNumber , viewStatus ) {
123+ await verifyRoomDetails ( driver , rNumber , fNumber , viewStatus ) ;
123124} ) ;
124125
125126Then ( 'I should see an alert displaying the number of rooms stored in the database' , async function ( ) {
126127 await verifyRoomsStoredAlert ( driver ) ;
127128} ) ;
128129
129- Then ( 'I should see a form with fields for {string}, {string}, and {string}' , { timeout : 20000 } , async function ( field1 , field2 , field3 ) {
130+ Then ( 'I should see a form with fields for {string}, {string}, and {string}' , { timeout : 20000 } , async function ( f1 , f2 , f3 ) {
130131 await verifyAddRoomFormFields ( driver ) ;
131132} ) ;
132133
0 commit comments