@@ -21,10 +21,9 @@ describe('Device users page - Add new device user', function () {
2121 it ( 'should add new device user with first name and last name' , ( ) => {
2222 const surname = generateRandmString ( ) ;
2323
24- // Ensure table is visible before counting rows
25- cy . get ( 'tbody > tr' , { timeout : 10000 } ) . should ( 'have.length.gt' , 0 ) ;
26-
27- deviceUsersPage . rowNum ( ) . then ( ( rowCountBeforeCreation ) => {
24+ // Count rows (may be 0 if table is empty)
25+ cy . get ( 'tbody' ) . then ( ( $tbody ) => {
26+ const rowCountBeforeCreation = $tbody . find ( 'tr' ) . length ;
2827 countDeviceUsersBeforeCreating = rowCountBeforeCreation ;
2928
3029 // Create new device user
@@ -40,7 +39,8 @@ describe('Device users page - Add new device user', function () {
4039 cy . get ( '#newDeviceUserBtn' ) . should ( 'be.visible' ) ;
4140
4241 // Verify the user was created
43- deviceUsersPage . rowNum ( ) . then ( ( rowCountAfterCreation ) => {
42+ cy . get ( 'tbody' ) . then ( ( $tbody ) => {
43+ const rowCountAfterCreation = $tbody . find ( 'tr' ) . length ;
4444 expect (
4545 rowCountAfterCreation ,
4646 'Number of rows hasn\'t changed after creating new user'
@@ -102,16 +102,17 @@ describe('Device users page - Should not add new device user', function () {
102102 } ) ;
103103
104104 it ( 'should NOT create user if cancel was clicked' , ( ) => {
105- // Ensure table is visible before counting rows
106- cy . get ( 'tbody > tr' , { timeout : 10000 } ) . should ( 'have.length.gt' , 0 ) ;
107-
108- deviceUsersPage . rowNum ( ) . then ( ( rowCountBeforeCreation ) => {
105+ // Count rows (may be 0 if table is empty at start)
106+ cy . get ( 'tbody' ) . then ( ( $tbody ) => {
107+ const rowCountBeforeCreation = $tbody . find ( 'tr' ) . length ;
108+
109109 cy . get ( '#newDeviceUserBtn' , { timeout : 10000 } ) . should ( 'be.visible' ) . click ( ) ;
110110 cy . get ( '#firstName' ) . should ( 'be.visible' ) ;
111111 cy . get ( '#cancelCreateBtn' ) . should ( 'be.visible' ) . click ( ) ;
112112 cy . get ( '#newDeviceUserBtn' , { timeout : 10000 } ) . should ( 'be.visible' ) ;
113113
114- deviceUsersPage . rowNum ( ) . then ( ( rowCountAfterCreation ) => {
114+ cy . get ( 'tbody' ) . then ( ( $tbody2 ) => {
115+ const rowCountAfterCreation = $tbody2 . find ( 'tr' ) . length ;
115116 expect (
116117 rowCountAfterCreation ,
117118 'Number of rows has changed after cancel'
@@ -121,29 +122,29 @@ describe('Device users page - Should not add new device user', function () {
121122 } ) ;
122123
123124 it ( 'should clean up created test data' , ( ) => {
124- // Ensure table is visible before finding user
125- cy . get ( 'tbody > tr' , { timeout : 10000 } ) . should ( 'have.length.gt' , 0 ) ;
126-
127- // Find and delete the test user
128- cy . get ( '#deviceUserFirstName' ) . each ( ( $el , index ) => {
129- if ( $el . text ( ) === nameDeviceUser ) {
130- cy . intercept ( 'POST' , '**/api/device-users/delete' ) . as ( 'deleteUser' ) ;
131- cy . intercept ( 'POST' , '**/api/device-users/index' ) . as ( 'reloadDeviceUsers' ) ;
132- cy . get ( '#deleteDeviceUserBtn' ) . eq ( index ) . click ( ) ;
133- cy . get ( '#saveDeleteBtn' ) . should ( 'be.visible' ) . click ( ) ;
134- cy . wait ( '@deleteUser' , { timeout : 30000 } ) ;
135- cy . wait ( '@reloadDeviceUsers' , { timeout : 30000 } ) ;
136- cy . get ( '#newDeviceUserBtn' , { timeout : 10000 } ) . should ( 'be.visible' ) ;
137- return false ; // break the loop
125+ // Check if there are any rows to clean up
126+ cy . get ( 'tbody' ) . then ( ( $tbody ) => {
127+ if ( $tbody . find ( 'tr' ) . length > 0 ) {
128+ // Find and delete the test user
129+ cy . get ( '#deviceUserFirstName' ) . each ( ( $el , index ) => {
130+ if ( $el . text ( ) === nameDeviceUser ) {
131+ cy . intercept ( 'POST' , '**/api/device-users/delete' ) . as ( 'deleteUser' ) ;
132+ cy . intercept ( 'POST' , '**/api/device-users/index' ) . as ( 'reloadDeviceUsers' ) ;
133+ cy . get ( '#deleteDeviceUserBtn' ) . eq ( index ) . click ( ) ;
134+ cy . get ( '#saveDeleteBtn' ) . should ( 'be.visible' ) . click ( ) ;
135+ cy . wait ( '@deleteUser' , { timeout : 30000 } ) ;
136+ cy . wait ( '@reloadDeviceUsers' , { timeout : 30000 } ) ;
137+ cy . get ( '#newDeviceUserBtn' , { timeout : 10000 } ) . should ( 'be.visible' ) ;
138+ return false ; // break the loop
139+ }
140+ } ) ;
138141 }
139- } ) ;
140142
141- // Ensure table is visible before counting rows
142- cy . get ( 'tbody > tr' , { timeout : 10000 } ) . should ( 'have.length.gt' , 0 ) ;
143-
144- // Verify count is back to original
145- deviceUsersPage . rowNum ( ) . then ( ( currentCount ) => {
146- expect ( currentCount ) . to . equal ( countDeviceUsersBeforeCreating ) ;
143+ // Verify count is back to original
144+ cy . get ( 'tbody' ) . then ( ( $tbody2 ) => {
145+ const currentCount = $tbody2 . find ( 'tr' ) . length ;
146+ expect ( currentCount ) . to . equal ( countDeviceUsersBeforeCreating ) ;
147+ } ) ;
147148 } ) ;
148149 } ) ;
149150} ) ;
0 commit comments