Make testing in all phone/tablet/desktop modes of Elastic possible

pull/7143/head
Aleksander Machniak 5 years ago
parent a32e2b4c6f
commit 934382c91f

@ -14,7 +14,7 @@ class Contacts extends \Tests\Browser\DuskTestCase
/**
* Contacts UI Basics
*/
public function testAddressbook()
public function testContactsUI()
{
$this->browse(function ($browser) {
$this->go('addressbook');
@ -30,6 +30,11 @@ class Contacts extends \Tests\Browser\DuskTestCase
$this->assertContains('contactslist', $objects);
$this->assertContains('countdisplay', $objects);
if (!$this->isDesktop()) {
$browser->assertMissing('#directorylist');
$browser->click('a.back-sidebar-button');
}
$browser->assertSeeIn('#layout-sidebar .header', 'Groups');
// Groups/Addressbooks list
@ -38,34 +43,41 @@ class Contacts extends \Tests\Browser\DuskTestCase
$browser->assertMissing('#directorylist .treetoggle.expanded');
// Contacts list
$browser->assertVisible('#contacts-table');
if (!$this->isDesktop()) {
$browser->assertMissing('#contacts-table');
$browser->click('#directorylist li:first-child');
$browser->waitFor('#contacts-table');
}
else {
$browser->assertVisible('#contacts-table');
}
// Contacts list menu
$browser->assertVisible('#toolbar-list-menu a.select:not(.disabled)');
if ($this->isPhone()) {
$this->assertToolbarMenu(['select'], []);
}
else if ($this->isTablet()) {
$browser->click('.toolbar-list-button');
$browser->assertVisible('#toolbar-list-menu a.select:not(.disabled)');
$browser->click();
}
else {
$browser->assertVisible('#toolbar-list-menu a.select:not(.disabled)');
}
// Toolbar menu
$browser->with('#toolbar-menu', function($browser) {
$browser->assertVisible('a.create:not(.disabled)');
$browser->assertVisible('a.print.disabled');
$browser->assertVisible('a.delete.disabled');
$browser->assertVisible('a.search:not(.disabled)');
$browser->assertVisible('a.import:not(.disabled)');
$browser->assertVisible('a.export:not(.disabled)');
$browser->assertVisible('a.more.disabled');
});
$this->assertToolbarMenu(
['create', 'search', 'import', 'export'], // active items
['print', 'delete', 'more'], // inactive items
);
// Contact frame
$browser->assertVisible('#contact-frame');
if (!$this->isPhone()) {
$browser->assertVisible('#contact-frame');
}
// Task menu
$browser->with('#taskmenu', function($browser) {
$browser->assertVisible('a.compose:not(.disabled):not(.selected)');
$browser->assertVisible('a.mail:not(.disabled):not(.selected)');
$browser->assertVisible('a.contacts.selected');
$browser->assertVisible('a.settings:not(.disabled):not(.selected)');
$browser->assertVisible('a.about:not(.disabled):not(.selected)');
$browser->assertVisible('a.logout:not(.disabled):not(.selected)');
});
$this->assertTaskMenu('contacts');
});
}
}

