Revert "Issue #2942900 by Mixologic, vaplas, jibran, Lendude, martin107, alexpott, dawehner, tedbow, tacituseu, tstoeckler, heddn: Convert JavascriptTestBase Tests to use DrupalSelenium2Driver"

This reverts commit f55d974612.
merge-requests/1654/head
Alex Pott 2018-07-04 08:20:33 +01:00
parent f55d974612
commit ff99cb2133
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
74 changed files with 380 additions and 553 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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.');

View File

@ -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}

View File

@ -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}

View File

@ -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.

View File

@ -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;

View File

@ -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.

View File

@ -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}

View File

@ -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.');

View File

@ -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.');

View File

@ -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;

View File

@ -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;

View File

@ -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.
*

View File

@ -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.

View File

@ -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.

View File

@ -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}

View File

@ -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');

View File

@ -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;

View File

@ -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}

View File

@ -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');

View File

@ -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}

View File

@ -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();

View File

@ -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;

View File

@ -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}

View File

@ -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.

View File

@ -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 */

View File

@ -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.

View File

@ -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".

View File

@ -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('<front>');

View File

@ -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());

View File

@ -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}

View File

@ -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}

View File

@ -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.

View File

@ -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));
}

View File

@ -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;

View File

@ -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}

View File

@ -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('<front>');
$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.

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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}

View File

@ -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;
/**

View File

@ -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}

View File

@ -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;

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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');
}
}

View File

@ -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}

View File

@ -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 <ul> unsorted list
// "message__list" structure will appear on the page echoing back the

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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.

View File

@ -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}

View File

@ -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.

View File

@ -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}

View File

@ -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}

View File

@ -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}
*/

View File

@ -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();

View File

@ -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 = <<<EndOfScript
(function () {
if (typeof drupalSettings !== 'undefined') {
return drupalSettings;
}
})();
EndOfScript;
return $this->getSession()->evaluateScript($script) ?: [];
}
/**
* {@inheritdoc}
*/
protected function getHtmlOutputHeaders() {
// The webdriver API does not support fetching headers.
return '';
}
}

View File

@ -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);
}
}

View File

@ -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.

View File

@ -1,110 +0,0 @@
<?php
namespace Drupal\FunctionalJavascriptTests;
use WebDriver\Service\CurlService;
use WebDriver\Exception\CurlExec;
use WebDriver\Exception as WebDriverException;
/**
* Provides a curl service to interact with Selenium driver.
*
* Extends WebDriver\Service\CurlService to solve problem with race conditions,
* when multiple processes requests.
*/
class WebDriverCurlService extends CurlService {
/**
* {@inheritdoc}
*/
public function execute($requestMethod, $url, $parameters = NULL, $extraOptions = []) {
$extraOptions += [
CURLOPT_FAILONERROR => 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));
}
}

View File

@ -1,202 +0,0 @@
<?php
namespace Drupal\FunctionalJavascriptTests;
use Drupal\Tests\BrowserTestBase;
use Zumba\GastonJS\Exception\DeadClient;
use Zumba\Mink\Driver\PhantomJSDriver;
/**
* Runs a browser test using a driver that supports Javascript.
*
* Base class for testing browser interaction implemented in JavaScript.
*/
abstract class WebDriverTestBase extends BrowserTestBase {
/**
* {@inheritdoc}
*
* To use a legacy phantomjs based approach, please use PhantomJSDriver::class.
*/
protected $minkDefaultDriverClass = DrupalSelenium2Driver::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 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 = <<<EndOfScript
(function () {
if (typeof drupalSettings !== 'undefined') {
return drupalSettings;
}
})();
EndOfScript;
return $this->getSession()->evaluateScript($script) ?: [];
}
/**
* {@inheritdoc}
*/
protected function getHtmlOutputHeaders() {
// The webdriver API does not support fetching headers.
return '';
}
}