2017-01-04 5 views
3
//gives count of downloads in download folder. 

    this.getCountOfDownloads = function (fileName,elementToClick) { 

     //provides a way to look for filenames matching a certain pattern (in the worst case, you can wait for the *.* - basically, any file to appear) 
     var glob = require("glob"); 
     var filesArray = glob.sync("./src/test/javascript/e2e/downloads/"+"*.xlsx"); 

     console.log("sizee",filesArray.length); 

     browser.driver.wait(function() { 
      elementToClick.click();//to download 

      if (typeof filesArray !== 'undefined' && filesArray.length > 0) { 
       // this check is necessary because `glob.sync` can return 
       // an empty list, which will be considered as a valid output 
       // making the wait to end. 

       return filesArray; 
      } 
     }, 4444).then(function (filesArray) { 
      console.log("sizee",filesArray[0]); 



      // now we have the filename and can do whatever we want 
     }); 
     browser.sleep(5555); console.log("sizee",filesArray.length); 
    }; 

elemtclickファイルをダウンロードしてください。私が最初にそれが空である時に同期ボタン分度器はダウンロードしたばかりのファイルを見ることができません。

をクリックしたときに

私はinteljで見ることができます。それから私はこれを実行し、両方のコンソール出力で0としてサイズを表示します。その後、次回の実行では、以前にダウンロードされたファイルであるため、1になります。

filesarray> 0が真になっていません。

elementclickの後にbrowsersleepを入れましたが、まだファイルを待っていないか、または同期していません。私は何をしたいか

は私がCURRENTCOUNT-1

=私は数える期待affer

  • をダウンロードカウントを取得
  • 操作する前に、ダウンロードの数を取得

    • ですしかしそれはファイルを見ることができません:(、 私はセッションをリフレッシュする必要があると思うが、おそらくそこにnotherの方法です

  • +0

    私はあなたが非同期の問題に遭遇していると思います。 console.log()はbrowser.sleepを待機しません。それは即座に起こります。 –

    答えて

    0

    私はあなたが非同期の問題に走っていると思います。 console.log()はbrowser.sleepを待機しません。それは即座に起こります。 glob.syncをもう一度呼び出す必要があると思いますが、そのコードはわかりません。

    //gives count of downloads in download folder. 
    
    this.getCountOfDownloads = function (fileName,elementToClick) { 
    
        //provides a way to look for filenames matching a certain pattern (in the worst case, you can wait for the *.* - basically, any file to appear) 
        var glob = require("glob"); 
        var filesArray = glob.sync("./src/test/javascript/e2e/downloads/"+"*.xlsx"); 
    
        console.log("sizee",filesArray.length); 
    
        browser.driver.wait(function() { 
        elementToClick.click();//to download 
        browser.sleep(5555); 
        filesArray = glob.sync("./src/test/javascript/e2e/downloads/"+"*.xlsx"); 
        console.log("sizee",filesArray.length); 
    
        if (typeof filesArray !== 'undefined' && filesArray.length > 0) { 
         // this check is necessary because `glob.sync` can return 
         // an empty list, which will be considered as a valid output 
         // making the wait to end. 
    
         return filesArray.length; 
        } 
        }, 4444).then(function (filesArray) { 
        console.log("sizee",filesArray[0]); 
        // now we have the filename and can do whatever we want 
        }); 
    }; 
    
    関連する問題