@ -12,7 +12,7 @@ class Import extends \Tests\Browser\DuskTestCase
$this->browse(function ($browser) {
$this->go('addressbook');
$browser->click('#toolbar-menu a.import');
$this->clickToolbarMenuItem('import');
$browser->assertSeeIn('.ui-dialog-title', 'Import contacts');
$browser->assertVisible('.ui-dialog button.mainaction.import');
@ -52,7 +52,7 @@ class Import extends \Tests\Browser\DuskTestCase
{
$this->browse(function ($browser) {
// Open the dialog again
$browser->click('#toolbar-menu a.import');
$this->clickToolbarMenuItem('import');
$browser->assertSeeIn('.ui-dialog-title', 'Import contacts');
// Submit the form with no file attached

@ -41,11 +41,27 @@ abstract class DuskTestCase extends TestCase
protected function driver()
{
$options = (new ChromeOptions())->addArguments([
'--lang=en_US',
'--disable-gpu',
'--headless',
'--window-size=1280,720',
]);
if (getenv('TESTS_MODE') == 'phone') {
// Fake User-Agent string for mobile mode
$ua = 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Mobile Safari/537.36';
$options->setExperimentalOption('mobileEmulation', ['userAgent' => $ua]);
$options->addArguments(['--window-size=375,667']);
}
else if (getenv('TESTS_MODE') == 'tablet') {
// Fake User-Agent string for mobile mode
$ua = 'Mozilla/5.0 (Linux; Android 6.0.1; vivo 1603 Build/MMB29M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.83 Mobile Safari/537.36';
$options->setExperimentalOption('mobileEmulation', ['userAgent' => $ua]);
$options->addArguments(['--window-size=1024,768']);
}
else {
$options->addArguments(['--window-size=1280,720']);
}
return RemoteWebDriver::create(
'http://localhost:9515',
DesiredCapabilities::chrome()->setCapability(
@ -108,6 +124,30 @@ abstract class DuskTestCase extends TestCase
}
}
/**
* Check if in Phone mode
*/
public static function isPhone()
{
return getenv('TESTS_MODE') == 'phone';
}
/**
* Check if in Tablet mode
*/
public static function isTablet()
{
return getenv('TESTS_MODE') == 'tablet';
}
/**
* Check if in Desktop mode
*/
public static function isDesktop()
{
return !self::isPhone() && !self::isTablet();
}
/**
* Assert specified rcmail.env value
*/
@ -131,6 +171,123 @@ abstract class DuskTestCase extends TestCase
});
}
/**
* Assert Task menu state
*/
protected function assertTaskMenu($selected)
{
$this->browse(function (Browser $browser) use ($selected) {
// On phone the menu is invisible, open it
if ($this->isPhone()) {
$browser->click('.task-menu-button');
}
$browser->with('#taskmenu', function(Browser $browser) use ($selected) {
$options = ['compose', 'mail', 'contacts', 'settings', 'about', 'logout'];
foreach ($options as $option) {
$browser->assertVisible("a.{$option}:not(.disabled)" . ($selected == $option ? ".selected" : ":not(.selected)"));
}
});
// hide the menu back
if ($this->isPhone()) {
$browser->click('.popover a.button.cancel');
$browser->waitUntilMissing('#taskmenu');
}
});
}
/**
* Assert toolbar menu state
*/
protected function assertToolbarMenu($active, $disabled)
{
$this->browse(function (Browser $browser) use ($active, $disabled) {
// On phone the menu is invisible, open it
if ($this->isPhone()) {
$browser->click('.toolbar-menu-button');
}
$browser->with('#toolbar-menu', function(Browser $browser) use ($active, $disabled) {
foreach ($active as $option) {
// Print action is disabled on phones
if ($option == 'print' && $this->isPhone()) {
$browser->assertMissing("a.print");
}
else {
$browser->assertVisible("a.{$option}:not(.disabled)");
}
}
foreach ($disabled as $option) {
if ($option == 'print' && $this->isPhone()) {
$browser->assertMissing("a.print");
}
else {
$browser->assertVisible("a.{$option}.disabled");
}
}
});
$this->closeToolbarMenu();
});
}
/**
* Close toolbar menu (on phones)
*/
protected function closeToolbarMenu()
{
// hide the menu back
if ($this->isPhone()) {
$this->browse(function (Browser $browser) {
$browser->script("window.UI.menu_hide('toolbar-menu')");
$browser->waitUntilMissing('#toolbar-menu');
// FIXME: For some reason sometimes .popover-overlay does not close,
// we have to remove it manually
$browser->script(
"Array.from(document.getElementsByClassName('popover-overlay')).forEach(function(elem) { elem.parentNode.removeChild(elem); })"
);
});
}
}
/**
* Select taskmenu item
*/
protected function clickTaskMenuItem($name)
{
$this->browse(function (Browser $browser) use ($name) {
if ($this->isPhone()) {
$browser->click('.task-menu-button');
}
$browser->click("#taskmenu a.{$name}");
if ($this->isPhone()) {
$browser->waitUntilMissing('#taskmenu');
}
});
}
/**
* Select toolbar menu item
*/
protected function clickToolbarMenuItem($name)
{
$this->browse(function (Browser $browser) use ($name) {
if ($this->isPhone()) {
$browser->click('.toolbar-menu-button');
}
$browser->click("#toolbar-menu a.{$name}");
if ($this->isPhone()) {
$this->closeToolbarMenu();
// $browser->waitUntilMissing('#toolbar-menu');
}
});
}
/**
* Get content of rcmail.env entry
*/

@ -9,9 +9,8 @@ class Logout extends DuskTestCase
$this->browse(function ($browser) {
$this->go('settings');
// wait for the menu and then click the Logout button
$browser->waitFor('#taskmenu');
$browser->click('#taskmenu a.logout');
// click the Logout button in taskmenu
$this->clickTaskMenuItem('logout');
// task should be set to 'login'
$this->assertEnvEquals('task', 'login');

@ -9,7 +9,7 @@ class Compose extends \Tests\Browser\DuskTestCase
$this->browse(function ($browser) {
$this->go('mail');
$browser->click('#taskmenu a.compose');
$this->clickTaskMenuItem('compose');
// check task and action
$this->assertEnvEquals('task', 'mail');
@ -27,27 +27,23 @@ class Compose extends \Tests\Browser\DuskTestCase
$this->assertContains('uploadform', $objects);
// Toolbar menu
$browser->with('#toolbar-menu', function($browser) {
$browser->assertVisible('a.save.draft:not(.disabled)');
$browser->assertVisible('a.attach:not(.disabled)');
$browser->assertVisible('a.signature.disabled');
$browser->assertVisible('a.responses:not(.disabled)');
$browser->assertVisible('a.spellcheck:not(.disabled)');
});
$this->assertToolbarMenu(
['save.draft', 'responses', 'spellcheck'], // active items
['signature'], // inactive items
);
if ($this->isPhone()) {
$this->assertToolbarMenu(['options'], []);
}
else {
$this->assertToolbarMenu(['attach'], []);
$browser->assertMissing('#toolbar-menu a.options');
}
// Task menu
$browser->with('#taskmenu', function($browser) {
$browser->assertVisible('a.compose:not(.disabled).selected');
$browser->assertVisible('a.mail:not(.disabled):not(.selected)');
$browser->assertVisible('a.contacts:not(.disabled):not(.selected)');
$browser->assertVisible('a.settings:not(.disabled):not(.selected)');
$browser->assertVisible('a.about:not(.disabled):not(.selected)');
$browser->assertVisible('a.logout:not(.disabled):not(.selected)');
});
$this->assertTaskMenu('compose');
// Header inputs
$browser->assertSeeIn('#layout-sidebar .header', 'Options and attachments');
$browser->assertVisible('#compose-attachments');
$browser->assertVisible('#_from');
$browser->assertVisible('#compose-subject');
$browser->assertInputValue('#compose-subject', '');
@ -55,6 +51,14 @@ class Compose extends \Tests\Browser\DuskTestCase
// Mail body input
$browser->assertVisible('#composebodycontainer.html-editor');
$browser->assertVisible('#composebodycontainer > textarea');
if ($this->isPhone()) {
$this->clickToolbarMenuItem('options');
}
// Compose options
$browser->assertSeeIn('#layout-sidebar .header', 'Options and attachments');
$browser->assertVisible('#compose-attachments');
});
}
}

@ -25,13 +25,19 @@ class Getunread extends \Tests\Browser\DuskTestCase
$this->browse(function ($browser) {
$this->go('mail');
$browser->waitFor('#messagelist tbody tr');
// Messages list state
$this->assertCount($this->msgcount, $browser->elements('#messagelist tbody tr.unread'));
if (!$this->isDesktop()) {
$browser->click('.back-sidebar-button');
}
// Folders list state
$browser->waitFor('.folderlist li.inbox.unread');
$browser->assertVisible('.folderlist li.inbox.unread');
$this->assertEquals(strval($this->msgcount), $browser->text('.folderlist li.inbox span.unreadcount'));
// Messages list state
$this->assertCount($this->msgcount, $browser->elements('#messagelist tr.unread'));
});
}
}

@ -33,16 +33,58 @@ class MailList extends \Tests\Browser\DuskTestCase
$browser->assertPresent('#messagelist tbody tr:first-child span.msgicon.unread');
// List toolbar menu
$browser->assertVisible('#toolbar-list-menu a.select:not(.disabled)');
$browser->assertVisible('#toolbar-list-menu a.options:not(.disabled)');
$browser->assertVisible('a.toolbar-button.refresh:not(.disabled)');
$browser->assertVisible('#layout-list .header a.toolbar-button.refresh:not(.disabled)');
$imap = \bootstrap::get_storage();
if ($imap->get_threading()) {
$browser->assertVisible('#toolbar-list-menu a.threads:not(.disabled)');
if ($this->isDesktop()) {
$browser->with('#toolbar-list-menu', function ($browser) {
$browser->assertVisible('a.select:not(.disabled)');
$browser->assertVisible('a.options:not(.disabled)');
$imap = \bootstrap::get_storage();
if ($imap->get_threading()) {
$browser->assertVisible('a.threads:not(.disabled)');
}
else {
$browser->assertMissing('a.threads');
}
});
}
else {
$browser->assertMissing('#toolbar-list-menu a.threads');
else if ($this->isTablet()) {
$browser->click('.toolbar-list-button');
$browser->with('#toolbar-list-menu', function ($browser) {
$browser->assertVisible('a.select:not(.disabled)');
$browser->assertVisible('a.options:not(.disabled)');
$imap = \bootstrap::get_storage();
if ($imap->get_threading()) {
$browser->assertVisible('a.threads:not(.disabled)');
}
else {
$browser->assertMissing('a.threads');
}
});
$browser->click(); // hide the popup menu
}
else { // phone
// On phones list options are in the toolbar menu
$browser->click('.toolbar-menu-button');
$browser->with('#toolbar-menu', function ($browser) {
$browser->assertVisible('a.select:not(.disabled)');
$browser->assertVisible('a.options:not(.disabled)');
$imap = \bootstrap::get_storage();
if ($imap->get_threading()) {
$browser->assertVisible('a.threads:not(.disabled)');
}
else {
$browser->assertMissing('a.threads');
}
});
$this->closeToolbarMenu();
}
});
}
@ -53,8 +95,18 @@ class MailList extends \Tests\Browser\DuskTestCase
public function testListSelection()
{
$this->browse(function ($browser) {
$browser->click('#toolbar-list-menu a.select');
$browser->assertFocused('#toolbar-list-menu a.select');
if ($this->isPhone()) {
$browser->click('.toolbar-menu-button');
$browser->click('#toolbar-menu a.select');
}
else if ($this->isTablet()) {
$browser->click('.toolbar-list-button');
$browser->click('#toolbar-list-menu a.select');
}
else {
$browser->click('#toolbar-list-menu a.select');
$browser->assertFocused('#toolbar-list-menu a.select');
}
// Popup menu content
$browser->with('#listselect-menu', function($browser) {
@ -67,7 +119,7 @@ class MailList extends \Tests\Browser\DuskTestCase
$browser->assertVisible('a.select.none:not(.disabled)');
});
// Close the menu by clicking the page body
// Close the menu(s) by clicking the page body
$browser->click();
$browser->waitUntilMissing('#listselect-menu');

@ -22,34 +22,32 @@ class Mail extends \Tests\Browser\DuskTestCase
$this->assertContains('search_filter', $objects);
$this->assertContains('countdisplay', $objects);
if (!$this->isDesktop()) {
$browser->click('.back-sidebar-button');
}
$browser->assertSeeIn('#layout-sidebar .header', TESTS_USER);
// Folders list
$browser->assertVisible('#mailboxlist li.mailbox.inbox.selected');
if (!$this->isDesktop()) {
$browser->click('.back-list-button');
}
// Mail preview frame
$browser->assertVisible('#messagecontframe');
if (!$this->isPhone()) {
$browser->assertVisible('#messagecontframe');
}
// Toolbar menu
$browser->with('#toolbar-menu', function($browser) {
$browser->assertMissing('a.compose'); // this is always hidden button
$browser->assertVisible('a.reply.disabled');
$browser->assertVisible('a.reply-all.disabled');
$browser->assertVisible('a.forward.disabled');
$browser->assertVisible('a.delete.disabled');
$browser->assertVisible('a.markmessage.disabled');
$browser->assertVisible('a.more:not(.disabled)');
});
$this->assertToolbarMenu(
['more'], // active items
['reply', 'reply-all', 'forward', 'delete', 'markmessage'], // inactive items
);
// Task menu
$browser->with('#taskmenu', function($browser) {
$browser->assertVisible('a.compose:not(.disabled):not(.selected)');
$browser->assertVisible('a.mail.selected');
$browser->assertVisible('a.contacts:not(.disabled):not(.selected)');
$browser->assertVisible('a.settings:not(.disabled):not(.selected)');
$browser->assertVisible('a.about:not(.disabled):not(.selected)');
$browser->assertVisible('a.logout:not(.disabled):not(.selected)');
});
$this->assertTaskMenu('mail');
});
}
}

