@@ -94,23 +94,25 @@ export class BaseMethods {
94
94
95
95
async checkElementVisibility ( { selector, isVisible = true , text, parentSelector } : VisibilityOptions ) : Promise < void > {
96
96
const locator = this . resolveLocator ( selector , { parentSelector, text } ) ;
97
- const count = await locator . count ( ) ;
98
97
99
98
if ( isVisible ) {
100
- expect ( count ) . toBeGreaterThan ( 0 ) ;
99
+ await expect ( locator . first ( ) ) . toBeVisible ( ) ;
100
+ const count = await locator . count ( ) ;
101
101
for ( let index = 0 ; index < count ; index ++ ) {
102
102
await expect ( locator . nth ( index ) ) . toBeVisible ( ) ;
103
103
}
104
104
105
105
return ;
106
106
}
107
107
108
- if ( count === 0 ) {
108
+ try {
109
+ await expect ( locator ) . toHaveCount ( 0 ) ;
109
110
return ;
110
- }
111
-
112
- for ( let index = 0 ; index < count ; index ++ ) {
113
- await expect ( locator . nth ( index ) ) . not . toBeVisible ( ) ;
111
+ } catch ( error ) {
112
+ const count = await locator . count ( ) ;
113
+ for ( let index = 0 ; index < count ; index ++ ) {
114
+ await expect ( locator . nth ( index ) ) . not . toBeVisible ( ) ;
115
+ }
114
116
}
115
117
}
116
118
@@ -127,29 +129,54 @@ export class BaseMethods {
127
129
if ( isMultiple ) {
128
130
const baseLocator = this . resolveLocator ( selector , { parentSelector } ) ;
129
131
const filtered = baseLocator . filter ( { hasText : text } ) ;
130
- const count = await filtered . count ( ) ;
131
- expect ( count ) . toBeGreaterThan ( 0 ) ;
132
- for ( let i = 0 ; i < count ; i ++ ) {
133
- if ( visibilityState === 'be.visible' ) {
132
+
133
+ if ( ! isVisible ) {
134
+ if ( notVisibleState === 'not.exist' ) {
135
+ await expect ( filtered ) . toHaveCount ( 0 ) ;
136
+ return ;
137
+ }
138
+
139
+ const count = await filtered . count ( ) ;
140
+
141
+ if ( count === 0 ) {
142
+ await expect ( filtered ) . toHaveCount ( 0 ) ;
143
+ return ;
144
+ }
145
+
146
+ for ( let i = 0 ; i < count ; i ++ ) {
147
+ await expect ( filtered . nth ( i ) ) . not . toBeVisible ( ) ;
148
+ }
149
+
150
+ return ;
151
+ }
152
+
153
+ if ( visibilityState === 'be.visible' ) {
154
+ await expect ( filtered . first ( ) ) . toBeVisible ( ) ;
155
+ const count = await filtered . count ( ) ;
156
+ for ( let i = 0 ; i < count ; i ++ ) {
134
157
await expect ( filtered . nth ( i ) ) . toBeVisible ( ) ;
135
- } else {
136
- await expect ( filtered . nth ( i ) ) . toContainText ( text ) ;
137
158
}
159
+
160
+ return ;
138
161
}
139
162
163
+ await expect ( filtered ) . not . toHaveCount ( 0 ) ;
164
+
140
165
return ;
141
166
}
142
167
143
168
const locator = this . resolveLocator ( selector , { parentSelector, text, index } ) ;
144
- const count = await locator . count ( ) ;
145
169
146
170
if ( ! isVisible ) {
147
- if ( count === 0 ) {
171
+ if ( notVisibleState === 'not.exist' ) {
172
+ await expect ( locator ) . toHaveCount ( 0 ) ;
148
173
return ;
149
174
}
150
175
151
- if ( notVisibleState === 'not.exist' ) {
152
- expect ( count ) . toBe ( 0 ) ;
176
+ const count = await locator . count ( ) ;
177
+
178
+ if ( count === 0 ) {
179
+ await expect ( locator ) . toHaveCount ( 0 ) ;
153
180
return ;
154
181
}
155
182
@@ -161,15 +188,16 @@ export class BaseMethods {
161
188
}
162
189
163
190
if ( visibilityState === 'be.visible' ) {
164
- expect ( count ) . toBeGreaterThan ( 0 ) ;
191
+ await expect ( locator . first ( ) ) . toBeVisible ( ) ;
192
+ const count = await locator . count ( ) ;
165
193
for ( let i = 0 ; i < count ; i ++ ) {
166
194
await expect ( locator . nth ( i ) ) . toBeVisible ( ) ;
167
195
}
168
196
169
197
return ;
170
198
}
171
199
172
- expect ( count ) . toBeGreaterThan ( 0 ) ;
200
+ await expect ( locator ) . not . toHaveCount ( 0 ) ;
173
201
}
174
202
175
203
async clickElementWithText ( { selector, text, parentSelector, isTargetChanged = false , index } : ClickWithTextOptions ) : Promise < void > {
@@ -300,15 +328,15 @@ export class BaseMethods {
300
328
}
301
329
302
330
async checkUrlText ( urlPart : string , isInclude : boolean = false ) : Promise < void > {
303
- const currentUrl = this . page . url ( ) ;
331
+ const poller = expect . poll ( ( ) => this . page . url ( ) ) ;
304
332
305
333
if ( isInclude ) {
306
- expect ( currentUrl ) . toContain ( urlPart ) ;
334
+ await poller . toContain ( urlPart ) ;
307
335
308
336
return ;
309
337
}
310
338
311
- expect ( currentUrl ) . not . toContain ( urlPart ) ;
339
+ await poller . not . toContain ( urlPart ) ;
312
340
}
313
341
314
342
async compareInfoBetweenHosts (
0 commit comments