2016-08-02 17 views
0
私はを使用してスクリプトを作成してい

、私のスクリプトのステップは必需品は以下のとおりです。ナイトメアの状態に応じて何かするには?

  1. オープン

  2. チェックが

  3. ログインがログに記録されていないクッキーでログインしているページ

  4. 残りのすべての作業を行う

このようなコード:

nightmare 
    .goto(url) 
    .cookies.get('cookie_key') 
    .then(cookie => { 

    }) 
    ; 

前に、ログに記録されていない場合、私は悪夢のログインに作ることができる方法必要なタスクの残りの部分を実行しますか?

+1

あなたの 'then()'に 'if'文を置くことはできませんか? – 4castle

答えて

1

@ 4castleは正しいです:.then()に直接ifブロックを置くことができます。たとえば:

nightmare 
    .goto(url) 
    .cookies.get('cookie_key') 
    .then(cookie => { 
    if(cookie){ 
     //perform your login action 
     return nightmare 
     .type('#username', username) 
     .type('#password', password) 
    } else { 
     //if you need to perform other logic 
     //if you're already logged in, do it here 
     //otherwise, this `else` can be omitted 
    } 
    }) 
    .then(()=>{ 
    return nightmare 
     .action() 
     .action() 
     //etc. 
    }) 

さらに読書のために、あなたはnightmare-examplesRunning Multiple Stepsを見てしたい場合があります。

関連する問題