Как передать переменную, определенную определенной командой, в другую внешнюю команду (в тесте) в nightwatch - PullRequest
0 голосов
/ 31 мая 2018

У меня есть пользовательская команда: initialCount.js

module.exports = {
    command: function () {
        this
            .getText('.header-mini-cart-menu-cart-legend', function (result) {
                cartCountInitial = Number(result.value); <--- I want this output into some other command.
                console.log(cartCountInitial); <---- Prints the count in number.
                return cartCountInitial;  <--- I want this output into some other command
            });
    }

Я хочу использовать значение в условии IF, которое находится в другом файле (в тестовом примере).

контрольный примеримя файла: addToCartFromTile.test.js

var initialCartCount = require('../../../commands/shopping/cart/initialCartCount');

module.exports= {
    'Determining whether the product is MATRIX or NON-MATRIX': client => {
        client
            .url(client.launchUrl)
            .getLocationInView(noOfSliders)
            .execute(function () {
                  var cartCount = document.querySelector('.header-mini-cart-menu-cart-legend').innerText;
                  return cartCount;
             },[],function(res){
                     var cartCount1 = Number(res.value);


                     if (initialCartCount.command == cartCount1) { <---- "initialCartCount.command" returns me {command: [Function: command]}.

                     }

«initialCartCount.command» в условии IF, возвращает меня {команда: [Функция: команда]} ,Как получить значение переменной.

Есть ли взлом или подход неправильный.Если мой подход неверен, то, пожалуйста, предложите, как мне этого добиться?

1 Ответ

0 голосов
/ 04 июня 2018

Я сам придумал решение.

module.exports= {
    'Determining whether the product is MATRIX or NON-MATRIX': client => {
        client
            .url(client.launchUrl)
            .getLocationInView(noOfSliders)
            .initialCount()  <============ Called the external command.
   ===>>    .perform(function(done){  <=== Extending the scope of external command.

                        var abc = cartCountInitial; <=== Got the value
                        console.log('Perform', abc);

                 .execute(function () {
                  var cartCount = document.querySelector('.header-mini-cart-menu-cart-legend').innerText;
                  return cartCount;
             },[],function(res){
                     var cartCount1 = Number(res.value);


                     if (abc == cartCount1) { <=== Matched :)

                     }
             })
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...