77use Generator ;
88use Pest \Browser \Playwright \Concerns \InteractsWithPlaywright ;
99use Pest \Browser \Support \Selector ;
10+ use PHPUnit \Framework \ExpectationFailedException ;
1011use RuntimeException ;
12+ use WebSocket \TimeoutException ;
1113
1214/**
1315 * @internal
@@ -31,6 +33,8 @@ public function __construct(
3133 */
3234 public function isVisible (): bool
3335 {
36+ $ this ->waitFor ();
37+
3438 $ response = $ this ->sendMessage ('isVisible ' );
3539
3640 return $ this ->processBooleanResponse ($ response );
@@ -41,6 +45,8 @@ public function isVisible(): bool
4145 */
4246 public function isChecked (): bool
4347 {
48+ $ this ->waitFor ();
49+
4450 $ response = $ this ->sendMessage ('isChecked ' );
4551
4652 return $ this ->processBooleanResponse ($ response );
@@ -51,6 +57,8 @@ public function isChecked(): bool
5157 */
5258 public function isEnabled (): bool
5359 {
60+ $ this ->waitFor ();
61+
5462 $ response = $ this ->sendMessage ('isEnabled ' );
5563
5664 return $ this ->processBooleanResponse ($ response );
@@ -61,22 +69,32 @@ public function isEnabled(): bool
6169 */
6270 public function isDisabled (): bool
6371 {
64- return ! $ this ->isEnabled ();
72+ $ this ->waitFor ();
73+
74+ $ response = $ this ->sendMessage ('isDisabled ' );
75+
76+ return $ this ->processBooleanResponse ($ response );
6577 }
6678
6779 /**
6880 * Check if element matching the locator is hidden.
6981 */
7082 public function isHidden (): bool
7183 {
72- return ! $ this ->isVisible ();
84+ $ this ->waitFor (['state ' => 'hidden ' ]);
85+
86+ $ response = $ this ->sendMessage ('isHidden ' );
87+
88+ return $ this ->processBooleanResponse ($ response );
7389 }
7490
7591 /**
7692 * Check if element matching the locator is editable.
7793 */
7894 public function isEditable (): bool
7995 {
96+ $ this ->waitFor ();
97+
8098 $ response = $ this ->sendMessage ('isEditable ' );
8199
82100 return $ this ->processBooleanResponse ($ response );
@@ -87,7 +105,10 @@ public function isEditable(): bool
87105 */
88106 public function check (): void
89107 {
108+ $ this ->waitFor ();
109+
90110 $ response = $ this ->sendMessage ('check ' );
111+
91112 $ this ->processVoidResponse ($ response );
92113 }
93114
@@ -263,8 +284,13 @@ public function getAttribute(string $name): ?string
263284 */
264285 public function waitFor (?array $ options = null ): void
265286 {
266- $ response = $ this ->sendMessage ('waitForSelector ' , $ options ?? []);
267- $ this ->processVoidResponse ($ response );
287+ try {
288+ $ response = $ this ->sendMessage ('waitForSelector ' , $ options ?? []);
289+
290+ $ this ->processVoidResponse ($ response );
291+ } catch (TimeoutException ) {
292+ throw new ExpectationFailedException ('Element not found. ' );
293+ }
268294 }
269295
270296 /**
0 commit comments