0

Selectors when passed using @ notation from the test function to the page object are not working.

Here's my homepage object.

module.exports = {

    url: function () {
        return this.api.launchUrl;
    },

    elements: {
        dropdownSelector: {
            selector: '#input-13',
            locateStrategy: 'css selector'
        },
        dropdownAuthSelector: {
            selector: '#list-item-18-5 > span > span.ml-1',
            locateStrategy: 'css selector'
        },
    },

    commands: [{

        setDropdown(selector, value) {
            let { selectDropdown } = require('../modules/Utils.js');
            selectDropdown(this.api, selector, value);
            return this;
        }

    }]

};

Utils.js

module.exports.selectDropdown = function (self,selector,value) {

    return self.click(selector).click(value);


}

Test js file.

module.exports = {

    '@tags': ['home'],

    'Dashboard Dropdown test'(browser) {
        const homePage = browser.page.homepage();
        homePage
            .navigate()
            //.setDropdown(homePage.elements.dropdownSelector.selector, homePage.elements.dropdownAuthSelector.selector)
            .setDropdown('@dropdownSelector', '@dropdownAuthSelector')
            .assert.urlContains('Authentication').end();
    }

};

So basically setDropdown(homePage.elements.dropdownSelector.selector, homePage.elements.dropdownAuthSelector.selector) Works fine, but when I use @ notation it doesn't work .setDropdown('@dropdownSelector', '@dropdownAuthSelector') and throws below error

Error Error while running .locateMultipleElements() protocol action: invalid selector: An invalid or illegal selector was specified

Error while running .locateMultipleElements() protocol action: invalid selector: An invalid or illegal selector was specified

Tajinder Singh
  • 205
  • 1
  • 5
  • 12

1 Answers1

0

I don't think they can be access directly thru @ due to the queueing behavior of nightwatch. Page object commands are not autoadded to the main queue. Also, why not define custom command HomePage page object, where you can access them directly and then just invoke that command in test?

Sj Pietel
  • 1
  • 1