<commit_before>/*global describe:true, it:true, before:true, after:true */
"use strict";

var yiewd = require('../lib/yiewd.js')
  , Express = require('../node_modules/wd/test/common/express.js').Express
  , _ = require('underscore')
  , should = require('should')
  , baseUrl = 'http://127.0.0.1:8181/'
  , monocle = require("monocle.js")
  , o0 = monocle.o0
  , run = monocle.run
  , caps = { browserName: 'chrome' };

describe('yiewd', function() {
  // handle running test server
  var server = new Express();
  var driver = null;
  var handles = [];
  before(function(done) {
    server.start();
    done();
  });
  after(function(done) {
    server.stop();
    done();
  });

  it('should start a session', function(done) {
    run(function*() {
      var d = yiewd.remote();
      driver = d;
      yield driver.init(caps);
      done();
    });
  });

  it('should get session status', function(done) {
    run(function*() {
      var status = yield driver.status();
      should.exist(status.build);
      done();
    });
  });

  it('should get list of sessions', function(done) {
    run(function*() {
      var sessions = yield driver.sessions();
      sessions.length.should.be.above(0);
      should.exist(sessions[0].id);
      done();
    });
  });

  it('should get session caps', function(done) {
    run(function*() {
      var sessionCaps = yield driver.sessionCapabilities();
      should.exist(sessionCaps.browserName);
      sessionCaps.browserName.should.equal('chrome');
      done();
    });
  });

  it('should get a url, page title, and window handle', function(done) {
    run(function*() {
      var testPage = baseUrl + 'test-page.html';
      yield driver.get(testPage);
      var title = yield driver.title();
      title.should.equal("TEST PAGE");
      var handle = yield driver.windowHandle();
      handle.length.should.be.above(0);
      handles['window-1'] = handle;
      done();
    });
  });

  it('should open a new window', function(done) {
    var newWindow = baseUrl + 'window-test-page.html?window_num=2';
    run(function*() {
      yield driver.newWindow(newWindow, 'window-2');
      done();
    });
  });

  it('should switch to a window', function(done) {
    run(function*() {
      yield driver.window("window-2");
      done();
    });
  });

  it('should get the window name', function(done) {
    run(function*() {
      var name = yield driver.windowName();
      name.should.equal("window-2");
      var handle = yield driver.windowHandle();
      handle.length.should.be.above(0);
      handle.should.not.eql(handles['window-1']);
      handles['window-2'] = handle;
      done();
    });
  });

  it('should get window handles', function(done) {
    run(function*() {
      var wdHandles = yield driver.windowHandles();
      _.each(handles, function(handle, handleId) {
        wdHandles.should.include(handle);
      });
      done();
    });
  });

  it('should sleep', function(done) {
    run(function*() {
      var begin = Date.now();
      yield driver.sleep(0.5);
      var end = Date.now();
      (end - begin).should.be.above(499);
      done();
    });
  });
<commit_msg>add a test for error handling<commit_after>/*global describe:true, it:true, before:true, after:true */
"use strict";

var yiewd = require('../lib/yiewd.js')
  , Express = require('../node_modules/wd/test/common/express.js').Express
  , _ = require('underscore')
  , should = require('should')
  , baseUrl = 'http://127.0.0.1:8181/'
  , monocle = require("monocle.js")
  , o0 = monocle.o0
  , run = monocle.run
  , caps = { browserName: 'chrome' };

describe('yiewd', function() {
  // handle running test server
  var server = new Express();
  var driver = null;
  var handles = [];
  before(function(done) {
    server.start();
    done();
  });
  after(function(done) {
    server.stop();
    done();
  });

  it('should start a session', function(done) {
    run(function*() {
      var d = yiewd.remote();
      driver = d;
      yield driver.init(caps);
      done();
    });
  });

  it('should get session status', function(done) {
    run(function*() {
      var status = yield driver.status();
      should.exist(status.build);
      done();
    });
  });

  it('should get list of sessions', function(done) {
    run(function*() {
      var sessions = yield driver.sessions();
      sessions.length.should.be.above(0);
      should.exist(sessions[0].id);
      done();
    });
  });

  it('should get session caps', function(done) {
    run(function*() {
      var sessionCaps = yield driver.sessionCapabilities();
      should.exist(sessionCaps.browserName);
      sessionCaps.browserName.should.equal('chrome');
      done();
    });
  });

  it('should get a url, page title, and window handle', function(done) {
    run(function*() {
      var testPage = baseUrl + 'test-page.html';
      yield driver.get(testPage);
      var title = yield driver.title();
      title.should.equal("TEST PAGE");
      var handle = yield driver.windowHandle();
      handle.length.should.be.above(0);
      handles['window-1'] = handle;
      done();
    });
  });

  it('should open a new window', function(done) {
    var newWindow = baseUrl + 'window-test-page.html?window_num=2';
    run(function*() {
      yield driver.newWindow(newWindow, 'window-2');
      done();
    });
  });

  it('should switch to a window', function(done) {
    run(function*() {
      yield driver.window("window-2");
      done();
    });
  });

  it('should get the window name', function(done) {
    run(function*() {
      var name = yield driver.windowName();
      name.should.equal("window-2");
      var handle = yield driver.windowHandle();
      handle.length.should.be.above(0);
      handle.should.not.eql(handles['window-1']);
      handles['window-2'] = handle;
      done();
    });
  });

  it('should get window handles', function(done) {
    run(function*() {
      var wdHandles = yield driver.windowHandles();
      _.each(handles, function(handle, handleId) {
        wdHandles.should.include(handle);
      });
      done();
    });
  });

  it('should handle wd errors', function(done) {
    driver.run(function*() {
      var err;
      try {
        var text = yield this.alertText();
      } catch(e) {
        err = e;
      }
      should.exist(err);
      err.message.should.include('27');
      done();
    });
  });

  it('should sleep', function(done) {
    run(function*() {
      var begin = Date.now();
      yield driver.sleep(0.5);
      var end = Date.now();
      (end - begin).should.be.above(499);
      done();
    });
  });

{'fraction_non_alphanumeric': 0.17663125948406677, 'fraction_numerical': 0.008801213960546282, 'mean_word_length': 2.6739130434782608, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3894959', 'n_tokens_mistral': 2148, 'n_tokens_neox': 2105, 'n_words': 438}