You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dusk.md
+94Lines changed: 94 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -522,6 +522,16 @@ Sometimes you may wish to perform several operations while scoping all of the op
522
522
->clickLink('Delete');
523
523
});
524
524
525
+
You may also wish to execute assertions outside of the current scope. For example, you may wish to interact with a portion of the web page outside of the current scope such as in a component. You may use the `elsewhere` method to accomplish this. The operations performed in the callback will break the current scope to the given one.
526
+
527
+
$browser->with('.table', function ($table) {
528
+
// selector is `body .table`
529
+
$browser->elsewhere('.page-title', function ($title) {
530
+
// selector is `body .page-title`
531
+
$title->assertSee('Hello World');
532
+
});
533
+
});
534
+
525
535
<aname="waiting-for-elements"></a>
526
536
### Waiting For Elements
527
537
@@ -1442,6 +1452,90 @@ Once the component has been defined, we can easily select a date within the date
1442
1452
});
1443
1453
}
1444
1454
}
1455
+
1456
+
#### Non-Standard Components
1457
+
1458
+
Sometimes a given component does not have a single ancestor in the dom, this can occur in scenarios where popups are rendered to a seperate node such as this custom dropdown component.
It makes sense to define the logic for interacting with this component in the same component class, but because they have seperate ancestors selecting the second portion with a scoped selector becomes untenable. In this scenarios you may bypass the current selector scope with the `elsewhere` method.
1476
+
1477
+
<?php
1478
+
1479
+
namespace Tests\Browser\Components;
1480
+
1481
+
use Laravel\Dusk\Browser;
1482
+
use Laravel\Dusk\Component as BaseComponent;
1483
+
1484
+
class DropdownPicker extends BaseComponent
1485
+
{
1486
+
/**
1487
+
* Get the root selector for the component.
1488
+
*
1489
+
* @return string
1490
+
*/
1491
+
public function selector()
1492
+
{
1493
+
return '.dropdown';
1494
+
}
1495
+
1496
+
/**
1497
+
* Assert that the browser page contains the component.
1498
+
*
1499
+
* @param Browser $browser
1500
+
* @return void
1501
+
*/
1502
+
public function assert(Browser $browser)
1503
+
{
1504
+
$browser->assertVisible($this->selector());
1505
+
}
1506
+
1507
+
/**
1508
+
* Get the element shortcuts for the component.
1509
+
*
1510
+
* @return array
1511
+
*/
1512
+
public function elements()
1513
+
{
1514
+
return [
1515
+
'@toggle' => '.dropdown-toggle',
1516
+
'@list' => '.dropdown-menu .dropdown-list',
1517
+
];
1518
+
}
1519
+
1520
+
/**
1521
+
* Select the given option.
1522
+
*
1523
+
* @param \Laravel\Dusk\Browser $browser
1524
+
* @param string $value
1525
+
* @return void
1526
+
*/
1527
+
public function selectFromDropdown($browser, $value)
1528
+
{
1529
+
// selector is `body .dropdown`
1530
+
$browser->click('@toggle')
1531
+
->elsewhere('@list', function ($browser) use ($value) {
1532
+
// selector is `body .dropdown-menu .dropdown-list`
0 commit comments