Unverified Commit 5b0f126b authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3265617 by nod_, longwave: Update Nightwatch to 2.x

parent 6572d37a
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -26,21 +26,21 @@ module.exports = {
          'administer users',
        ],
      })
      .drupalLogin({ name: 'user', password: '123' })
      .drupalRelativeURL('/')
      .waitForElementPresent('#toolbar-administration', 10000);
      .drupalLogin({ name: 'user', password: '123' });
  },
  beforeEach(browser) {
    // Set the resolution to the default desktop resolution. Ensure the default
    // toolbar is horizontal in headless mode.
    browser.resizeWindow(1920, 1080);
    browser
      .setWindowSize(1920, 1080)
      // To clear active tab/tray from previous tests
    browser.execute(function () {
      .execute(function () {
        localStorage.clear();
        // Clear escapeAdmin url values.
        sessionStorage.clear();
    });
    browser.drupalRelativeURL('/');
      })
      .drupalRelativeURL('/')
      .waitForElementPresent('#toolbar-administration', 50000, 1000, false);
  },
  after(browser) {
    browser.drupalUninstall();
+57 −55
Original line number Diff line number Diff line
@@ -34,44 +34,46 @@ module.exports = {
          'administer users',
        ],
      })
      .drupalLogin({ name: 'user', password: '123' })
      .drupalRelativeURL('/')
      .waitForElementPresent('#toolbar-administration', 10000);
      .drupalLogin({ name: 'user', password: '123' });
  },
  beforeEach(browser) {
    browser.resizeWindow(1920, 1080);
    browser.execute(function () {
      // To clear active tab/tray from previous tests.
    // Set the resolution to the default desktop resolution. Ensure the default
    // toolbar is horizontal in headless mode.
    browser
      .setWindowSize(1920, 1080)
      // To clear active tab/tray from previous tests
      .execute(function () {
        localStorage.clear();
      // Clear escapeAdmin URL values.
        // Clear escapeAdmin url values.
        sessionStorage.clear();
    });
    browser.drupalRelativeURL('/');
      })
      .drupalRelativeURL('/')
      .waitForElementPresent('#toolbar-administration');
  },
  after(browser) {
    browser.drupalUninstall();
  },
  'Change tab': (browser) => {
    browser.waitForElementPresent(itemUserTray);
    browser.assert.not.cssClassPresent(itemUser, 'is-active');
    browser.assert.not.cssClassPresent(itemUserTray, 'is-active');
    browser.assert.not.hasClass(itemUser, 'is-active');
    browser.assert.not.hasClass(itemUserTray, 'is-active');
    browser.click(itemUser);
    browser.assert.cssClassPresent(itemUser, 'is-active');
    browser.assert.cssClassPresent(itemUserTray, 'is-active');
    browser.assert.hasClass(itemUser, 'is-active');
    browser.assert.hasClass(itemUserTray, 'is-active');
  },
  'Change orientation': (browser) => {
    browser.waitForElementPresent(adminOrientationButton);
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      itemAdministrationTray,
      'is-active toolbar-tray-horizontal',
    );
    browser.click(adminOrientationButton);
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      itemAdministrationTray,
      'is-active toolbar-tray-vertical',
    );
    browser.click(adminOrientationButton);
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      itemAdministrationTray,
      'is-active toolbar-tray-horizontal',
    );
@@ -79,40 +81,40 @@ module.exports = {
  'Toggle tray': (browser) => {
    browser.waitForElementPresent(itemUserTray);
    browser.click(itemUser);
    browser.assert.cssClassPresent(itemUserTray, 'is-active');
    browser.assert.hasClass(itemUserTray, 'is-active');
    browser.click(itemUser);
    browser.assert.not.cssClassPresent(itemUserTray, 'is-active');
    browser.assert.not.hasClass(itemUserTray, 'is-active');
    browser.click(itemUser);
    browser.assert.cssClassPresent(itemUserTray, 'is-active');
    browser.assert.hasClass(itemUserTray, 'is-active');
  },
  'Toggle submenu and sub-submenu': (browser) => {
    browser.waitForElementPresent(adminOrientationButton);
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      itemAdministrationTray,
      'is-active toolbar-tray-horizontal',
    );
    browser.click(adminOrientationButton);
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      itemAdministrationTray,
      'is-active toolbar-tray-vertical',
    );
    browser.waitForElementPresent(
      '#toolbar-item-administration-tray li:nth-child(4) button',
    );
    browser.assert.not.cssClassPresent(
    browser.assert.not.hasClass(
      '#toolbar-item-administration-tray li:nth-child(4)',
      'open',
    );
    browser.assert.not.cssClassPresent(
    browser.assert.not.hasClass(
      '#toolbar-item-administration-tray li:nth-child(4) button',
      'open',
    );
    browser.click('#toolbar-item-administration-tray li:nth-child(4) button');
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      '#toolbar-item-administration-tray li:nth-child(4)',
      'open',
    );
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      '#toolbar-item-administration-tray li:nth-child(4) button',
      'open',
    );