@ -9,7 +9,7 @@ class About extends \Tests\Browser\DuskTestCase
$this->browse(function ($browser) {
$this->go('settings');
$browser->click('#taskmenu a.about');
$this->clickTaskMenuItem('about');
$browser->assertSeeIn('.ui-dialog-title', 'About');
$browser->assertVisible('.ui-dialog #aboutframe');

@ -19,15 +19,15 @@ class Folders extends \Tests\Browser\DuskTestCase
$this->assertContains('quotadisplay', $objects);
$this->assertContains('subscriptionlist', $objects);
$browser->assertVisible('#settings-menu li.folders.selected');
if ($this->isDesktop()) {
$browser->assertVisible('#settings-menu li.folders.selected');
}
// Folders list
$browser->assertVisible('#subscription-table li.mailbox.inbox');
// Toolbar menu
$browser->assertVisible('#toolbar-menu a.create:not(.disabled)');
$browser->assertVisible('#toolbar-menu a.delete.disabled');
$browser->assertVisible('#toolbar-menu a.purge.disabled');
$this->assertToolbarMenu(['create'], ['delete', 'purge']);
});
}
}

@ -18,15 +18,16 @@ class Identities extends \Tests\Browser\DuskTestCase
// these objects should be there always
$this->assertContains('identitieslist', $objects);
$browser->assertVisible('#settings-menu li.identities.selected');
if ($this->isDesktop()) {
$browser->assertVisible('#settings-menu li.identities.selected');
}
// Identities list
$browser->assertVisible('#identities-table tr:first-child.focused');
$browser->assertSeeIn('#identities-table tr:first-child td.mail', TESTS_USER);
// Toolbar menu
$browser->assertVisible('#toolbar-menu a.create:not(.disabled)');
$browser->assertVisible('#toolbar-menu a.delete.disabled');
$this->assertToolbarMenu(['create'], ['delete']);
});
}
}

