Tests: Add Browser::assertElementsCount() helper

pull/7181/head
Aleksander Machniak 5 years ago
parent c2e348067e
commit 5c73848499

@ -11,6 +11,27 @@ use Tests\Browser\Components;
*/
class Browser extends \Laravel\Dusk\Browser
{
/**
* Assert number of (visible) elements
*/
public function assertElementsCount($selector, $expected_count, $visible = true)
{
$elements = $this->elements($selector);
$count = count($elements);
if ($visible) {
foreach ($elements as $element) {
if (!$element->isDisplayed()) {
$count--;
}
}
}
Assert::assertEquals($expected_count, $count);
return $this;
}
/**
* Assert specified rcmail.env value
*/

@ -70,11 +70,10 @@ class Groups extends \Tests\Browser\TestCase
$browser->waitUntilMissing('.ui-dialog');
$browser->with('#directorylist', function ($browser) {
$browser->waitFor('li:first-child ul.groups');
$browser->assertVisible('.treetoggle.expanded');
$this->assertCount(1, $browser->elements('ul.groups > li.contactgroup'));
$browser->assertSeeIn('ul.groups > li.contactgroup', 'New Group');
$browser->waitFor('li:first-child ul.groups')
->assertVisible('.treetoggle.expanded')
->assertElementsCount('ul.groups > li.contactgroup', 1)
->assertSeeIn('ul.groups > li.contactgroup', 'New Group');
// Test expand toggle
$browser->click('.treetoggle.expanded')
@ -123,11 +122,10 @@ class Groups extends \Tests\Browser\TestCase
$browser->waitUntilMissing('.ui-dialog');
$browser->with('#directorylist', function ($browser) {
$browser->waitFor('li:first-child ul.groups');
$browser->assertVisible('.treetoggle.expanded');
$this->assertCount(1, $browser->elements('ul.groups > li.contactgroup'));
$browser->assertSeeIn('ul.groups > li.contactgroup', 'Renamed');
$browser->waitFor('li:first-child ul.groups')
->assertVisible('.treetoggle.expanded')
->assertElementsCount('ul.groups > li.contactgroup', 1)
->assertSeeIn('ul.groups > li.contactgroup', 'Renamed');
// Test if expand toggle is still working
$browser->click('.treetoggle.expanded')

@ -63,7 +63,7 @@ class Import extends \Tests\Browser\TestCase
$browser->waitForText('Attention');
$browser->assertSee('Please select a file');
$browser->driver->getKeyboard()->sendKeys(\Facebook\WebDriver\WebDriverKeys::ESCAPE);
$this->assertCount(1, $browser->elements('.ui-dialog'));
$browser->assertElementsCount('.ui-dialog', 1);
$browser->withinFrame('.ui-dialog iframe', function ($browser) {
$browser->attach('.custom-file input', TESTS_DIR . 'data/contacts.vcf');
@ -79,9 +79,9 @@ class Import extends \Tests\Browser\TestCase
$browser->click('.ui-dialog button.cancel');
// Expected existing contacts + imported
$browser->waitFor('#contacts-table tr');
$this->assertCount(4, $browser->elements('#contacts-table tbody tr'));
$browser->assertSeeIn('#rcmcountdisplay', '1 4 of 4');
$browser->waitFor('#contacts-table tr')
->assertElementsCount('#contacts-table tbody tr', 4)
->assertSeeIn('#rcmcountdisplay', '1 4 of 4');
});
}

@ -26,7 +26,7 @@ class Getunread extends \Tests\Browser\TestCase
$browser->waitFor('#messagelist tbody tr');
// Messages list state
$this->assertCount(self::$msgcount, $browser->elements('#messagelist tbody tr.unread'));
$browser->assertElementsCount('#messagelist tbody tr.unread', self::$msgcount);
if (!$browser->isDesktop()) {
$browser->click('.back-sidebar-button');

@ -25,7 +25,7 @@ class MailList extends \Tests\Browser\TestCase
$this->browse(function ($browser) {
$browser->go('mail');
$this->assertCount(self::$msgcount, $browser->elements('#messagelist tbody tr'));
$browser->assertElementsCount('#messagelist tbody tr', self::$msgcount);
// check message list
$browser->assertVisible('#messagelist tbody tr:first-child.unread');

@ -132,11 +132,9 @@ class Preview extends \Tests\Browser\TestCase
->with('.ui-dialog', function ($browser) {
$browser->assertSeeIn('.ui-dialog-titlebar', 'Cc')
->assertSeeIn('.ui-dialog-content', 'test1@domain.tld')
->assertSeeIn('.ui-dialog-content', 'test12@domain.tld');
$this->assertCount(12, $browser->elements('span.adr'));
$browser->click('.ui-dialog-buttonset button.cancel');
->assertSeeIn('.ui-dialog-content', 'test12@domain.tld')
->assertElementsCount('span.adr', 12)
->click('.ui-dialog-buttonset button.cancel');
});
$browser->waitUntilMissing('.ui-dialog');
@ -144,8 +142,8 @@ class Preview extends \Tests\Browser\TestCase
// Attachments list
$browser->withinFrame('#messagecontframe', function ($browser) {
$browser->with('#attachment-list', function ($browser) {
$this->assertCount(2, $browser->elements('li'));
$browser->assertVisible('li.text.plain')
$browser->assertElementsCount('li', 2)
->assertVisible('li.text.plain')
->assertSeeIn('li:first-child .attachment-name', 'lines.txt')
->assertSeeIn('li:first-child .attachment-size', '(~13 B)')
->assertSeeIn('li:last-child .attachment-name', 'lines_lf.txt')

Loading…
Cancel
Save