@@ -126,22 +128,22 @@ module.exports = {
    browser.waitForElementPresent(
      '#toolbar-item-administration-tray li.menu-item.level-2',
    );
    browser.assert.not.cssClassPresent(
    browser.assert.not.hasClass(
      '#toolbar-item-administration-tray li.menu-item.level-2',
      'open',
    );
    browser.assert.not.cssClassPresent(
    browser.assert.not.hasClass(
      '#toolbar-item-administration-tray li.menu-item.level-2 button',
      'open',
    );
    browser.click(
      '#toolbar-item-administration-tray li.menu-item.level-2 button',
    );
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      '#toolbar-item-administration-tray li.menu-item.level-2',
      'open',
    );
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      '#toolbar-item-administration-tray li.menu-item.level-2 button',
      'open',
    );
@@ -151,36 +153,36 @@ module.exports = {
  },
  'Narrow toolbar width breakpoint': (browser) => {
    browser.waitForElementPresent(adminOrientationButton);
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      itemAdministrationTray,
      'is-active toolbar-tray-horizontal',
    );
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      '#toolbar-administration',
      'toolbar-oriented',
    );
    browser.resizeWindow(263, 900);
    browser.assert.cssClassPresent(
    browser.setWindowSize(263, 900);
    browser.assert.hasClass(
      itemAdministrationTray,
      'is-active toolbar-tray-vertical',
    );
    browser.assert.not.cssClassPresent(itemAdministration, 'toolbar-oriented');
    browser.assert.not.hasClass(itemAdministration, 'toolbar-oriented');
  },
  'Standard width toolbar breakpoint': (browser) => {
    browser.resizeWindow(1000, 900);
    browser.setWindowSize(1000, 900);
    browser.waitForElementPresent(adminOrientationButton);
    browser.assert.cssClassPresent('body', 'toolbar-fixed');
    browser.resizeWindow(609, 900);
    browser.assert.cssClassPresent(
    browser.assert.hasClass('body', 'toolbar-fixed');
    browser.setWindowSize(609, 900);
    browser.assert.hasClass(
      itemAdministrationTray,
      'is-active toolbar-tray-vertical',
    );
    browser.assert.not.cssClassPresent('body', 'toolbar-fixed');
    browser.assert.not.hasClass('body', 'toolbar-fixed');
  },
  'Wide toolbar breakpoint': (browser) => {
    browser.waitForElementPresent(adminOrientationButton);
    browser.resizeWindow(975, 900);
    browser.assert.cssClassPresent(
    browser.setWindowSize(975, 900);
    browser.assert.hasClass(
      itemAdministrationTray,
      'is-active toolbar-tray-vertical',
    );
@@ -314,12 +316,12 @@ module.exports = {
    );
  },
  'Locked toolbar vertical wide viewport': (browser) => {
    browser.resizeWindow(1000, 900);
    browser.setWindowSize(1000, 900);
    browser.waitForElementPresent(adminOrientationButton);
    // eslint-disable-next-line no-unused-expressions
    browser.expect.element(adminOrientationButton).to.be.visible;
    browser.resizeWindow(975, 900);
    browser.assert.cssClassPresent(
    browser.setWindowSize(975, 900);
    browser.assert.hasClass(
      itemAdministrationTray,
      'is-active toolbar-tray-vertical',
    );
@@ -329,34 +331,34 @@ module.exports = {
  'Settings are retained on refresh': (browser) => {
    browser.waitForElementPresent(itemUser);
    // Set user as active tab.
    browser.assert.not.cssClassPresent(itemUser, 'is-active');
    browser.assert.not.cssClassPresent(itemUserTray, 'is-active');
    browser.assert.not.hasClass(itemUser, 'is-active');
    browser.assert.not.hasClass(itemUserTray, 'is-active');
    browser.click(itemUser);
    // Check tab and tray are open.
    browser.assert.cssClassPresent(itemUser, 'is-active');
    browser.assert.cssClassPresent(itemUserTray, 'is-active');
    browser.assert.hasClass(itemUser, 'is-active');
    browser.assert.hasClass(itemUserTray, 'is-active');
    // Set orientation to vertical.
    browser.waitForElementPresent(userOrientationBtn);
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      itemUserTray,
      'is-active toolbar-tray-horizontal',
    );
    browser.click(userOrientationBtn);
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      itemUserTray,
      'is-active toolbar-tray-vertical',
    );
    browser.refresh();
    // Check user tab is active.
    browser.assert.cssClassPresent(itemUser, 'is-active');
    browser.assert.hasClass(itemUser, 'is-active');
    // Check tray is active and orientation is vertical.
    browser.assert.cssClassPresent(
    browser.assert.hasClass(
      itemUserTray,
      'is-active toolbar-tray-vertical',
    );
  },
  'Check toolbar overlap with page content': (browser) => {
    browser.assert.cssClassPresent('body', 'toolbar-horizontal');
    browser.assert.hasClass('body', 'toolbar-horizontal');
    browser.execute(
      () => {
        const toolbar = document.querySelector('#toolbar-administration');
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@
    "loadjs": "^4.2.0",
    "minimist": "^1.2.2",
    "mkdirp": "^1.0.4",
    "nightwatch": "^1.6.3",
    "nightwatch": "^2.1.3",
    "normalize.css": "^8.0.1",
    "picturefill": "^3.0.3",
    "postcss": "^7.0.18",
+18 −29
Original line number Diff line number Diff line
@@ -20,40 +20,29 @@ exports.command = function drupalCreateRole(
  const roleName = name || Math.random().toString(36).substring(2, 15);

  let machineName;
  this.drupalLoginAsAdmin(() => {
    this.drupalRelativeURL('/admin/people/roles/add')
      .setValue('input[name="label"]', roleName)
  this.drupalLoginAsAdmin(async () => {
    this.drupalRelativeURL('/admin/people/roles/add');

    this.setValue('input[name="label"]', roleName)
      // Wait for the machine name to appear so that it can be used later to
      // select the permissions from the permission page.
      .expect.element('.user-role-form .machine-name-value')
      .to.be.visible.before(2000);

    this.perform((done) => {
      this.getText('.user-role-form .machine-name-value', (element) => {
        machineName = element.value;
        done();
      });
    })
      .submitForm('#user-role-form')
      .drupalRelativeURL('/admin/people/permissions')
      .perform((client, done) => {
        Promise.all(
          permissions.map(
            (permission) =>
              new Promise((resolve) => {
                client.click(
                  `input[name="${machineName}[${permission}]"]`,
                  () => {
                    resolve();
                  },
                );
              }),
    machineName = await this.getText('.user-role-form .machine-name-value');
    this.submitForm('#user-role-form').waitForElementVisible('body');

    this.drupalRelativeURL('/admin/people/permissions');

    await Promise.all(
      permissions.map(async (permission) =>
        this.click(`input[name="${machineName}[${permission}]"]`),
      ),
        ).then(() => {
          done();
        });
      })
      .submitForm('#user-admin-permissions');
    );

    this.submitForm('#user-admin-permissions').waitForElementVisible('body');

    this.drupalRelativeURL('/admin/people/permissions');
  }).perform(() => {
    if (typeof callback === 'function') {
      callback.call(self, machineName);
+12 −12
Original line number Diff line number Diff line
@@ -20,24 +20,24 @@ exports.command = function drupalCreateUser(
) {
  const self = this;

  let role;
  // Define the name here because the callback from drupalCreateRole can be
  // undefined in some cases.
  const roleName = Math.random()
    .toString(36)
    .replace(/[^\w\d]/g, '')
    .substring(2, 15);
  this.perform((client, done) => {
    if (permissions) {
      client.drupalCreateRole({ permissions, name: null }, (newRole) => {
        role = newRole;
        done();
      });
    } else {
      done();
    if (permissions.length) {
      this.drupalCreateRole({ permissions, name: roleName }, done);
    }
  }).drupalLoginAsAdmin(() => {
  }).drupalLoginAsAdmin(async () => {
    this.drupalRelativeURL('/admin/people/create')
      .setValue('input[name="name"]', name)
      .setValue('input[name="pass[pass1]"]', password)
      .setValue('input[name="pass[pass2]"]', password)
      .perform((client, done) => {
        if (role) {
          client.click(`input[name="roles[${role}]`, () => {
        if (permissions.length) {
          client.click(`input[name="roles[${roleName}]`, () => {
            done();
          });
        } else {
@@ -45,7 +45,7 @@ exports.command = function drupalCreateUser(
        }
      })
      .submitForm('#user-register-form')
      .assert.containsText(
      .assert.textContains(
        '[data-drupal-messages]',
        'Created a new user account',
        `User "${name}" was created successfully.`,
Loading