@ -15,6 +15,13 @@ class Preferences extends \Tests\Browser\DuskTestCase
$browser->assertVisible('#settings-menu li.preferences.selected');
// On phone/tablet #sections-table is initially hidden
if ($this->isPhone() || $this->isTablet()) {
$browser->assertMissing('#sections-table');
$browser->click('#settings-menu li.preferences');
$browser->waitFor('#sections-table');
}
// Preferences actions
$browser->with('#sections-table', function($browser) {
$browser->assertSeeIn('tr.general', 'User Interface');

@ -18,12 +18,25 @@ class General extends \Tests\Browser\DuskTestCase
$this->browse(function ($browser) {
$this->go('settings');
$browser->click('#sections-table tr.general');
if ($this->isPhone() || $this->isTablet()) {
$browser->click('#settings-menu li.preferences');
$browser->waitFor('#sections-table');
}
$browser->assertVisible('#sections-table tr.general.focused');
$browser->click('#sections-table tr.general');
if ($this->isPhone()) {
$browser->waitFor('#layout-content .footer a.button.submit:not(.disabled)');
$browser->assertVisible('#layout-content .footer a.button.prev.disabled');
$browser->assertVisible('#layout-content .footer a.button.next:not(.disabled)');
}
$browser->withinFrame('#preferences-frame', function ($browser) {
$browser->waitFor('.formbuttons button.submit');
if (!$this->isPhone()) {
$browser->waitFor('.formbuttons button.submit');
}
// check task and action
$this->assertEnvEquals('task', 'settings');
@ -112,9 +125,15 @@ class General extends \Tests\Browser\DuskTestCase
$this->setCheckboxState('_standard_windows', $this->settings['standard_windows']);
// Submit form
$browser->click('.formbuttons button.submit');
if (!$this->isPhone()) {
$browser->click('.formbuttons button.submit');
}
});
if ($this->isPhone()) {
$browser->click('#layout-content .footer a.submit');
}
$this->waitForMessage('confirmation', 'Successfully saved');
// Verify if every option has been updated

@ -18,15 +18,16 @@ class Responses extends \Tests\Browser\DuskTestCase
// these objects should be there always
$this->assertContains('responseslist', $objects);
$browser->assertVisible('#settings-menu li.responses.selected');
if ($this->isDesktop()) {
$browser->assertVisible('#settings-menu li.responses.selected');
}
// Responses list
$browser->assertPresent('#responses-table');
$browser->assertMissing('#responses-table tr');
// Toolbar menu
$browser->assertVisible('#toolbar-menu a.create:not(.disabled)');
$browser->assertVisible('#toolbar-menu a.delete.disabled');
$this->assertToolbarMenu(['create'], ['delete']);
});
}
}

@ -23,14 +23,7 @@ class Settings extends \Tests\Browser\DuskTestCase
});
// Task menu
$browser->with('#taskmenu', function($browser) {
$browser->assertVisible('a.compose:not(.disabled):not(.selected)');
$browser->assertVisible('a.mail:not(.disabled):not(.selected)');
$browser->assertVisible('a.contacts:not(.disabled):not(.selected)');
$browser->assertVisible('a.settings:not(.disabled).selected');
$browser->assertVisible('a.about:not(.disabled):not(.selected)');
$browser->assertVisible('a.logout:not(.disabled):not(.selected)');
});
$this->assertTaskMenu('settings');
});
}
}

Loading…
Cancel
Save