簡體   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