Skip to content

Commit aba366b

Browse files
authored
Merge pull request #335 from mansoorkhan96/add-docs-for-withiniframe-resize-and-wait
feat: add docs for withinIframe resize and wait
2 parents f2fd7e0 + 2d3a0a2 commit aba366b

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

browser-testing.md

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Browser Testing
3-
description:
3+
description:
44
---
55

66
# Browser Testing
@@ -20,7 +20,7 @@ This is a basic example of a browser test that checks if the homepage contains t
2020
Here is an example of a more complex browser test, on Laravel, that checks if a user can sign in:
2121

2222
```php
23-
it('may sign in the user', function () {
23+
it('may sign in the user', function () {
2424
Event::fake();
2525

2626
User::factory()->create([ // assumes RefreshDatabase trait is used on Pest.php...
@@ -167,13 +167,13 @@ You can locate elements in the DOM using text or CSS selectors. Pest provides a
167167
$page->click('Login');
168168

169169
// Clicks the first element with the class "btn-primary"
170-
$page->click('.btn-primary');
170+
$page->click('.btn-primary');
171171

172172
// Clicks the element with the data-test attribute "login"
173-
$page->click('@login');
173+
$page->click('@login');
174174

175175
// Clicks the element with the ID "submit-button"
176-
$page->click('#submit-button');
176+
$page->click('#submit-button');
177177

178178
// etc...
179179
```
@@ -273,6 +273,7 @@ pest()->browser()->userAgent('CustomUserAgent');
273273
[attribute](#attribute)
274274
[keys](#keys)
275275
[type](#type)
276+
[typeSlowly](#type-slowly)
276277
[select](#select)
277278
[append](#append)
278279
[clear](#clear)
@@ -286,6 +287,8 @@ pest()->browser()->userAgent('CustomUserAgent');
286287
[hover](#hover)
287288
[submit](#submit)
288289
[value](#value)
290+
[withinIframe](#within-iframe)
291+
[resize](#resize)
289292
[script](#script)
290293
[content](#content)
291294
[url](#url)
@@ -300,6 +303,7 @@ pest()->browser()->userAgent('CustomUserAgent');
300303

301304
[debug](#debug)
302305
[screenshot](#screenshot)
306+
[screenshotElement](#screenshot-element)
303307
[tinker](#tinker)
304308
[headed](#headed)
305309

@@ -874,6 +878,12 @@ The `click` method clicks the link with the given text:
874878
$page->click('Login');
875879
```
876880

881+
You may also pass options:
882+
883+
```php
884+
$page->click('#button', options: ['clickCount' => 2]);
885+
```
886+
877887
<a name="text"></a>
878888
### text
879889

@@ -911,6 +921,16 @@ The `type` method types the given value in the given field:
911921
$page->type('email', 'test@example.com');
912922
```
913923

924+
<a name="type-slowly"></a>
925+
926+
### typeSlowly
927+
928+
The `typeSlowly` method types the given value in the given field slowly, like a user:
929+
930+
```php
931+
$page->typeSlowly('email', 'test@example.com');
932+
```
933+
914934
<a name="select"></a>
915935
### select
916936

@@ -1031,6 +1051,31 @@ The `value` method gets the value of the element matching the given selector:
10311051
$value = $page->value('input[name=email]');
10321052
```
10331053

1054+
<a name="with-in-iframe"></a>
1055+
1056+
### withinIframe
1057+
1058+
The `withinIframe` method allows you to interact with elements inside an iframe:
1059+
1060+
```php
1061+
use Pest\Browser\Api\PendingAwaitablePage;
1062+
1063+
$page->withinIframe('.iframe-container', function (PendingAwaitablePage $page) {
1064+
$page->type('frame-input', 'Hello iframe')
1065+
->click('frame-button');
1066+
});
1067+
```
1068+
1069+
<a name="resize"></a>
1070+
1071+
### resize
1072+
1073+
You may use the resize method to adjust the size of the browser window:
1074+
1075+
```php
1076+
$page->resize(1280, 720);
1077+
```
1078+
10341079
<a name="script"></a>
10351080
### script
10361081

@@ -1094,12 +1139,21 @@ $page->debug();
10941139
<a name="screenshot"></a>
10951140
You can also take a screenshot of the current page using the `screenshot()` method. This is useful for visual debugging:
10961141

1142+
NOTE: If you don't pass the filename, it will use the test name as the filename.
1143+
10971144
```php
10981145
$page->screenshot();
10991146
$page->screenshot(fullPage: true);
11001147
$page->screenshot(filename: 'custom-name');
11011148
```
11021149

1150+
<a name="screenshotElement"></a>
1151+
You can also take a screenshot of a specific element using the `screenshotElement()` method:
1152+
1153+
```php
1154+
$page->screenshotElement('#my-element');
1155+
```
1156+
11031157
<a name="tinker"></a>
11041158
You can also use the `tinker()` method to open a Tinker session in the context of the current page. This allows you to interact with the page using PHP code:
11051159

0 commit comments

Comments
 (0)