Skip to content

Instantly share code, notes, and snippets.

@MikaelSoderstrom
Last active July 17, 2025 02:58
Show Gist options
  • Save MikaelSoderstrom/4842a97ec399aae1e024 to your computer and use it in GitHub Desktop.
Save MikaelSoderstrom/4842a97ec399aae1e024 to your computer and use it in GitHub Desktop.

Revisions

  1. MikaelSoderstrom renamed this gist Oct 19, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. MikaelSoderstrom created this gist Oct 19, 2014.
    58 changes: 58 additions & 0 deletions Nightmare-demo
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    var path = require('path');
    var Nightmare = require('nightmare');
    var should = require('chai').should();

    describe('Nightmare demo', function () {
    this.timeout(15000); // Set timeout to 15 seconds, instead of the original 2 seconds

    var url = 'http://localhost:3000';

    describe('Start page', function () {
    it('should show form when loaded', function (done) {
    new Nightmare()
    .goto(url)
    .evaluate(function () {
    return document.querySelectorAll('form').length;
    }, function (result) {
    result.should.equal(1);
    done();
    })
    .run();
    });
    });

    describe('Send form', function () {
    it('should print the posted string on submit', function (done) {
    var expected = 'Hello, world!';

    new Nightmare()
    .goto(url)
    .type('input[name="sometext"]', expected)
    .click('input[type="submit"]')
    .wait()
    .evaluate(function () {
    return document.querySelector('#result');
    }, function (element) {
    element.innerText.should.equal(expected);
    done();
    })
    .run();
    });

    it('should print "nothing" on submit if no string were provided', function (done) {
    var expected = 'nothing';

    new Nightmare()
    .goto(url)
    .click('input[type="submit"]')
    .wait()
    .evaluate(function () {
    return document.querySelector('#result');
    }, function (element) {
    element.innerText.should.equal(expected);
    done();
    })
    .run();
    });
    });
    });