From 140d2e98dd84923f96e4b338fb1d35d67642d392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ja=CC=81n=20Mikla=CC=81s=CC=8C?= Date: Mon, 17 Dec 2018 18:52:50 +0100 Subject: [PATCH] Refactor acceptance tests with unified waiting for select2 to load --- tests/_support/AcceptanceTester.php | 1 + tests/acceptance/EditExistingNewsletterCest.php | 1 - tests/acceptance/ExportSubscribersCest.php | 5 +---- tests/acceptance/NewsletterCreationCest.php | 1 - tests/acceptance/ReceiveStandardEmailCest.php | 5 +---- tests/acceptance/SaveNewsletterAsDraftCest.php | 1 - tests/acceptance/SaveNotificationAsDraftCest.php | 1 - tests/acceptance/ScheduleNewsletterCest.php | 5 +---- tests/acceptance/SubscriberManageImportExportCest.php | 8 ++------ tests/acceptance/SubscriberManagementCest.php | 2 -- 10 files changed, 6 insertions(+), 24 deletions(-) diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index 423e0956f9..583ae42d92 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -90,6 +90,7 @@ class AcceptanceTester extends \Codeception\Actor { */ public function selectOptionInSelect2($value, $element = 'input.select2-search__field') { $I = $this; + $I->waitForElement($element); $I->fillField($element, $value); $I->pressKey($element, \WebDriverKeys::ENTER); } diff --git a/tests/acceptance/EditExistingNewsletterCest.php b/tests/acceptance/EditExistingNewsletterCest.php index 5b5e366439..0787d63036 100644 --- a/tests/acceptance/EditExistingNewsletterCest.php +++ b/tests/acceptance/EditExistingNewsletterCest.php @@ -35,7 +35,6 @@ class EditExistingNewsletterCest { $send_form_element = '[data-automation-id="newsletter_send_form"]'; $I->waitForElement($send_form_element); $I->seeInCurrentUrl('mailpoet-newsletters#/send/'); - $I->waitForElement('.select2'); $I->selectOptionInSelect2('WordPress Users'); $I->click('Save as draft and close'); $I->waitForText('Standard newsletter', 5, '[data-automation-id="listing_item_1"]'); diff --git a/tests/acceptance/ExportSubscribersCest.php b/tests/acceptance/ExportSubscribersCest.php index 03b3878dc5..3f1612c836 100644 --- a/tests/acceptance/ExportSubscribersCest.php +++ b/tests/acceptance/ExportSubscribersCest.php @@ -9,9 +9,6 @@ require_once __DIR__ . '/../DataFactories/Segment.php'; require_once __DIR__ . '/../DataFactories/Subscriber.php'; class ExportSubscribersCest { - function __construct() { - $this->search_field_element = 'input.select2-search__field'; - } function exportSubscribers(\AcceptanceTester $I) { $segment_factory = new Segment(); $segment_name = 'Hobbyists'; @@ -32,4 +29,4 @@ class ExportSubscribersCest { $I->waitForText('3 subscribers were exported. Get the exported file here.', 20); $I->seeNoJSErrors(); } -} \ No newline at end of file +} diff --git a/tests/acceptance/NewsletterCreationCest.php b/tests/acceptance/NewsletterCreationCest.php index 890974e827..1f389b788e 100644 --- a/tests/acceptance/NewsletterCreationCest.php +++ b/tests/acceptance/NewsletterCreationCest.php @@ -81,7 +81,6 @@ class NewsletterCreationCest { $send_form_element = '[data-automation-id="newsletter_send_form"]'; $I->waitForElement($send_form_element); $I->seeInCurrentUrl('mailpoet-newsletters#/send/'); - $I->waitForElement('.select2'); $I->selectOptionInSelect2('WordPress Users'); $I->click('Send'); } diff --git a/tests/acceptance/ReceiveStandardEmailCest.php b/tests/acceptance/ReceiveStandardEmailCest.php index 9707e27a32..d73d8898b9 100644 --- a/tests/acceptance/ReceiveStandardEmailCest.php +++ b/tests/acceptance/ReceiveStandardEmailCest.php @@ -8,7 +8,6 @@ class ReceiveStandardEmailCest { function receiveStandardEmail(\AcceptanceTester $I) { $newsletter_title = 'Receive Test'; - $search_field_element = 'input.select2-search__field'; $standard_template = '[data-automation-id=\'select_template_0\']'; $title_element = '[data-automation-id=\'newsletter_title\']'; $send_form_element = '[data-automation-id="newsletter_send_form"]'; @@ -33,9 +32,7 @@ class ReceiveStandardEmailCest { //Choose list and send $I->waitForElement($send_form_element, 30); $I->seeInCurrentUrl('mailpoet-newsletters#/send/'); - $I->waitForElement($search_field_element, 30); - $I->fillField($search_field_element, 'WordPress Users'); - $I->pressKey($search_field_element, \WebDriverKeys::ENTER); + $I->selectOptionInSelect2('WordPress Users'); $I->click('Send'); $I->waitForElement('.mailpoet_progress_label', 90); //confirm newsletter is received diff --git a/tests/acceptance/SaveNewsletterAsDraftCest.php b/tests/acceptance/SaveNewsletterAsDraftCest.php index fb2c59f981..ec90acba08 100644 --- a/tests/acceptance/SaveNewsletterAsDraftCest.php +++ b/tests/acceptance/SaveNewsletterAsDraftCest.php @@ -34,7 +34,6 @@ class SaveNewsletterAsDraftCest { $send_form_element = '[data-automation-id="newsletter_send_form"]'; $I->waitForElement($send_form_element); $I->seeInCurrentUrl('mailpoet-newsletters#/send/'); - $I->waitForElement('.select2'); $I->selectOptionInSelect2('WordPress Users'); $I->click('Save as draft and close'); diff --git a/tests/acceptance/SaveNotificationAsDraftCest.php b/tests/acceptance/SaveNotificationAsDraftCest.php index 7a179a8218..a83a8ec1c7 100644 --- a/tests/acceptance/SaveNotificationAsDraftCest.php +++ b/tests/acceptance/SaveNotificationAsDraftCest.php @@ -24,7 +24,6 @@ class SaveNotificationAsDraftCest { $send_form_element = '[data-automation-id="newsletter_send_form"]'; $I->waitForElement($send_form_element); $I->seeInCurrentUrl('mailpoet-newsletters#/send/'); - $I->waitForElement('.select2'); $I->selectOptionInSelect2('WordPress Users'); $I->click('Save as draft and close'); $I->waitForElement('[data-automation-id="newsletters_listing_tabs"]', 10); diff --git a/tests/acceptance/ScheduleNewsletterCest.php b/tests/acceptance/ScheduleNewsletterCest.php index 37949562e4..06eb806053 100644 --- a/tests/acceptance/ScheduleNewsletterCest.php +++ b/tests/acceptance/ScheduleNewsletterCest.php @@ -24,10 +24,7 @@ class ScheduleNewsletterCest { // step 4 - Choose list and schedule $I->waitForElement('[data-automation-id="newsletter_send_form"]'); $I->seeInCurrentUrl('mailpoet-newsletters#/send/'); - $search_field_element = 'input.select2-search__field'; - $I->waitForElement('.select2'); - $I->fillField($search_field_element, 'WordPress Users'); - $I->pressKey($search_field_element, \WebDriverKeys::ENTER); + $I->selectOptionInSelect2('WordPress Users'); $I->checkOption('isScheduled'); $I->click('select[name=time]'); $I->selectOption('form select[name=time]', '6:00'); diff --git a/tests/acceptance/SubscriberManageImportExportCest.php b/tests/acceptance/SubscriberManageImportExportCest.php index 6cabf9ba09..30468cc0f3 100644 --- a/tests/acceptance/SubscriberManageImportExportCest.php +++ b/tests/acceptance/SubscriberManageImportExportCest.php @@ -5,10 +5,6 @@ namespace MailPoet\Test\Acceptance; require_once __DIR__ . '/../_data/MailPoetImportList.csv'; class SubscriberManageImportExportCest { - function __construct() { - $this->search_field_element = 'input.select2-search__field'; - } - function importUsersToSubscribersViaCSV(\AcceptanceTester $I) { $I->wantTo('Import a subscriber list from CSV'); $I->login(); @@ -21,7 +17,7 @@ class SubscriberManageImportExportCest { $I->attachFile(['css'=>'#file_local'], 'MailPoetImportList.csv'); $I->click(['xpath'=>'//*[@id="method_file"]/div/table/tbody/tr[2]/th/a']); //click is to trigger dropdown to display selections - $I->click($this->search_field_element); + $I->click('input.select2-search__field'); //choose My First List $I->click(['xpath'=>'//*[@id="select2-mailpoet_segments_select-results"]/li[2]']); //click next step @@ -50,4 +46,4 @@ class SubscriberManageImportExportCest { $I->waitForText('iii@example.com', 10); $I->seeNoJSErrors(); } -} \ No newline at end of file +} diff --git a/tests/acceptance/SubscriberManagementCest.php b/tests/acceptance/SubscriberManagementCest.php index e60b7ceea6..12231a9adc 100644 --- a/tests/acceptance/SubscriberManagementCest.php +++ b/tests/acceptance/SubscriberManagementCest.php @@ -96,7 +96,6 @@ class SubscriberManagementCest { $I->waitForText('Subscriber', 30); $I->seeInCurrentUrl('mailpoet-subscribers#/edit/'); $I->waitForElementNotVisible('.mailpoet_form_loading'); - $I->waitForElement('.select2'); $I->selectOptionInSelect2('Cooking'); $I->click('[data-automation-id="subscriber_edit_form"] input[type="submit"]'); $I->seeNoJSErrors(); @@ -113,7 +112,6 @@ class SubscriberManagementCest { $I->waitForText('Subscriber', 10); $I->seeInCurrentUrl('mailpoet-subscribers#/edit/'); $I->waitForElementNotVisible('.mailpoet_form_loading'); - $I->waitForElement('.select2'); $I->selectOptionInSelect2('Cooking'); $I->click('.select2-selection__choice__remove'); $I->click('[data-automation-id="subscriber_edit_form"] input[type="submit"]');