@@ -38,12 +38,26 @@ Cypress.Commands.add("clickDataTableMoreButtonItem", (element, rowIndex = 0) =>
3838} ) ;
3939
4040Cypress . Commands . add ( "clickElement" , ( element , isForce = false , index = 0 ) => {
41- cy . getElement ( element ) . eq ( index ) . click ( { force : isForce } ) ;
41+
42+ if ( isForce ) {
43+ cy . getElement ( element )
44+ . eq ( index )
45+ . click ( { force : true } ) ;
46+ }
47+ else {
48+ cy . getElement ( element )
49+ . filter ( ':visible' )
50+ . eq ( index )
51+ . should ( 'exist' )
52+ . and ( 'not.be.disabled' )
53+ . click ( ) ;
54+ }
55+
4256 cy . checkPaceRunning ( ) ;
4357} ) ;
4458
4559Cypress . Commands . add ( "clickBody" , ( ) => {
46- cy . get ( 'body' ) . click ( { force : true } ) ;
60+ cy . get ( 'body' , { log : false } ) . click ( 0 , 0 ) ;
4761 cy . checkPaceRunning ( ) ;
4862} ) ;
4963
@@ -76,7 +90,7 @@ Cypress.Commands.add("selectCheckboxOption", (element, ...options) => {
7690} ) ;
7791
7892Cypress . Commands . add ( "clickOption" , ( element , option ) => {
79- cy . getElement ( element ) . contains ( new RegExp ( "^" + option + "$" , "g" ) ) . click ( { force : true } ) ;
93+ cy . getElement ( element ) . contains ( new RegExp ( "^" + option + "$" , "g" ) ) . click ( { force : true } ) ;
8094} ) ;
8195
8296Cypress . Commands . add ( "selectValue" , ( element , valueText ) => {
@@ -181,18 +195,17 @@ Cypress.Commands.add("shouldUrlInclude", (url) => {
181195 cy . url ( ) . should ( 'include' , url ) ;
182196} ) ;
183197
184- Cypress . Commands . add ( 'elementExists' , ( selector ) => {
185-
186- cy . wait ( 500 ) ;
187- if ( ! selector . includes ( ' [data-test-id=' ) && ( ! selector [ 0 ] . includes ( '.' ) || ! selector [ 0 ] . includes ( '#' ) ) ) {
188- selector = `[data-test-id=" ${ selector } "]` ;
198+ Cypress . Commands . add ( 'elementExists' , ( selector , { parent = 'body' } = { } ) => {
199+ if ( ! selector . includes ( '[data-test-id=' ) ) {
200+ if ( ! ( selector . startsWith ( '.' ) || selector . startsWith ( '#' ) ) ) {
201+ selector = ` [data-test-id=" ${ selector } "]` ;
202+ }
189203 }
190204
191- cy
192- . get ( 'body' )
193- . then ( ( $body ) => {
194- return $body . find ( selector ) . length > 0 ;
195- } ) ;
205+ return cy . get ( parent , { log : false } ) . then ( $parent => {
206+ const exists = $parent . find ( selector ) . length > 0 ;
207+ return exists ;
208+ } ) ;
196209} ) ;
197210
198211Cypress . Commands . add ( 'shouldBeExist' , ( element ) => {
@@ -204,23 +217,20 @@ Cypress.Commands.add('shouldNotExist', (element) => {
204217} ) ;
205218
206219Cypress . Commands . add ( 'checkPaceRunning' , ( ) => {
207- cy
208- . elementExists ( '.pace-running' )
209- . then ( ( isExists ) => {
210- if ( isExists ) {
211- cy . shouldNotExist ( '.pace-running' ) ;
212- }
213- } ) ;
220+ cy . get ( '.pace-running' , { timeout : 10000 } ) . should ( 'not.exist' ) ;
214221} ) ;
215222
216223Cypress . Commands . add ( 'checkPaceActive' , ( ) => {
217- cy
218- . elementExists ( '.pace-active' )
219- . then ( ( isExists ) => {
220- if ( isExists ) {
221- cy . shouldNotExist ( '.pace-active' ) ;
222- }
223- } ) ;
224+ cy . get ( '.pace-active' , { timeout : 10000 } ) . should ( 'not.exist' ) ;
225+ } ) ;
226+
227+ Cypress . Commands . add ( 'checkLoading' , ( ) => {
228+ cy . get ( 'body' ) . then ( $body => {
229+ if ( $body . find ( '.el-loading-mask' ) . length ) {
230+ cy . get ( '.el-loading-mask' , { timeout : 20000 } )
231+ . should ( 'not.be.visible' ) ;
232+ }
233+ } ) ;
224234} ) ;
225235
226236Cypress . Commands . add ( "scrollPageSlightly" , ( element = '.main-view' , index = 0 ) => {
@@ -362,7 +372,7 @@ Cypress.Commands.add('dropMongoDatabase', () => {
362372Cypress . Commands . add ( 'getElement' , ( selector , parent = null ) => {
363373
364374 if ( ! selector . includes ( '[data-test-id=' ) ) {
365- if ( selector [ 0 ] . includes ( '.' ) || selector [ 0 ] . includes ( '#' ) ) {
375+ if ( selector . startsWith ( '.' ) || selector . startsWith ( '#' ) ) {
366376 return cy . get ( selector ) ;
367377 }
368378 else {
0 commit comments