From ff99cb21334b15faab77c8c6598eefc56de10b33 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 4 Jul 2018 08:20:33 +0100 Subject: [PATCH] Revert "Issue #2942900 by Mixologic, vaplas, jibran, Lendude, martin107, alexpott, dawehner, tedbow, tacituseu, tstoeckler, heddn: Convert JavascriptTestBase Tests to use DrupalSelenium2Driver" This reverts commit f55d974612094a9f3e5a6dd25d95575ca752de19. --- core/drupalci.yml | 2 +- .../ActionFormAjaxTest.php | 12 +- .../BigPipeRegressionTest.php | 4 +- .../FunctionalJavascript/BlockFilterTest.php | 4 +- .../BookJavascriptTest.php | 4 +- .../src/FunctionalJavascript/AjaxCssTest.php | 4 +- .../CKEditorIntegrationTest.php | 9 +- .../FunctionalJavascript/ConfigEntityTest.php | 4 +- .../ConfigTranslationUiTest.php | 4 +- .../ContentTranslationContextualLinksTest.php | 4 +- .../ContextualLinksTest.php | 4 +- .../src/FunctionalJavascript/EditModeTest.php | 4 +- .../FormJSAddMoreTest.php | 4 +- .../FunctionalJavascript/FieldLayoutTest.php | 10 +- .../EntityDisplayTest.php | 13 +- .../FileFieldValidateTest.php | 4 +- .../MaximumFileSizeExceededUploadTest.php | 4 +- .../ImageFieldTestBase.php | 10 +- .../FormErrorHandlerCKEditorTest.php | 9 +- .../FormErrorHandlerQuickEditTest.php | 4 +- .../FunctionalJavascript/FieldBlockTest.php | 4 +- .../FunctionalJavascript/MediaDisplayTest.php | 1 - .../MediaJavascriptTestBase.php | 4 +- .../FunctionalJavascript/MediaLibraryTest.php | 4 +- .../MenuUiJavascriptTest.php | 6 +- .../NodePreviewLinkTest.php | 4 +- .../TestSettingSummariesContentType.php | 6 +- .../src/FunctionalJavascript/FieldTest.php | 4 +- .../QuickEditJavascriptTestBase.php | 12 +- .../FunctionalJavascript/ConfigAccessTest.php | 1 - .../QuickEditIntegrationTest.php | 2 - .../SettingsTrayBlockFormTest.php | 10 +- .../SettingsTrayTestBase.php | 19 +- .../BrowserWithJavascriptTest.php | 4 +- .../JavascriptGetDrupalSettingsTest.php | 6 +- .../StatisticsLoggingTest.php | 4 +- .../ModalRendererTest.php | 4 +- .../FunctionalJavascript/OffCanvasTest.php | 5 +- .../OffCanvasTestBase.php | 23 +- .../ThemeFormSettingsTest.php | 4 +- .../TextareaWithSummaryTest.php | 4 +- .../ToolbarIntegrationTest.php | 9 +- .../ClickSortingAJAXTest.php | 4 +- .../ExposedFilterAJAXTest.php | 4 +- .../FunctionalJavascript/GlossaryViewTest.php | 4 +- .../PaginationAJAXTest.php | 4 +- .../views/Handler/ContextualFilterTest.php | 4 +- .../Plugin/views/Handler/FieldTest.php | 4 +- .../Handler/GroupedExposedFilterTest.php | 4 +- .../src/FunctionalJavascript/DisplayTest.php | 4 +- .../FilterCriteriaTest.php | 4 +- .../FilterOptionsTest.php | 4 +- .../LibraryCachingTest.php | 4 +- .../FunctionalJavascript/ViewsListingTest.php | 4 +- .../FunctionalJavascript/ViewsWizardTest.php | 4 +- .../StandardJavascriptTest.php | 4 +- .../Ajax/AjaxCallbacksTest.php | 24 ++- .../Ajax/AjaxFormImageButtonTest.php | 4 +- .../Ajax/AjaxFormPageCacheTest.php | 10 +- .../Ajax/AjaxTest.php | 4 +- .../Ajax/BackwardCompatibilityTest.php | 4 +- .../Ajax/ThrobberTest.php | 10 +- .../Core/Form/FormGroupingElementsTest.php | 4 +- .../Installer/Form/SelectProfileFormTest.php | 4 +- .../Core/MachineNameTest.php | 4 +- .../Core/Session/SessionTest.php | 4 +- .../Dialog/DialogPositionTest.php | 4 +- .../DrupalSelenium2Driver.php | 9 - .../EntityReferenceAutocompleteWidgetTest.php | 8 +- .../JavascriptTestBase.php | 191 ++++++++++++++++- .../LegacyJavascriptTestBase.php | 20 +- .../Tests/JSWebAssertTest.php | 4 +- .../WebDriverCurlService.php | 110 ---------- .../WebDriverTestBase.php | 202 ------------------ 74 files changed, 380 insertions(+), 553 deletions(-) delete mode 100644 core/tests/Drupal/FunctionalJavascriptTests/WebDriverCurlService.php delete mode 100644 core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php diff --git a/core/drupalci.yml b/core/drupalci.yml index b539d562af3..b658e475b89 100644 --- a/core/drupalci.yml +++ b/core/drupalci.yml @@ -47,7 +47,7 @@ build: # Functional JavaScript tests require a concurrency of 1 because there is # only one instance of PhantomJS on the testbot machine. run_tests.javascript: - concurrency: 15 + concurrency: 1 types: 'PHPUnit-FunctionalJavascript' testgroups: '--all' suppress-deprecations: false diff --git a/core/modules/action/tests/src/FunctionalJavascript/ActionFormAjaxTest.php b/core/modules/action/tests/src/FunctionalJavascript/ActionFormAjaxTest.php index f4c85fc755d..bc314a573d5 100644 --- a/core/modules/action/tests/src/FunctionalJavascript/ActionFormAjaxTest.php +++ b/core/modules/action/tests/src/FunctionalJavascript/ActionFormAjaxTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\action\FunctionalJavascript; use Drupal\Core\Url; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\system\Entity\Action; /** @@ -11,7 +11,7 @@ use Drupal\system\Entity\Action; * * @group action */ -class ActionFormAjaxTest extends WebDriverTestBase { +class ActionFormAjaxTest extends JavascriptTestBase { /** * {@inheritdoc} @@ -33,15 +33,16 @@ class ActionFormAjaxTest extends WebDriverTestBase { public function testActionConfigurationWithAjax() { $url = Url::fromRoute('action.admin_add', ['action_id' => 'action_form_ajax_test']); $this->drupalGet($url); + $this->assertSession()->statusCodeEquals(200); $page = $this->getSession()->getPage(); $id = 'test_plugin'; - $this->assertSession()->waitForElementVisible('named', ['button', 'Edit'])->press(); - $this->assertSession()->waitForElementVisible('css', '[name="id"]')->setValue($id); + $page->find('css', '[name="id"]') + ->setValue($id); $page->find('css', '[name="having_a_party"]') ->check(); - $this->assertSession()->waitForElementVisible('css', '[name="party_time"]'); + $this->assertSession()->waitForElement('css', '[name="party_time"]'); $party_time = 'Evening'; $page->find('css', '[name="party_time"]') @@ -53,6 +54,7 @@ class ActionFormAjaxTest extends WebDriverTestBase { $url = Url::fromRoute('entity.action.collection'); $this->assertSession()->pageTextContains('The action has been successfully saved.'); $this->assertSession()->addressEquals($url); + $this->assertSession()->statusCodeEquals(200); // Check storage. $instance = Action::load($id); diff --git a/core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php b/core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php index f4cd5108bf8..b4da7b0a9be 100644 --- a/core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php +++ b/core/modules/big_pipe/tests/src/FunctionalJavascript/BigPipeRegressionTest.php @@ -11,7 +11,7 @@ use Drupal\comment\Tests\CommentTestTrait; use Drupal\Core\Url; use Drupal\editor\Entity\Editor; use Drupal\filter\Entity\FilterFormat; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\simpletest\ContentTypeCreationTrait; use Drupal\simpletest\NodeCreationTrait; @@ -20,7 +20,7 @@ use Drupal\simpletest\NodeCreationTrait; * * @group big_pipe */ -class BigPipeRegressionTest extends WebDriverTestBase { +class BigPipeRegressionTest extends JavascriptTestBase { use CommentTestTrait; use ContentTypeCreationTrait; diff --git a/core/modules/block/tests/src/FunctionalJavascript/BlockFilterTest.php b/core/modules/block/tests/src/FunctionalJavascript/BlockFilterTest.php index e9ecc065260..b64f7c1ba2e 100644 --- a/core/modules/block/tests/src/FunctionalJavascript/BlockFilterTest.php +++ b/core/modules/block/tests/src/FunctionalJavascript/BlockFilterTest.php @@ -3,14 +3,14 @@ namespace Drupal\Tests\block\FunctionalJavascript; use Behat\Mink\Element\NodeElement; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the JavaScript functionality of the block add filter. * * @group block */ -class BlockFilterTest extends WebDriverTestBase { +class BlockFilterTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php b/core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php index dc9b8125ccc..d8d406b4408 100644 --- a/core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php +++ b/core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php @@ -4,7 +4,7 @@ namespace Drupal\Tests\book\FunctionalJavascript; use Behat\Mink\Exception\ExpectationException; use Drupal\Component\Render\FormattableMarkup; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\node\Entity\Node; /** @@ -12,7 +12,7 @@ use Drupal\node\Entity\Node; * * @group book */ -class BookJavascriptTest extends WebDriverTestBase { +class BookJavascriptTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/ckeditor/tests/src/FunctionalJavascript/AjaxCssTest.php b/core/modules/ckeditor/tests/src/FunctionalJavascript/AjaxCssTest.php index ddb53d8303e..b15433d4f75 100644 --- a/core/modules/ckeditor/tests/src/FunctionalJavascript/AjaxCssTest.php +++ b/core/modules/ckeditor/tests/src/FunctionalJavascript/AjaxCssTest.php @@ -4,14 +4,14 @@ namespace Drupal\Tests\ckeditor\FunctionalJavascript; use Drupal\editor\Entity\Editor; use Drupal\filter\Entity\FilterFormat; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests delivery of CSS to CKEditor via AJAX. * * @group ckeditor */ -class AjaxCssTest extends WebDriverTestBase { +class AjaxCssTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php b/core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php index a9ee69719b5..80de46d6bc4 100644 --- a/core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php +++ b/core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php @@ -7,7 +7,7 @@ use Drupal\editor\Entity\Editor; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\filter\Entity\FilterFormat; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\node\Entity\NodeType; /** @@ -15,7 +15,7 @@ use Drupal\node\Entity\NodeType; * * @group ckeditor */ -class CKEditorIntegrationTest extends WebDriverTestBase { +class CKEditorIntegrationTest extends JavascriptTestBase { /** * The account. @@ -92,10 +92,9 @@ class CKEditorIntegrationTest extends WebDriverTestBase { $session->getPage(); // Add a bottom margin to the title field to be sure the body field is not - // visible. - $session->executeScript("document.getElementById('edit-title-0-value').style.marginBottom = window.innerHeight*2 +'px';"); + // visible. PhantomJS runs with a resolution of 1024x768px. + $session->executeScript("document.getElementById('edit-title-0-value').style.marginBottom = '800px';"); - $this->assertSession()->waitForElementVisible('css', $ckeditor_id); // Check that the CKEditor-enabled body field is currently not visible in // the viewport. $web_assert->assertNotVisibleInViewport('css', $ckeditor_id, 'topLeft', 'CKEditor-enabled body field is visible.'); diff --git a/core/modules/config/tests/src/FunctionalJavascript/ConfigEntityTest.php b/core/modules/config/tests/src/FunctionalJavascript/ConfigEntityTest.php index f7e6dc8ff52..110c9f894ea 100644 --- a/core/modules/config/tests/src/FunctionalJavascript/ConfigEntityTest.php +++ b/core/modules/config/tests/src/FunctionalJavascript/ConfigEntityTest.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\config\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the Config operations through the UI. * * @group config */ -class ConfigEntityTest extends WebDriverTestBase { +class ConfigEntityTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/config_translation/tests/src/FunctionalJavascript/ConfigTranslationUiTest.php b/core/modules/config_translation/tests/src/FunctionalJavascript/ConfigTranslationUiTest.php index 585d2d1d38d..13e1b545c2b 100644 --- a/core/modules/config_translation/tests/src/FunctionalJavascript/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/tests/src/FunctionalJavascript/ConfigTranslationUiTest.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\config_translation\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Translate settings and entities to various languages. * * @group config_translation */ -class ConfigTranslationUiTest extends WebDriverTestBase { +class ConfigTranslationUiTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/content_translation/tests/src/FunctionalJavascript/ContentTranslationContextualLinksTest.php b/core/modules/content_translation/tests/src/FunctionalJavascript/ContentTranslationContextualLinksTest.php index 156b10d97ff..b0953991954 100644 --- a/core/modules/content_translation/tests/src/FunctionalJavascript/ContentTranslationContextualLinksTest.php +++ b/core/modules/content_translation/tests/src/FunctionalJavascript/ContentTranslationContextualLinksTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\content_translation\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\language\Entity\ConfigurableLanguage; /** @@ -10,7 +10,7 @@ use Drupal\language\Entity\ConfigurableLanguage; * * @group content_translation */ -class ContentTranslationContextualLinksTest extends WebDriverTestBase { +class ContentTranslationContextualLinksTest extends JavascriptTestBase { /** * The 'translator' user to use during testing. diff --git a/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php b/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php index 7435dada23f..de836924119 100644 --- a/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php +++ b/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\contextual\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\user\Entity\Role; /** @@ -10,7 +10,7 @@ use Drupal\user\Entity\Role; * * @group contextual */ -class ContextualLinksTest extends WebDriverTestBase { +class ContextualLinksTest extends JavascriptTestBase { use ContextualLinkClickTrait; diff --git a/core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php b/core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php index 4a00a7efc49..a61ea8a3d78 100644 --- a/core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php +++ b/core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\contextual\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests edit mode. * * @group contextual */ -class EditModeTest extends WebDriverTestBase { +class EditModeTest extends JavascriptTestBase { /** * CSS selector for Drupal's announce element. diff --git a/core/modules/field/tests/src/FunctionalJavascript/FormJSAddMoreTest.php b/core/modules/field/tests/src/FunctionalJavascript/FormJSAddMoreTest.php index 0561d737119..64ee24d4694 100644 --- a/core/modules/field/tests/src/FunctionalJavascript/FormJSAddMoreTest.php +++ b/core/modules/field/tests/src/FunctionalJavascript/FormJSAddMoreTest.php @@ -6,14 +6,14 @@ use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests add more behavior for a multiple value field. * * @group field */ -class FormJSAddMoreTest extends WebDriverTestBase { +class FormJSAddMoreTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php b/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php index 9e65b270be7..162d22329c4 100644 --- a/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php +++ b/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php @@ -3,14 +3,14 @@ namespace Drupal\Tests\field_layout\FunctionalJavascript; use Drupal\entity_test\Entity\EntityTest; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests using field layout for entity displays. * * @group field_layout */ -class FieldLayoutTest extends WebDriverTestBase { +class FieldLayoutTest extends JavascriptTestBase { /** * {@inheritdoc} @@ -100,15 +100,12 @@ class FieldLayoutTest extends WebDriverTestBase { // After a refresh the new regions are still there. $this->drupalGet('entity_test/structure/entity_test/form-display'); $this->assertEquals(['Top', 'First', 'Second', 'Bottom', 'Disabled'], $this->getRegionTitles()); - $this->assertSession()->waitForElement('css', '.tabledrag-handle'); - $id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue(); // Drag the field to the second region. $field_test_text_row = $this->getSession()->getPage()->find('css', '#field-test-text'); $second_region_row = $this->getSession()->getPage()->find('css', '.region-second-message'); $field_test_text_row->find('css', '.handle')->dragTo($second_region_row); $this->assertSession()->assertWaitOnAjaxRequest(); - $this->assertSession()->waitForElement('css', "[name='form_build_id']:not([value='$id'])"); $this->submitForm([], 'Save'); $this->assertSession()->pageTextContains('Your settings have been saved.'); @@ -161,8 +158,6 @@ class FieldLayoutTest extends WebDriverTestBase { // After a refresh the new regions are still there. $this->drupalGet('entity_test/structure/entity_test/display'); $this->assertEquals(['Top', 'First', 'Second', 'Bottom', 'Disabled'], $this->getRegionTitles()); - $this->assertSession()->waitForElement('css', '.tabledrag-handle'); - $id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue(); // Drag the field to the first region. $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected()); @@ -171,7 +166,6 @@ class FieldLayoutTest extends WebDriverTestBase { $field_test_text_row->find('css', '.handle')->dragTo($first_region_row); $this->assertSession()->assertWaitOnAjaxRequest(); $this->assertFalse($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected()); - $this->assertSession()->waitForElement('css', "[name='form_build_id']:not([value='$id'])"); $this->submitForm([], 'Save'); $this->assertSession()->pageTextContains('Your settings have been saved.'); diff --git a/core/modules/field_ui/tests/src/FunctionalJavascript/EntityDisplayTest.php b/core/modules/field_ui/tests/src/FunctionalJavascript/EntityDisplayTest.php index 7909f0f0061..ae2c56c954b 100644 --- a/core/modules/field_ui/tests/src/FunctionalJavascript/EntityDisplayTest.php +++ b/core/modules/field_ui/tests/src/FunctionalJavascript/EntityDisplayTest.php @@ -3,14 +3,14 @@ namespace Drupal\Tests\field_ui\FunctionalJavascript; use Drupal\entity_test\Entity\EntityTest; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the UI for entity displays. * * @group field_ui */ -class EntityDisplayTest extends WebDriverTestBase { +class EntityDisplayTest extends JavascriptTestBase { /** * {@inheritdoc} @@ -50,8 +50,7 @@ class EntityDisplayTest extends WebDriverTestBase { $this->drupalGet('entity_test/structure/entity_test/form-display'); $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected()); - $this->getSession()->getPage()->pressButton('Show row weights'); - $this->assertSession()->waitForElementVisible('css', '[name="fields[field_test_text][region]"]'); + $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'hidden'); $this->assertSession()->assertWaitOnAjaxRequest(); $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected()); @@ -73,8 +72,6 @@ class EntityDisplayTest extends WebDriverTestBase { $this->drupalGet('entity_test/structure/entity_test/display'); $this->assertSession()->elementExists('css', '.region-content-message.region-empty'); - $this->getSession()->getPage()->pressButton('Show row weights'); - $this->assertSession()->waitForElementVisible('css', '[name="fields[field_test_text][region]"]'); $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected()); $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'content'); @@ -95,16 +92,12 @@ class EntityDisplayTest extends WebDriverTestBase { public function testExtraFields() { entity_test_create_bundle('bundle_with_extra_fields'); $this->drupalGet('entity_test/structure/bundle_with_extra_fields/display'); - $this->assertSession()->waitForElement('css', '.tabledrag-handle'); - $id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue(); $extra_field_row = $this->getSession()->getPage()->find('css', '#display-extra-field'); $disabled_region_row = $this->getSession()->getPage()->find('css', '.region-hidden-title'); $extra_field_row->find('css', '.handle')->dragTo($disabled_region_row); $this->assertSession()->assertWaitOnAjaxRequest(); - $this->assertSession() - ->waitForElement('css', "[name='form_build_id']:not([value='$id'])"); $this->submitForm([], 'Save'); $this->assertSession()->pageTextContains('Your settings have been saved.'); diff --git a/core/modules/file/tests/src/FunctionalJavascript/FileFieldValidateTest.php b/core/modules/file/tests/src/FunctionalJavascript/FileFieldValidateTest.php index 99acc3712a0..2e4cb697595 100644 --- a/core/modules/file/tests/src/FunctionalJavascript/FileFieldValidateTest.php +++ b/core/modules/file/tests/src/FunctionalJavascript/FileFieldValidateTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\file\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\Tests\file\Functional\FileFieldCreationTrait; use Drupal\Tests\TestFileCreationTrait; @@ -12,7 +12,7 @@ use Drupal\Tests\TestFileCreationTrait; * * @group file */ -class FileFieldValidateTest extends WebDriverTestBase { +class FileFieldValidateTest extends JavascriptTestBase { use FileFieldCreationTrait; use TestFileCreationTrait; diff --git a/core/modules/file/tests/src/FunctionalJavascript/MaximumFileSizeExceededUploadTest.php b/core/modules/file/tests/src/FunctionalJavascript/MaximumFileSizeExceededUploadTest.php index 45c8bf5eec0..7ccd2b21873 100644 --- a/core/modules/file/tests/src/FunctionalJavascript/MaximumFileSizeExceededUploadTest.php +++ b/core/modules/file/tests/src/FunctionalJavascript/MaximumFileSizeExceededUploadTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\file\FunctionalJavascript; use Drupal\Component\Utility\Bytes; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\Tests\TestFileCreationTrait; use Drupal\Tests\file\Functional\FileFieldCreationTrait; @@ -12,7 +12,7 @@ use Drupal\Tests\file\Functional\FileFieldCreationTrait; * * @group file */ -class MaximumFileSizeExceededUploadTest extends WebDriverTestBase { +class MaximumFileSizeExceededUploadTest extends JavascriptTestBase { use FileFieldCreationTrait; use TestFileCreationTrait; diff --git a/core/modules/image/tests/src/FunctionalJavascript/ImageFieldTestBase.php b/core/modules/image/tests/src/FunctionalJavascript/ImageFieldTestBase.php index 4e21f6aca7a..a4af78b9a3e 100644 --- a/core/modules/image/tests/src/FunctionalJavascript/ImageFieldTestBase.php +++ b/core/modules/image/tests/src/FunctionalJavascript/ImageFieldTestBase.php @@ -2,14 +2,15 @@ namespace Drupal\Tests\image\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\Tests\image\Kernel\ImageFieldCreationTrait; use Drupal\Tests\TestFileCreationTrait; /** * This class provides methods specifically for testing Image's field handling. */ -abstract class ImageFieldTestBase extends WebDriverTestBase { +abstract class ImageFieldTestBase extends JavascriptTestBase { use ImageFieldCreationTrait; use TestFileCreationTrait { @@ -28,6 +29,11 @@ abstract class ImageFieldTestBase extends WebDriverTestBase { 'image_module_test', ]; + /** + * {@inheritdoc} + */ + protected $minkDefaultDriverClass = DrupalSelenium2Driver::class; + /** * An user with permissions to administer content types and image styles. * diff --git a/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerCKEditorTest.php b/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerCKEditorTest.php index 7c9a74ab503..2007e1e2663 100644 --- a/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerCKEditorTest.php +++ b/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerCKEditorTest.php @@ -7,7 +7,7 @@ use Drupal\editor\Entity\Editor; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\filter\Entity\FilterFormat; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\node\Entity\NodeType; /** @@ -15,7 +15,7 @@ use Drupal\node\Entity\NodeType; * * @group ckeditor */ -class FormErrorHandlerCKEditorTest extends WebDriverTestBase { +class FormErrorHandlerCKEditorTest extends JavascriptTestBase { /** * {@inheritdoc} @@ -87,10 +87,9 @@ class FormErrorHandlerCKEditorTest extends WebDriverTestBase { $this->submitForm($edit, 'Save'); - $this->assertSession()->waitForElement('css', '#cke_edit-body-0-value'); // Add a bottom margin to the title field to be sure the body field is not - // visible. - $session->executeScript("document.getElementById('edit-title-0-value').style.marginBottom = window.innerHeight*2 + 'px';"); + // visible. PhantomJS runs with a resolution of 1024x768px. + $session->executeScript("document.getElementById('edit-title-0-value').style.marginBottom = '800px';"); // Check that the CKEditor-enabled body field is currently not visible in // the viewport. diff --git a/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerQuickEditTest.php b/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerQuickEditTest.php index 00dc3d3f622..b956cccbd0b 100644 --- a/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerQuickEditTest.php +++ b/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerQuickEditTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\inline_form_errors\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\node\Entity\NodeType; /** @@ -10,7 +10,7 @@ use Drupal\node\Entity\NodeType; * * @group inline_form_errors */ -class FormErrorHandlerQuickEditTest extends WebDriverTestBase { +class FormErrorHandlerQuickEditTest extends JavascriptTestBase { /** * Modules to enable. diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/FieldBlockTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/FieldBlockTest.php index f2ecd52b3bf..4f086d6a96b 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/FieldBlockTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/FieldBlockTest.php @@ -4,14 +4,14 @@ namespace Drupal\Tests\layout_builder\FunctionalJavascript; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * @coversDefaultClass \Drupal\layout_builder\Plugin\Block\FieldBlock * * @group field */ -class FieldBlockTest extends WebDriverTestBase { +class FieldBlockTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php index 76b1badd0b3..30b62042c82 100644 --- a/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php @@ -55,7 +55,6 @@ class MediaDisplayTest extends MediaJavascriptTestBase { // Enable the field on the display and verify it becomes visible on the UI. $this->drupalGet("/admin/structure/media/manage/{$media_type->id()}/display"); $assert_session->buttonExists('Show row weights')->press(); - $this->assertSession()->waitForElementVisible('css', '[name="fields[name][region]"]'); $page->selectFieldOption('fields[name][region]', 'content'); $assert_session->waitForElementVisible('css', '#edit-fields-name-settings-edit'); $page->pressButton('Save'); diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php b/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php index f8c04d17b6e..e84db38b7dd 100644 --- a/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\media\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\Tests\media\Functional\MediaFunctionalTestTrait; use Drupal\Tests\media\Traits\MediaTypeCreationTrait; /** * Base class for Media functional JavaScript tests. */ -abstract class MediaJavascriptTestBase extends WebDriverTestBase { +abstract class MediaJavascriptTestBase extends JavascriptTestBase { use MediaFunctionalTestTrait; use MediaTypeCreationTrait; diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php index 154a1d23025..f8604e644bf 100644 --- a/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\media_library\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\media\Entity\Media; /** @@ -10,7 +10,7 @@ use Drupal\media\Entity\Media; * * @group media_library */ -class MediaLibraryTest extends WebDriverTestBase { +class MediaLibraryTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php b/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php index 22959326dca..6ce4ccc713d 100644 --- a/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php +++ b/core/modules/menu_ui/tests/src/FunctionalJavascript/MenuUiJavascriptTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\menu_ui\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\system\Entity\Menu; use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait; use Drupal\Tests\menu_ui\Traits\MenuUiTrait; @@ -12,7 +12,7 @@ use Drupal\Tests\menu_ui\Traits\MenuUiTrait; * * @group menu_ui */ -class MenuUiJavascriptTest extends WebDriverTestBase { +class MenuUiJavascriptTest extends JavascriptTestBase { use ContextualLinkClickTrait; use MenuUiTrait; @@ -123,6 +123,7 @@ class MenuUiJavascriptTest extends WebDriverTestBase { protected function addMenuLink($parent = '', $path = '/', $menu_id = 'tools', $expanded = FALSE, $weight = '0') { // View add menu link page. $this->drupalGet("admin/structure/menu/manage/$menu_id/add"); + $this->assertSession()->statusCodeEquals(200); $title = '!link_' . $this->randomMachineName(16); $edit = [ @@ -137,6 +138,7 @@ class MenuUiJavascriptTest extends WebDriverTestBase { // Add menu link. $this->drupalPostForm(NULL, $edit, 'Save'); + $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains('The menu link has been saved.'); $storage = $this->container->get('entity_type.manager')->getStorage('menu_link_content'); diff --git a/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php b/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php index e1c185000f9..8eb7a268d0a 100644 --- a/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php +++ b/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php @@ -3,14 +3,14 @@ namespace Drupal\Tests\node\FunctionalJavascript; use Drupal\filter\Entity\FilterFormat; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the JavaScript prevention of navigation away from node previews. * * @group node */ -class NodePreviewLinkTest extends WebDriverTestBase { +class NodePreviewLinkTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/node/tests/src/FunctionalJavascript/TestSettingSummariesContentType.php b/core/modules/node/tests/src/FunctionalJavascript/TestSettingSummariesContentType.php index aef0c1e27d3..4760ee65091 100644 --- a/core/modules/node/tests/src/FunctionalJavascript/TestSettingSummariesContentType.php +++ b/core/modules/node/tests/src/FunctionalJavascript/TestSettingSummariesContentType.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\node\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the JavaScript updating of summaries on content type form. * * @group node */ -class TestSettingSummariesContentType extends WebDriverTestBase { +class TestSettingSummariesContentType extends JavascriptTestBase { /** * {@inheritdoc} @@ -33,8 +33,6 @@ class TestSettingSummariesContentType extends WebDriverTestBase { public function testWorkflowSummary() { $this->drupalGet('admin/structure/types/manage/test'); $page = $this->getSession()->getPage(); - $page->find('css', 'a[href="#edit-workflow"]')->click(); - $this->assertSession()->waitForElementVisible('css', '[name="options[status]"]'); $page->findField('options[status]')->uncheck(); $page->findField('options[sticky]')->check(); $page->findField('options[promote]')->check(); diff --git a/core/modules/quickedit/tests/src/FunctionalJavascript/FieldTest.php b/core/modules/quickedit/tests/src/FunctionalJavascript/FieldTest.php index 7555220acfb..3e604700dfd 100644 --- a/core/modules/quickedit/tests/src/FunctionalJavascript/FieldTest.php +++ b/core/modules/quickedit/tests/src/FunctionalJavascript/FieldTest.php @@ -4,7 +4,7 @@ namespace Drupal\Tests\quickedit\FunctionalJavascript; use Drupal\editor\Entity\Editor; use Drupal\filter\Entity\FilterFormat; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait; @@ -14,7 +14,7 @@ use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait; * * @group quickedit */ -class FieldTest extends WebDriverTestBase { +class FieldTest extends JavascriptTestBase { use ContextualLinkClickTrait; diff --git a/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditJavascriptTestBase.php b/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditJavascriptTestBase.php index 8c939b3264a..cb40a83ceca 100644 --- a/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditJavascriptTestBase.php +++ b/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditJavascriptTestBase.php @@ -2,13 +2,21 @@ namespace Drupal\Tests\quickedit\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use WebDriver\Key; /** * Base class for testing the QuickEdit. */ -class QuickEditJavascriptTestBase extends WebDriverTestBase { +class QuickEditJavascriptTestBase extends JavascriptTestBase { + + /** + * {@inheritdoc} + * + * @todo: Remove after https://www.drupal.org/project/drupal/issues/2942900 + */ + protected $minkDefaultDriverClass = DrupalSelenium2Driver::class; /** * {@inheritdoc} diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/ConfigAccessTest.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/ConfigAccessTest.php index 6b15be9425e..8646b93ec38 100644 --- a/core/modules/settings_tray/tests/src/FunctionalJavascript/ConfigAccessTest.php +++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/ConfigAccessTest.php @@ -51,7 +51,6 @@ class ConfigAccessTest extends SettingsTrayTestBase { // permission. $web_assert->fieldNotExists('settings[site_information][site_name]'); $page->pressButton('Save Site branding'); - $this->waitForOffCanvasToClose(); $this->assertElementVisibleAfterWait('css', 'div:contains(The block configuration has been saved)'); $web_assert->assertWaitOnAjaxRequest(); // Confirm we did not save changes to the configuration. diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php index 6f623cb1bcf..d30562f71d6 100644 --- a/core/modules/settings_tray/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php +++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php @@ -134,8 +134,6 @@ class QuickEditIntegrationTest extends SettingsTrayTestBase { $this->placeBlock('block_content:' . $block_content->uuid(), ['id' => 'custom']); $this->drupalGet('user'); $page = $this->getSession()->getPage(); - $this->toggleContextualTriggerVisibility('#block-custom'); - $page->find('css', '#block-custom .contextual button')->press(); $links = $page->findAll('css', "#block-custom .contextual-links li a"); $link_labels = []; /** @var \Behat\Mink\Element\NodeElement $link */ diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php index 0e6b9d6251e..106dae43e11 100644 --- a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php +++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php @@ -67,8 +67,8 @@ class SettingsTrayBlockFormTest extends SettingsTrayTestBase { $block_id = $block->id(); $this->drupalGet('user'); - $link = $web_assert->waitForElement('css', "$block_selector .contextual-links li a"); - $this->assertEquals('Quick edit', $link->getHtml(), "'Quick edit' is the first contextual link for the block."); + $link = $page->find('css', "$block_selector .contextual-links li a"); + $this->assertEquals('Quick edit', $link->getText(), "'Quick edit' is the first contextual link for the block."); $this->assertContains("/admin/structure/block/manage/$block_id/settings-tray?destination=user/2", $link->getAttribute('href')); if (isset($toolbar_item)) { @@ -138,11 +138,9 @@ class SettingsTrayBlockFormTest extends SettingsTrayTestBase { $this->getSession()->executeScript('jQuery("body").trigger(jQuery.Event("keyup", { keyCode: 27 }));'); $this->waitForOffCanvasToClose(); $this->getSession()->wait(100); - $this->getSession()->executeScript("jQuery('[data-quickedit-entity-id]').trigger('mouseleave')"); - $this->getSession()->getPage()->find('css', static::TOOLBAR_EDIT_LINK_SELECTOR)->mouseOver(); $this->assertEditModeDisabled(); - $this->assertNotEmpty($web_assert->waitForElement('css', '#drupal-live-announce:contains(Exited edit mode)')); - $this->waitForNoElement('.contextual-toolbar-tab button:contains(Editing)'); + $web_assert->elementTextContains('css', '#drupal-live-announce', 'Exited edit mode.'); + $web_assert->elementTextNotContains('css', '.contextual-toolbar-tab button', 'Editing'); $web_assert->elementAttributeNotContains('css', '.dialog-off-canvas-main-canvas', 'class', 'js-settings-tray-edit-mode'); // Clean up test data so each test does not impact the next. diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayTestBase.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayTestBase.php index 2017accd88a..448fd21836f 100644 --- a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayTestBase.php +++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayTestBase.php @@ -49,9 +49,7 @@ class SettingsTrayTestBase extends OffCanvasTestBase { $this->assertElementVisibleAfterWait('css', '.dialog-off-canvas-main-canvas.js-settings-tray-edit-mode'); // Ensure that all other Ajax activity is completed. $this->assertSession()->assertWaitOnAjaxRequest(); - $block = $this->getSession()->getPage()->find('css', $block_selector); - $block->mouseOver(); - $block->click(); + $this->click($block_selector); $this->waitForOffCanvasToOpen(); $this->assertOffCanvasBlockFormIsValid(); } @@ -81,8 +79,6 @@ class SettingsTrayTestBase extends OffCanvasTestBase { $edit_button = $this->getSession() ->getPage() ->find('css', static::TOOLBAR_EDIT_LINK_SELECTOR); - $this->getSession()->executeScript("jQuery('[data-quickedit-entity-id]').trigger('mouseleave')"); - $edit_button->mouseOver(); $edit_button->press(); } @@ -91,12 +87,6 @@ class SettingsTrayTestBase extends OffCanvasTestBase { */ protected function assertEditModeDisabled() { $web_assert = $this->assertSession(); - $page = $this->getSession()->getPage(); - $this->getSession()->executeScript("jQuery('[data-quickedit-entity-id]').trigger('mouseleave')"); - $page->find('css', static::TOOLBAR_EDIT_LINK_SELECTOR)->mouseOver(); - $this->assertTrue($page->waitFor(10, function ($page) { - return !$page->find('css', '.contextual .trigger:not(.visually-hidden)'); - })); // Contextual triggers should be hidden. $web_assert->elementExists('css', '.contextual .trigger.visually-hidden'); // No contextual triggers should be not hidden. @@ -113,13 +103,6 @@ class SettingsTrayTestBase extends OffCanvasTestBase { */ protected function assertEditModeEnabled() { $web_assert = $this->assertSession(); - $page = $this->getSession()->getPage(); - // Move the mouse over the toolbar button so that isn't over a contextual - // links area which cause the contextual link to be shown. - $page->find('css', static::TOOLBAR_EDIT_LINK_SELECTOR)->mouseOver(); - $this->assertTrue($page->waitFor(10, function ($page) { - return !$page->find('css', '.contextual .trigger.visually-hidden'); - })); // No contextual triggers should be hidden. $web_assert->elementNotExists('css', '.contextual .trigger.visually-hidden'); // The toolbar edit button should read "Editing". diff --git a/core/modules/simpletest/tests/src/FunctionalJavascript/BrowserWithJavascriptTest.php b/core/modules/simpletest/tests/src/FunctionalJavascript/BrowserWithJavascriptTest.php index 945afe95f83..24397990e04 100644 --- a/core/modules/simpletest/tests/src/FunctionalJavascript/BrowserWithJavascriptTest.php +++ b/core/modules/simpletest/tests/src/FunctionalJavascript/BrowserWithJavascriptTest.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\simpletest\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests if we can execute JavaScript in the browser. * * @group javascript */ -class BrowserWithJavascriptTest extends WebDriverTestBase { +class BrowserWithJavascriptTest extends JavascriptTestBase { public function testJavascript() { $this->drupalGet(''); diff --git a/core/modules/simpletest/tests/src/FunctionalJavascript/JavascriptGetDrupalSettingsTest.php b/core/modules/simpletest/tests/src/FunctionalJavascript/JavascriptGetDrupalSettingsTest.php index fbe9b737926..0048159bfa8 100644 --- a/core/modules/simpletest/tests/src/FunctionalJavascript/JavascriptGetDrupalSettingsTest.php +++ b/core/modules/simpletest/tests/src/FunctionalJavascript/JavascriptGetDrupalSettingsTest.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\simpletest\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests Drupal settings retrieval in JavascriptTestBase tests. * * @group javascript */ -class JavascriptGetDrupalSettingsTest extends WebDriverTestBase { +class JavascriptGetDrupalSettingsTest extends JavascriptTestBase { /** * {@inheritdoc} @@ -19,7 +19,7 @@ class JavascriptGetDrupalSettingsTest extends WebDriverTestBase { /** * Tests retrieval of Drupal settings. * - * @see \Drupal\FunctionalJavascriptTests\WebDriverTestBase::getDrupalSettings() + * @see \Drupal\FunctionalJavascriptTests\JavascriptTestBase::getDrupalSettings() */ public function testGetDrupalSettings() { $this->drupalLogin($this->drupalCreateUser()); diff --git a/core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php b/core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php index acd103e9f69..b00f0ed47df 100644 --- a/core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php +++ b/core/modules/statistics/tests/src/FunctionalJavascript/StatisticsLoggingTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\statistics\FunctionalJavascript; use Drupal\Core\Session\AccountInterface; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\user\Entity\Role; @@ -12,7 +12,7 @@ use Drupal\user\Entity\Role; * * @group system */ -class StatisticsLoggingTest extends WebDriverTestBase { +class StatisticsLoggingTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/system/tests/src/FunctionalJavascript/ModalRendererTest.php b/core/modules/system/tests/src/FunctionalJavascript/ModalRendererTest.php index 3597ba46dd2..7c0aec022cb 100644 --- a/core/modules/system/tests/src/FunctionalJavascript/ModalRendererTest.php +++ b/core/modules/system/tests/src/FunctionalJavascript/ModalRendererTest.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\system\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests that dialog links use different renderer services. * * @group system */ -class ModalRendererTest extends WebDriverTestBase { +class ModalRendererTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTest.php b/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTest.php index c42d777c135..7719634118c 100644 --- a/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTest.php +++ b/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTest.php @@ -50,7 +50,7 @@ class OffCanvasTest extends OffCanvasTestBase { if ($link_index == '2') { // Check no title behavior. $web_assert->elementExists('css', '.ui-dialog-empty-title'); - $this->assertEquals(' ', $header_text); + $this->assertEquals("\xc2\xa0", $header_text); $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style'); $this->assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.'); @@ -127,9 +127,6 @@ class OffCanvasTest extends OffCanvasTestBase { $this->waitForOffCanvasToOpen(); // Check that the main canvas is padded when page is not narrow width and // tray is open. - $page->waitFor(10, function ($page) { - return $page->find('css', '.dialog-off-canvas-main-canvas')->hasAttribute('style'); - }); $web_assert->elementAttributeContains('css', '.dialog-off-canvas-main-canvas', 'style', 'padding-right'); // Testing at the narrower width. diff --git a/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php b/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php index b2e6c2b65d8..293d9f70a04 100644 --- a/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php +++ b/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php @@ -2,12 +2,12 @@ namespace Drupal\Tests\system\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Base class contains common test functionality for the Off-canvas dialog. */ -abstract class OffCanvasTestBase extends WebDriverTestBase { +abstract class OffCanvasTestBase extends JavascriptTestBase { /** * {@inheritdoc} @@ -106,22 +106,8 @@ abstract class OffCanvasTestBase extends WebDriverTestBase { * @todo Remove in https://www.drupal.org/node/2892440. */ protected function waitForNoElement($selector, $timeout = 10000) { - - $start = microtime(TRUE); - $end = $start + ($timeout / 1000); - $page = $this->getSession()->getPage(); - - do { - $result = $page->find('css', $selector); - - if (empty($result)) { - return; - } - - usleep(100000); - } while (microtime(TRUE) < $end); - - $this->assertEmpty($result, 'Element was not on the page after wait.'); + $condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)"; + $this->assertJsCondition($condition, $timeout); } /** @@ -146,7 +132,6 @@ abstract class OffCanvasTestBase extends WebDriverTestBase { * (Optional) Timeout in milliseconds, defaults to 10000. */ protected function assertElementVisibleAfterWait($selector, $locator, $timeout = 10000) { - $this->assertSession()->assertWaitOnAjaxRequest(); $this->assertNotEmpty($this->assertSession()->waitForElementVisible($selector, $locator, $timeout)); } diff --git a/core/modules/system/tests/src/FunctionalJavascript/ThemeFormSettingsTest.php b/core/modules/system/tests/src/FunctionalJavascript/ThemeFormSettingsTest.php index 4f3e9f1d49c..8e4729fe332 100644 --- a/core/modules/system/tests/src/FunctionalJavascript/ThemeFormSettingsTest.php +++ b/core/modules/system/tests/src/FunctionalJavascript/ThemeFormSettingsTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\system\FunctionalJavascript; use Drupal\file\Entity\File; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\Tests\TestFileCreationTrait; /** @@ -11,7 +11,7 @@ use Drupal\Tests\TestFileCreationTrait; * * @group system */ -class ThemeFormSettingsTest extends WebDriverTestBase { +class ThemeFormSettingsTest extends JavascriptTestBase { use TestFileCreationTrait; diff --git a/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php index 88153abce5b..76fbcc77d74 100644 --- a/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php +++ b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php @@ -3,14 +3,14 @@ namespace Drupal\Tests\text\FunctionalJavascript; use Drupal\field\Entity\FieldConfig; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the JavaScript functionality of the text_textarea_with_summary widget. * * @group text */ -class TextareaWithSummaryTest extends WebDriverTestBase { +class TextareaWithSummaryTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php index fd163985e75..c3b3d9abc60 100644 --- a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php +++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\toolbar\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the JavaScript functionality of the toolbar. * * @group toolbar */ -class ToolbarIntegrationTest extends WebDriverTestBase { +class ToolbarIntegrationTest extends JavascriptTestBase { /** * {@inheritdoc} @@ -27,12 +27,7 @@ class ToolbarIntegrationTest extends WebDriverTestBase { ]); $this->drupalLogin($admin_user); - // Set size for horizontal toolbar. - $this->getSession()->resizeWindow(1200, 600); $this->drupalGet(''); - $this->assertNotEmpty($this->assertSession()->waitForElement('css', 'body.toolbar-horizontal')); - $this->assertNotEmpty($this->assertSession()->waitForElementVisible('css', '.toolbar-tray')); - $page = $this->getSession()->getPage(); // Test that it is possible to toggle the toolbar tray. diff --git a/core/modules/views/tests/src/FunctionalJavascript/ClickSortingAJAXTest.php b/core/modules/views/tests/src/FunctionalJavascript/ClickSortingAJAXTest.php index 085fd821d52..0e5095d81ae 100644 --- a/core/modules/views/tests/src/FunctionalJavascript/ClickSortingAJAXTest.php +++ b/core/modules/views/tests/src/FunctionalJavascript/ClickSortingAJAXTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\views\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\simpletest\ContentTypeCreationTrait; use Drupal\simpletest\NodeCreationTrait; use Drupal\views\Tests\ViewTestData; @@ -12,7 +12,7 @@ use Drupal\views\Tests\ViewTestData; * * @group views */ -class ClickSortingAJAXTest extends WebDriverTestBase { +class ClickSortingAJAXTest extends JavascriptTestBase { use ContentTypeCreationTrait; use NodeCreationTrait; diff --git a/core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php b/core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php index 6aa52bcd12c..dc6846876b6 100644 --- a/core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php +++ b/core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\views\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\simpletest\ContentTypeCreationTrait; use Drupal\simpletest\NodeCreationTrait; @@ -11,7 +11,7 @@ use Drupal\simpletest\NodeCreationTrait; * * @group views */ -class ExposedFilterAJAXTest extends WebDriverTestBase { +class ExposedFilterAJAXTest extends JavascriptTestBase { use ContentTypeCreationTrait; use NodeCreationTrait; diff --git a/core/modules/views/tests/src/FunctionalJavascript/GlossaryViewTest.php b/core/modules/views/tests/src/FunctionalJavascript/GlossaryViewTest.php index d4760e59b41..594d6f764bb 100644 --- a/core/modules/views/tests/src/FunctionalJavascript/GlossaryViewTest.php +++ b/core/modules/views/tests/src/FunctionalJavascript/GlossaryViewTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\views\FunctionalJavascript; use Drupal\Core\Url; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\simpletest\ContentTypeCreationTrait; use Drupal\simpletest\NodeCreationTrait; @@ -14,7 +14,7 @@ use Drupal\views\Tests\ViewTestData; * * @group node */ -class GlossaryViewTest extends WebDriverTestBase { +class GlossaryViewTest extends JavascriptTestBase { use ContentTypeCreationTrait; use NodeCreationTrait; diff --git a/core/modules/views/tests/src/FunctionalJavascript/PaginationAJAXTest.php b/core/modules/views/tests/src/FunctionalJavascript/PaginationAJAXTest.php index de4efd24abd..b4372c6d61b 100644 --- a/core/modules/views/tests/src/FunctionalJavascript/PaginationAJAXTest.php +++ b/core/modules/views/tests/src/FunctionalJavascript/PaginationAJAXTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\views\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\simpletest\ContentTypeCreationTrait; use Drupal\simpletest\NodeCreationTrait; use Drupal\views\Tests\ViewTestData; @@ -12,7 +12,7 @@ use Drupal\views\Tests\ViewTestData; * * @group views */ -class PaginationAJAXTest extends WebDriverTestBase { +class PaginationAJAXTest extends JavascriptTestBase { use ContentTypeCreationTrait; use NodeCreationTrait; diff --git a/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/ContextualFilterTest.php b/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/ContextualFilterTest.php index f0ac6085487..dd1d1ae2648 100644 --- a/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/ContextualFilterTest.php +++ b/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/ContextualFilterTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\views\Tests\ViewTestData; /** @@ -10,7 +10,7 @@ use Drupal\views\Tests\ViewTestData; * * @group views */ -class ContextualFilterTest extends WebDriverTestBase { +class ContextualFilterTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php b/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php index 079fe99ee4a..76f0ff1e214 100644 --- a/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php +++ b/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php @@ -4,7 +4,7 @@ namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler; use Drupal\Tests\SchemaCheckTestTrait; use Drupal\field\Entity\FieldConfig; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\node\Entity\NodeType; use Drupal\views\Tests\ViewTestData; @@ -13,7 +13,7 @@ use Drupal\views\Tests\ViewTestData; * * @group views */ -class FieldTest extends WebDriverTestBase { +class FieldTest extends JavascriptTestBase { use SchemaCheckTestTrait; /** diff --git a/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/GroupedExposedFilterTest.php b/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/GroupedExposedFilterTest.php index 1bc8a486d32..9a9b2da4a8d 100644 --- a/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/GroupedExposedFilterTest.php +++ b/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/GroupedExposedFilterTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler; use Drupal\field\Entity\FieldConfig; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\node\Entity\NodeType; use Drupal\views\Tests\ViewTestData; @@ -12,7 +12,7 @@ use Drupal\views\Tests\ViewTestData; * * @group views */ -class GroupedExposedFilterTest extends WebDriverTestBase { +class GroupedExposedFilterTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php index 7dcaccdd241..c8d37f21c3c 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\views_ui\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\simpletest\NodeCreationTrait; use Drupal\views\Entity\View; use Drupal\views\Tests\ViewTestData; @@ -12,7 +12,7 @@ use Drupal\views\Tests\ViewTestData; * * @group views_ui */ -class DisplayTest extends WebDriverTestBase { +class DisplayTest extends JavascriptTestBase { use NodeCreationTrait; diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php index 9e303dfb922..e48487a6ed6 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\views_ui\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the View UI filter criteria group dialog. * * @group views_ui */ -class FilterCriteriaTest extends WebDriverTestBase { +class FilterCriteriaTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/FilterOptionsTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterOptionsTest.php index 6f2f6259682..32b1a400cb7 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/FilterOptionsTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterOptionsTest.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\views_ui\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the JavaScript filtering of options in add handler form. * * @group views_ui */ -class FilterOptionsTest extends WebDriverTestBase { +class FilterOptionsTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/LibraryCachingTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/LibraryCachingTest.php index b1b158ba6ce..4cf51d57fa3 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/LibraryCachingTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/LibraryCachingTest.php @@ -2,14 +2,14 @@ namespace Drupal\Tests\views_ui\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the JavaScript library caching on consecutive requests. * * @group views_ui */ -class LibraryCachingTest extends WebDriverTestBase { +class LibraryCachingTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php index fc696c03a86..86d3b6e5e7e 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\views_ui\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the JavaScript filtering on the Views listing page. @@ -10,7 +10,7 @@ use Drupal\FunctionalJavascriptTests\WebDriverTestBase; * @see core/modules/views_ui/js/views_ui.listing.js * @group views_ui */ -class ViewsListingTest extends WebDriverTestBase { +class ViewsListingTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsWizardTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsWizardTest.php index 16369f12fea..3fb1167e1f3 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsWizardTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsWizardTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\views_ui\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests views creation wizard. @@ -10,7 +10,7 @@ use Drupal\FunctionalJavascriptTests\WebDriverTestBase; * @see core/modules/views_ui/js/views-admin.js * @group views_ui */ -class ViewsWizardTest extends WebDriverTestBase { +class ViewsWizardTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/profiles/standard/tests/src/FunctionalJavascript/StandardJavascriptTest.php b/core/profiles/standard/tests/src/FunctionalJavascript/StandardJavascriptTest.php index 13973e0c5dc..c9c92f404f2 100644 --- a/core/profiles/standard/tests/src/FunctionalJavascript/StandardJavascriptTest.php +++ b/core/profiles/standard/tests/src/FunctionalJavascript/StandardJavascriptTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\standard\FunctionalJavascript; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\node\Entity\Node; /** @@ -10,7 +10,7 @@ use Drupal\node\Entity\Node; * * @group standard */ -class StandardJavascriptTest extends WebDriverTestBase { +class StandardJavascriptTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxCallbacksTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxCallbacksTest.php index ffdbd98eb91..e13ecfd56c6 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxCallbacksTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxCallbacksTest.php @@ -2,14 +2,14 @@ namespace Drupal\FunctionalJavascriptTests\Ajax; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests Ajax callbacks on FAPI elements. * * @group Ajax */ -class AjaxCallbacksTest extends WebDriverTestBase { +class AjaxCallbacksTest extends JavascriptTestBase { /** * {@inheritdoc} @@ -23,9 +23,11 @@ class AjaxCallbacksTest extends WebDriverTestBase { // Test Ajax callback when date changes. $this->drupalGet('ajax_forms_test_ajax_element_form'); - $this->assertNotEmpty($this->getSession()->getPage()->find('xpath', '//div[@id="ajax_date_value"][text()="No date yet selected"]')); - $this->getSession()->executeScript('jQuery("[data-drupal-selector=edit-date]").val("2016-01-01").trigger("change");'); - $this->assertNotEmpty($this->assertSession()->waitForElement('xpath', '//div[@id="ajax_date_value"]/div[text()="2016-01-01"]')); + $this->assertSession()->responseContains('No date yet selected'); + $this->getSession()->getPage()->fillField('edit-date', '2016-01-01'); + $this->assertSession()->assertWaitOnAjaxRequest(); + $this->assertSession()->responseNotContains('No date yet selected'); + $this->assertSession()->responseContains('2016-01-01'); } /** @@ -35,10 +37,14 @@ class AjaxCallbacksTest extends WebDriverTestBase { // Test Ajax callback when datetime changes. $this->drupalGet('ajax_forms_test_ajax_element_form'); - $this->assertNotEmpty($this->getSession()->getPage()->find('xpath', '//div[@id="ajax_datetime_value"][text()="No datetime selected."]')); - $this->getSession()->executeScript('jQuery("[data-drupal-selector=edit-datetime-date]").val("2016-01-01");'); - $this->getSession()->executeScript('jQuery("[data-drupal-selector=edit-datetime-time]").val("12:00:00").trigger("change");'); - $this->assertNotEmpty($this->assertSession()->waitForElement('xpath', '//div[@id="ajax_datetime_value"]/div[text()="2016-01-01 12:00:00"]')); + $this->assertSession()->responseContains('No datetime selected.'); + $this->getSession()->getPage()->fillField('edit-datetime-date', '2016-01-01'); + $this->assertSession()->assertWaitOnAjaxRequest(); + $this->assertSession()->responseNotContains('No datetime selected.'); + $this->assertSession()->responseContains('2016-01-01'); + $this->getSession()->getPage()->fillField('edit-datetime-time', '12:00:00'); + $this->assertSession()->assertWaitOnAjaxRequest(); + $this->assertSession()->responseContains('2016-01-01 12:00:00'); } } diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormImageButtonTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormImageButtonTest.php index bfd890a04f7..4811a350ac7 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormImageButtonTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormImageButtonTest.php @@ -2,14 +2,14 @@ namespace Drupal\FunctionalJavascriptTests\Ajax; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the Ajax image buttons work with key press events. * * @group Ajax */ -class AjaxFormImageButtonTest extends WebDriverTestBase { +class AjaxFormImageButtonTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormPageCacheTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormPageCacheTest.php index 06b64af67b2..3d174b04df1 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormPageCacheTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormPageCacheTest.php @@ -2,14 +2,14 @@ namespace Drupal\FunctionalJavascriptTests\Ajax; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Performs tests on AJAX forms in cached pages. * * @group Ajax */ -class AjaxFormPageCacheTest extends WebDriverTestBase { +class AjaxFormPageCacheTest extends JavascriptTestBase { /** * {@inheritdoc} @@ -41,6 +41,7 @@ class AjaxFormPageCacheTest extends WebDriverTestBase { */ public function testSimpleAJAXFormValue() { $this->drupalGet('ajax_forms_test_get_form'); + $this->assertEquals($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.'); $build_id_initial = $this->getFormBuildId(); // Changing the value of a select input element, triggers a AJAX @@ -76,6 +77,7 @@ class AjaxFormPageCacheTest extends WebDriverTestBase { // Emulate a push of the reload button and then repeat the test sequence // this time with a page loaded from the cache. $session->reload(); + $this->assertEquals($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); $build_id_from_cache_initial = $this->getFormBuildId(); $this->assertEquals($build_id_initial, $build_id_from_cache_initial, 'Build id is the same as on the first request'); @@ -113,9 +115,7 @@ class AjaxFormPageCacheTest extends WebDriverTestBase { $this->drupalGet('ajax_validation_test'); // Changing the value of the textfield will trigger an AJAX // request/response. - $field = $this->getSession()->getPage()->findField('drivertext'); - $field->setValue('some dumb text'); - $field->blur(); + $this->getSession()->getPage()->fillField('drivertext', 'some dumb text'); // When the AJAX command updates the DOM a
    unsorted list // "message__list" structure will appear on the page echoing back the diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php index fa2a3e45c02..e05940537c4 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxTest.php @@ -2,14 +2,14 @@ namespace Drupal\FunctionalJavascriptTests\Ajax; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests AJAX responses. * * @group Ajax */ -class AjaxTest extends WebDriverTestBase { +class AjaxTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/BackwardCompatibilityTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/BackwardCompatibilityTest.php index 9a45583b7c2..077c3aa1ae3 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/BackwardCompatibilityTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/BackwardCompatibilityTest.php @@ -2,14 +2,14 @@ namespace Drupal\FunctionalJavascriptTests\Ajax; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the compatibility of the ajax.es6.js file. * * @group Ajax */ -class BackwardCompatibilityTest extends WebDriverTestBase { +class BackwardCompatibilityTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/ThrobberTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/ThrobberTest.php index 56715e6dd13..e2ecaea7a46 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/ThrobberTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/ThrobberTest.php @@ -2,14 +2,20 @@ namespace Drupal\FunctionalJavascriptTests\Ajax; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the throbber. * * @group Ajax */ -class ThrobberTest extends WebDriverTestBase { +class ThrobberTest extends JavascriptTestBase { + + /** + * {@inheritdoc} + */ + protected $minkDefaultDriverClass = DrupalSelenium2Driver::class; /** * {@inheritdoc} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Core/Form/FormGroupingElementsTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Core/Form/FormGroupingElementsTest.php index 1c76c26ea35..92b3a739f64 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Core/Form/FormGroupingElementsTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Core/Form/FormGroupingElementsTest.php @@ -2,14 +2,14 @@ namespace Drupal\FunctionalJavascriptTests\Core\Form; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests for form grouping elements. * * @group form */ -class FormGroupingElementsTest extends WebDriverTestBase { +class FormGroupingElementsTest extends JavascriptTestBase { /** * Required modules. diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Core/Installer/Form/SelectProfileFormTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Core/Installer/Form/SelectProfileFormTest.php index a6c59d11529..efad210c6a8 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Core/Installer/Form/SelectProfileFormTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Core/Installer/Form/SelectProfileFormTest.php @@ -6,7 +6,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Language\Language; use Drupal\Core\Session\UserSession; use Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use GuzzleHttp\HandlerStack; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\Request; @@ -17,7 +17,7 @@ use Symfony\Component\HttpFoundation\RequestStack; * * @group Installer */ -class SelectProfileFormTest extends WebDriverTestBase { +class SelectProfileFormTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php index 71bdc982e6e..bf2643da6a5 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Core/MachineNameTest.php @@ -2,14 +2,14 @@ namespace Drupal\FunctionalJavascriptTests\Core; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests for the machine name field. * * @group field */ -class MachineNameTest extends WebDriverTestBase { +class MachineNameTest extends JavascriptTestBase { /** * Required modules. diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php index f4a18003824..fa2d541c8a8 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php @@ -2,7 +2,7 @@ namespace Drupal\FunctionalJavascriptTests\Core\Session; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\menu_link_content\Entity\MenuLinkContent; /** @@ -10,7 +10,7 @@ use Drupal\menu_link_content\Entity\MenuLinkContent; * * @group session */ -class SessionTest extends WebDriverTestBase { +class SessionTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php index 4bfe3e0b3ae..19cf5a4b359 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php @@ -2,14 +2,14 @@ namespace Drupal\FunctionalJavascriptTests\Dialog; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests the JavaScript functionality of the dialog position. * * @group dialog */ -class DialogPositionTest extends WebDriverTestBase { +class DialogPositionTest extends JavascriptTestBase { /** * {@inheritdoc} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php b/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php index f67e738baf0..5f243af6709 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php @@ -3,21 +3,12 @@ namespace Drupal\FunctionalJavascriptTests; use Behat\Mink\Driver\Selenium2Driver; -use WebDriver\ServiceFactory; /** * Provides a driver for Selenium testing. */ class DrupalSelenium2Driver extends Selenium2Driver { - /** - * {@inheritdoc} - */ - public function __construct($browserName = 'firefox', $desiredCapabilities = NULL, $wdHost = 'http://localhost:4444/wd/hub') { - parent::__construct($browserName, $desiredCapabilities, $wdHost); - ServiceFactory::getInstance()->setServiceClass('service.curl', WebDriverCurlService::class); - } - /** * {@inheritdoc} */ diff --git a/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php b/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php index 3d0b402a481..511dee6e32a 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php @@ -3,7 +3,7 @@ namespace Drupal\FunctionalJavascriptTests\EntityReference; use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; use Drupal\simpletest\ContentTypeCreationTrait; use Drupal\simpletest\NodeCreationTrait; @@ -12,7 +12,7 @@ use Drupal\simpletest\NodeCreationTrait; * * @group entity_reference */ -class EntityReferenceAutocompleteWidgetTest extends WebDriverTestBase { +class EntityReferenceAutocompleteWidgetTest extends JavascriptTestBase { use ContentTypeCreationTrait; use EntityReferenceTestTrait; @@ -63,7 +63,7 @@ class EntityReferenceAutocompleteWidgetTest extends WebDriverTestBase { $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); - $autocomplete_field = $assert_session->waitForElement('css', '[name="' . $field_name . '[0][target_id]"].ui-autocomplete-input'); + $autocomplete_field = $page->findField($field_name . '[0][target_id]'); $autocomplete_field->setValue('Test'); $this->getSession()->getDriver()->keyDown($autocomplete_field->getXpath(), ' '); $assert_session->waitOnAutocomplete(); @@ -87,7 +87,7 @@ class EntityReferenceAutocompleteWidgetTest extends WebDriverTestBase { $this->drupalGet('node/add/page'); $page = $this->getSession()->getPage(); - $autocomplete_field = $assert_session->waitForElement('css', '[name="' . $field_name . '[0][target_id]"].ui-autocomplete-input'); + $autocomplete_field = $page->findField($field_name . '[0][target_id]'); $autocomplete_field->setValue('Test'); $this->getSession()->getDriver()->keyDown($autocomplete_field->getXpath(), ' '); $assert_session->waitOnAutocomplete(); diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php index b545f711827..44b83c1633d 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php @@ -2,33 +2,202 @@ namespace Drupal\FunctionalJavascriptTests; -@trigger_error('The ' . __NAMESPACE__ . '\JavascriptTestBase is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\WebDriverTestBase. See https://www.drupal.org/node/2945059', E_USER_DEPRECATED); - +use Drupal\Tests\BrowserTestBase; +use Zumba\GastonJS\Exception\DeadClient; use Zumba\Mink\Driver\PhantomJSDriver; /** - * Runs a browser test using PhantomJS. + * Runs a browser test using a driver that supports Javascript. * * Base class for testing browser interaction implemented in JavaScript. - * - * @deprecated in Drupal 8.6.x, will be removed before Drupal 9.0.0. - * Use \Drupal\FunctionalJavascriptTests\WebDriverTestBase instead - * - * @see https://www.drupal.org/node/2945059 */ -abstract class JavascriptTestBase extends WebDriverTestBase { +abstract class JavascriptTestBase extends BrowserTestBase { /** * {@inheritdoc} + * + * To use a webdriver based approach, please use DrupalSelenium2Driver::class. + * We will switch the default later. */ protected $minkDefaultDriverClass = PhantomJSDriver::class; + /** + * {@inheritdoc} + */ + protected function initMink() { + if ($this->minkDefaultDriverClass === DrupalSelenium2Driver::class) { + $this->minkDefaultDriverArgs = ['chrome', NULL, 'http://localhost:4444/']; + } + elseif ($this->minkDefaultDriverClass === PhantomJSDriver::class) { + // Set up the template cache used by the PhantomJS mink driver. + $path = $this->tempFilesDirectory . DIRECTORY_SEPARATOR . 'browsertestbase-templatecache'; + $this->minkDefaultDriverArgs = [ + 'http://127.0.0.1:8510', + $path, + ]; + if (!file_exists($path)) { + mkdir($path); + } + } + + try { + return parent::initMink(); + } + catch (DeadClient $e) { + $this->markTestSkipped('PhantomJS is either not installed or not running. Start it via phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768&'); + } + catch (\Exception $e) { + $this->markTestSkipped('An unexpected error occurred while starting Mink: ' . $e->getMessage()); + } + } + + /** + * {@inheritdoc} + */ + protected function tearDown() { + if ($this->mink) { + // Wait for all requests to finish. It is possible that an AJAX request is + // still on-going. + $result = $this->getSession()->wait(5000, '(typeof(jQuery)=="undefined" || (0 === jQuery.active && 0 === jQuery(\':animated\').length))'); + if (!$result) { + // If the wait is unsuccessful, there may still be an AJAX request in + // progress. If we tear down now, then this AJAX request may fail with + // missing database tables, because tear down will have removed them. + // Rather than allow it to fail, throw an explicit exception now + // explaining what the problem is. + throw new \RuntimeException('Unfinished AJAX requests while tearing down a test'); + } + } + parent::tearDown(); + } + + /** + * {@inheritdoc} + */ + protected function getMinkDriverArgs() { + if ($this->minkDefaultDriverClass === DrupalSelenium2Driver::class) { + return getenv('MINK_DRIVER_ARGS_WEBDRIVER') ?: getenv('MINK_DRIVER_ARGS_PHANTOMJS') ?: parent::getMinkDriverArgs(); + } + elseif ($this->minkDefaultDriverClass === PhantomJSDriver::class) { + return getenv('MINK_DRIVER_ARGS_PHANTOMJS') ?: parent::getMinkDriverArgs(); + } + return parent::getMinkDriverArgs(); + } + + /** + * Asserts that the element with the given CSS selector is visible. + * + * @param string $css_selector + * The CSS selector identifying the element to check. + * @param string $message + * Optional message to show alongside the assertion. + * + * @deprecated in Drupal 8.1.0, will be removed before Drupal 9.0.0. Use + * \Behat\Mink\Element\NodeElement::isVisible() instead. + */ + protected function assertElementVisible($css_selector, $message = '') { + $this->assertTrue($this->getSession()->getDriver()->isVisible($this->cssSelectToXpath($css_selector)), $message); + @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 8.1.0 and will be removed in 9.0.0. Use \Behat\Mink\Element\NodeElement::isVisible() instead.', E_USER_DEPRECATED); + } + + /** + * Asserts that the element with the given CSS selector is not visible. + * + * @param string $css_selector + * The CSS selector identifying the element to check. + * @param string $message + * Optional message to show alongside the assertion. + * + * @deprecated in Drupal 8.1.0, will be removed before Drupal 9.0.0. Use + * \Behat\Mink\Element\NodeElement::isVisible() instead. + */ + protected function assertElementNotVisible($css_selector, $message = '') { + $this->assertFalse($this->getSession()->getDriver()->isVisible($this->cssSelectToXpath($css_selector)), $message); + @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 8.1.0 and will be removed in 9.0.0. Use \Behat\Mink\Element\NodeElement::isVisible() instead.', E_USER_DEPRECATED); + } + + /** + * Waits for the given time or until the given JS condition becomes TRUE. + * + * @param string $condition + * JS condition to wait until it becomes TRUE. + * @param int $timeout + * (Optional) Timeout in milliseconds, defaults to 10000. + * @param string $message + * (optional) A message to display with the assertion. If left blank, a + * default message will be displayed. + * + * @throws \PHPUnit_Framework_AssertionFailedError + * + * @see \Behat\Mink\Driver\DriverInterface::evaluateScript() + */ + protected function assertJsCondition($condition, $timeout = 10000, $message = '') { + $message = $message ?: "Javascript condition met:\n" . $condition; + $result = $this->getSession()->getDriver()->wait($timeout, $condition); + $this->assertTrue($result, $message); + } + + /** + * Creates a screenshot. + * + * @param string $filename + * The file name of the resulting screenshot. If using the default phantomjs + * driver then this should be a JPG filename. + * @param bool $set_background_color + * (optional) By default this method will set the background color to white. + * Set to FALSE to override this behaviour. + * + * @throws \Behat\Mink\Exception\UnsupportedDriverActionException + * When operation not supported by the driver. + * @throws \Behat\Mink\Exception\DriverException + * When the operation cannot be done. + */ + protected function createScreenshot($filename, $set_background_color = TRUE) { + $session = $this->getSession(); + if ($set_background_color) { + $session->executeScript("document.body.style.backgroundColor = 'white';"); + } + $image = $session->getScreenshot(); + file_put_contents($filename, $image); + } + /** * {@inheritdoc} */ public function assertSession($name = NULL) { - // Return a WebAssert that supports status code and header assertions. - return new JSWebAssert($this->getSession($name), $this->baseUrl); + return new WebDriverWebAssert($this->getSession($name), $this->baseUrl); + } + + /** + * Gets the current Drupal javascript settings and parses into an array. + * + * Unlike BrowserTestBase::getDrupalSettings(), this implementation reads the + * current values of drupalSettings, capturing all changes made via javascript + * after the page was loaded. + * + * @return array + * The Drupal javascript settings array. + * + * @see \Drupal\Tests\BrowserTestBase::getDrupalSettings() + */ + protected function getDrupalSettings() { + $script = <<getSession()->evaluateScript($script) ?: []; + } + + /** + * {@inheritdoc} + */ + protected function getHtmlOutputHeaders() { + // The webdriver API does not support fetching headers. + return ''; } } diff --git a/core/tests/Drupal/FunctionalJavascriptTests/LegacyJavascriptTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/LegacyJavascriptTestBase.php index 70869d08b4e..b3baf6e2d37 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/LegacyJavascriptTestBase.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/LegacyJavascriptTestBase.php @@ -2,14 +2,26 @@ namespace Drupal\FunctionalJavascriptTests; +use Zumba\Mink\Driver\PhantomJSDriver; + /** * Runs a browser test using PhantomJS. * - * @deprecated in Drupal 8.6.0, will be removed before Drupal 9.0.0. - * Use \Drupal\FunctionalJavascriptTests\WebDriverTestBase instead - * - * BC layer for testing browser interaction implemented in JavaScript. + * Base class for testing browser interaction implemented in JavaScript. */ abstract class LegacyJavascriptTestBase extends JavascriptTestBase { + /** + * {@inheritdoc} + */ + protected $minkDefaultDriverClass = PhantomJSDriver::class; + + /** + * {@inheritdoc} + */ + public function assertSession($name = NULL) { + // Return a WebAssert that supports status code and header assertions. + return new JSWebAssert($this->getSession($name), $this->baseUrl); + } + } diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Tests/JSWebAssertTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Tests/JSWebAssertTest.php index 6dd591f5fe4..36f6340f727 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/Tests/JSWebAssertTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Tests/JSWebAssertTest.php @@ -3,14 +3,14 @@ namespace Drupal\FunctionalJavascriptTests\Tests; use Behat\Mink\Element\NodeElement; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; +use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** * Tests for the JSWebAssert class. * * @group javascript */ -class JSWebAssertTest extends WebDriverTestBase { +class JSWebAssertTest extends JavascriptTestBase { /** * Required modules. diff --git a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverCurlService.php b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverCurlService.php deleted file mode 100644 index 13991afd5da..00000000000 --- a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverCurlService.php +++ /dev/null @@ -1,110 +0,0 @@ - TRUE, - ]; - $retries = 0; - while ($retries < 10) { - try { - $customHeaders = [ - 'Content-Type: application/json;charset=UTF-8', - 'Accept: application/json;charset=UTF-8', - ]; - - $curl = curl_init($url); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); - - switch ($requestMethod) { - case 'GET': - break; - - case 'POST': - if ($parameters && is_array($parameters)) { - curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($parameters)); - } - else { - $customHeaders[] = 'Content-Length: 0'; - } - - // Suppress "Expect: 100-continue" header automatically added by - // cURL that causes a 1 second delay if the remote server does not - // support Expect. - $customHeaders[] = 'Expect:'; - - curl_setopt($curl, CURLOPT_POST, TRUE); - break; - - case 'DELETE': - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); - break; - - case 'PUT': - if ($parameters && is_array($parameters)) { - curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($parameters)); - } - else { - $customHeaders[] = 'Content-Length: 0'; - } - - // Suppress "Expect: 100-continue" header automatically added by - // cURL that causes a 1 second delay if the remote server does not - // support Expect. - $customHeaders[] = 'Expect:'; - - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); - break; - } - - foreach ($extraOptions as $option => $value) { - curl_setopt($curl, $option, $value); - } - - curl_setopt($curl, CURLOPT_HTTPHEADER, $customHeaders); - - $rawResult = trim(curl_exec($curl)); - - $info = curl_getinfo($curl); - $info['request_method'] = $requestMethod; - - if (array_key_exists(CURLOPT_FAILONERROR, $extraOptions) && $extraOptions[CURLOPT_FAILONERROR] && CURLE_GOT_NOTHING !== ($errno = curl_errno($curl)) && $error = curl_error($curl)) { - curl_close($curl); - - throw WebDriverException::factory(WebDriverException::CURL_EXEC, sprintf("Curl error thrown for http %s to %s%s\n\n%s", $requestMethod, $url, $parameters && is_array($parameters) ? ' with params: ' . json_encode($parameters) : '', $error)); - } - - curl_close($curl); - - $result = json_decode($rawResult, TRUE); - if (isset($result['status']) && $result['status'] === WebDriverException::STALE_ELEMENT_REFERENCE) { - usleep(100000); - $retries++; - continue; - } - return [$rawResult, $info]; - } - catch (CurlExec $exception) { - $retries++; - } - } - throw WebDriverException::factory(WebDriverException::CURL_EXEC, sprintf("Curl error thrown for http %s to %s%s\n\n%s", $requestMethod, $url, $parameters && is_array($parameters) ? ' with params: ' . json_encode($parameters) : '', $error)); - } - -} diff --git a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php deleted file mode 100644 index 1d32371cea4..00000000000 --- a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php +++ /dev/null @@ -1,202 +0,0 @@ -minkDefaultDriverClass === DrupalSelenium2Driver::class) { - $this->minkDefaultDriverArgs = ['chrome', NULL, 'http://localhost:4444/']; - } - elseif ($this->minkDefaultDriverClass === PhantomJSDriver::class) { - // Set up the template cache used by the PhantomJS mink driver. - $path = $this->tempFilesDirectory . DIRECTORY_SEPARATOR . 'browsertestbase-templatecache'; - $this->minkDefaultDriverArgs = [ - 'http://127.0.0.1:8510', - $path, - ]; - if (!file_exists($path)) { - mkdir($path); - } - } - - try { - return parent::initMink(); - } - catch (DeadClient $e) { - $this->markTestSkipped('PhantomJS is either not installed or not running. Start it via phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768&'); - } - catch (\Exception $e) { - $this->markTestSkipped('An unexpected error occurred while starting Mink: ' . $e->getMessage()); - } - } - - /** - * {@inheritdoc} - */ - protected function tearDown() { - if ($this->mink) { - // Wait for all requests to finish. It is possible that an AJAX request is - // still on-going. - $result = $this->getSession()->wait(5000, '(typeof(jQuery)=="undefined" || (0 === jQuery.active && 0 === jQuery(\':animated\').length))'); - if (!$result) { - // If the wait is unsuccessful, there may still be an AJAX request in - // progress. If we tear down now, then this AJAX request may fail with - // missing database tables, because tear down will have removed them. - // Rather than allow it to fail, throw an explicit exception now - // explaining what the problem is. - throw new \RuntimeException('Unfinished AJAX requests while tearing down a test'); - } - } - parent::tearDown(); - } - - /** - * {@inheritdoc} - */ - protected function getMinkDriverArgs() { - if ($this->minkDefaultDriverClass === DrupalSelenium2Driver::class) { - return getenv('MINK_DRIVER_ARGS_WEBDRIVER') ?: getenv('MINK_DRIVER_ARGS_PHANTOMJS') ?: parent::getMinkDriverArgs(); - } - elseif ($this->minkDefaultDriverClass === PhantomJSDriver::class) { - return getenv('MINK_DRIVER_ARGS_PHANTOMJS') ?: parent::getMinkDriverArgs(); - } - return parent::getMinkDriverArgs(); - } - - /** - * Asserts that the element with the given CSS selector is visible. - * - * @param string $css_selector - * The CSS selector identifying the element to check. - * @param string $message - * Optional message to show alongside the assertion. - * - * @deprecated in Drupal 8.1.0, will be removed before Drupal 9.0.0. Use - * \Behat\Mink\Element\NodeElement::isVisible() instead. - */ - protected function assertElementVisible($css_selector, $message = '') { - $this->assertTrue($this->getSession()->getDriver()->isVisible($this->cssSelectToXpath($css_selector)), $message); - @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 8.1.0 and will be removed in 9.0.0. Use \Behat\Mink\Element\NodeElement::isVisible() instead.', E_USER_DEPRECATED); - } - - /** - * Asserts that the element with the given CSS selector is not visible. - * - * @param string $css_selector - * The CSS selector identifying the element to check. - * @param string $message - * Optional message to show alongside the assertion. - * - * @deprecated in Drupal 8.1.0, will be removed before Drupal 9.0.0. Use - * \Behat\Mink\Element\NodeElement::isVisible() instead. - */ - protected function assertElementNotVisible($css_selector, $message = '') { - $this->assertFalse($this->getSession()->getDriver()->isVisible($this->cssSelectToXpath($css_selector)), $message); - @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 8.1.0 and will be removed in 9.0.0. Use \Behat\Mink\Element\NodeElement::isVisible() instead.', E_USER_DEPRECATED); - } - - /** - * Waits for the given time or until the given JS condition becomes TRUE. - * - * @param string $condition - * JS condition to wait until it becomes TRUE. - * @param int $timeout - * (Optional) Timeout in milliseconds, defaults to 10000. - * @param string $message - * (optional) A message to display with the assertion. If left blank, a - * default message will be displayed. - * - * @throws \PHPUnit_Framework_AssertionFailedError - * - * @see \Behat\Mink\Driver\DriverInterface::evaluateScript() - */ - protected function assertJsCondition($condition, $timeout = 10000, $message = '') { - $message = $message ?: "Javascript condition met:\n" . $condition; - $result = $this->getSession()->getDriver()->wait($timeout, $condition); - $this->assertTrue($result, $message); - } - - /** - * Creates a screenshot. - * - * @param string $filename - * The file name of the resulting screenshot. If using the default phantomjs - * driver then this should be a JPG filename. - * @param bool $set_background_color - * (optional) By default this method will set the background color to white. - * Set to FALSE to override this behaviour. - * - * @throws \Behat\Mink\Exception\UnsupportedDriverActionException - * When operation not supported by the driver. - * @throws \Behat\Mink\Exception\DriverException - * When the operation cannot be done. - */ - protected function createScreenshot($filename, $set_background_color = TRUE) { - $session = $this->getSession(); - if ($set_background_color) { - $session->executeScript("document.body.style.backgroundColor = 'white';"); - } - $image = $session->getScreenshot(); - file_put_contents($filename, $image); - } - - /** - * {@inheritdoc} - */ - public function assertSession($name = NULL) { - return new WebDriverWebAssert($this->getSession($name), $this->baseUrl); - } - - /** - * Gets the current Drupal javascript settings and parses into an array. - * - * Unlike BrowserTestBase::getDrupalSettings(), this implementation reads the - * current values of drupalSettings, capturing all changes made via javascript - * after the page was loaded. - * - * @return array - * The Drupal javascript settings array. - * - * @see \Drupal\Tests\BrowserTestBase::getDrupalSettings() - */ - protected function getDrupalSettings() { - $script = <<getSession()->evaluateScript($script) ?: []; - } - - /** - * {@inheritdoc} - */ - protected function getHtmlOutputHeaders() { - // The webdriver API does not support fetching headers. - return ''; - } - -}