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 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 * Assert specified rcmail.env value
*/ */

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

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

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

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

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

Loading…
Cancel
Save