繁体   English   中英

如何将变量定义的某些命令传递给夜视仪中的其他外部命令(在测试中)

[英]How to pass on variable defined certain command, into some other external command(in the test) in nightwatch

我有一个自定义命令: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]}.

                     }

在IF条件下,“ initialCartCount.command”向我返回{command:[Function:command]} 如何获得变量值。

是否有破解或方法错误。 如果我的方法是错误的,那么请建议我该如何实现?

我自己提出了一个解决方案。

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 :)

                     }
             })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM