Skip to content

Instantly share code, notes, and snippets.

@rosshinkley
Last active July 22, 2016 18:14
Show Gist options
  • Select an option

  • Save rosshinkley/c1873d40e17dd433cc2d to your computer and use it in GitHub Desktop.

Select an option

Save rosshinkley/c1873d40e17dd433cc2d to your computer and use it in GitHub Desktop.

Revisions

  1. rosshinkley revised this gist Nov 24, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions nightmare-multiple-downloads.js
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,7 @@ function *start() {
    .click('a[data="153"]')
    .click('a[data="48"]')
    .click('a[data="55"]')
    .wait(3000);

    while(counter > 0){
    yield nightmare.wait(1000);
  2. rosshinkley created this gist Nov 24, 2015.
    39 changes: 39 additions & 0 deletions nightmare-multiple-downloads.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    var Nightmare = require('nightmare'),
    vo = require('vo');

    function *start() {
    var nightmare = new Nightmare({
    show: true,
    'download-preferences': {
    destination: require('path').resolve(__dirname, 'downloads')
    }
    });

    var counter = 0;
    nightmare.on('download-start', function(download){
    console.log('download start: ' + JSON.stringify(download,null,3));
    counter++;
    });

    nightmare.on('download-done', function(download){
    console.log('download end: ' + JSON.stringify(download, null, 3));
    counter--;
    });

    var dl = yield nightmare.goto('http://www.sample-videos.com')
    .click('a[data="153"]')
    .click('a[data="48"]')
    .click('a[data="55"]')

    while(counter > 0){
    yield nightmare.wait(1000);
    }

    console.log('all files downloaded');
    yield nightmare.end();
    }

    vo(start)(function() {
    console.log('done');
    });