Skip to content

Nightwatch integration! #141

Open
Open
@awatson1978

Description

@awatson1978

Hi! Just saw the post by @samcorcos on forms.meteor.com about Gagarin.js testing, and I was excited to see another mocha based test solution in the ecosystem.

So, 6 months ago, I approached Andrei over at Nightwatch, and asked about Mocha integration, and about 2 months ago he was able to finally get it working. I had initially expected that he would encapsulate the Mocha describe/it syntax into Nightwatch; but instead, he managed to adjust Nightwatch so it could be run within Mocha.

At first, this was a bit perplexing, but it seems to have been a smart choice, because I think we might be able to simply require Nightwatch in the Gagarin test script, and get all of Nightwatch's extensive UI testing API.

Anyhow, long story short, Andrei has provided the following code example of running Nightwatch within Mocha.

var nightwatch = require('nightwatch');

describe('Github', function() {
  var client = nightwatch.initClient({
    silent : true
  });

  var browser = client.api();

  this.timeout(99999999);

  before(function() {

    browser.perform(function() {
      console.log('beforeAll')
    });

  });

  beforeEach(function(done) {
    browser.perform(function() {
      console.log('beforeEach')
    });

    client.start(done);
  });


  it('Demo test GitHub', function (done) {
    browser
      .url('https://github.com/nightwatchjs/nightwatch')
      .waitForElementVisible('body', 5000)
      .assert.title('nightwatchjs/nightwatch · GitHub')
      .waitForElementVisible('body', 1000)
      .assert.visible('.container .breadcrumb a span')
      .assert.containsText('.container .breadcrumb a span', 'nightwatch', 'Checking project title is set to nightwatch');

    client.start(done);
  });

  afterEach(function() {
    browser.perform(function() {
      console.log('afterEach')
    });
  });

  after(function(done) {
    browser.end(function() {
      console.log('afterAll')
    });

    client.start(done);
  });

});

Could we do the same thing with Gagarin? Put a var nightwatch = require('nightwatch'); at the top of the test script, and import Nightwatch's higher-level UI testing API?

I think we may have been working towards the same goal, from different directions.

More information here
http://nightwatchjs.org/guide#using-mocha

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions