diff --git a/test/macaca-wd.test.js b/test/browser.test.js similarity index 94% rename from test/macaca-wd.test.js rename to test/browser.test.js index 6bda8422..495fd55e 100644 --- a/test/macaca-wd.test.js +++ b/test/browser.test.js @@ -6,7 +6,7 @@ const { Server } = require('./helper'); const wd = require('../lib/macaca-wd'); -describe('test/macaca-wd.test.js', function() { +describe('test/browser.test.js', function() { let driver, server; before(() => { server = new Server(); diff --git a/test/session.test.js b/test/session.test.js new file mode 100644 index 00000000..003ddc00 --- /dev/null +++ b/test/session.test.js @@ -0,0 +1,103 @@ +'use strict'; + +const assert = require('assert'); + +const { Server } = require('./helper'); + +const wd = require('../lib/macaca-wd'); + +describe('test/session.test.js', function() { + let driver, server; + before(() => { + server = new Server(); + server.start(); + const remoteConfig = { + host: 'localhost', + port: 3456 + }; + + driver = wd.promiseChainRemote(remoteConfig); + driver.configureHttp({ + timeout: 20 * 1000, + retries: 5, + retryDelay: 5 + }); + }); + + after(() => { + server.stop(); + }); + + /** + * https://macacajs.github.io/macaca-wd/#init + */ + describe('init', async () => { + it('should work', async () => { + await driver.init({ + platformName: 'desktop', + browserName: 'chrome' + }); + assert.equal(server.ctx.method, 'POST'); + assert.equal(server.ctx.url, '/wd/hub/session'); + assert.deepEqual(server.ctx.request.body, { + desiredCapabilities: { + platformName: 'desktop', + browserName: 'chrome', + version: '', + javascriptEnabled: true, + platform: 'ANY', + }, + }); + assert.deepEqual(server.ctx.response.body, { + sessionId: 'sessionId', + status: 0, + value: '', + }); + }); + }); + + /** + * https://macacajs.github.io/macaca-wd/#quit + */ + describe('quit', async () => { + beforeEach(async () => { + await driver.init({ + platformName: 'desktop', + browserName: 'chrome' + }); + }); + it('should work', async () => { + await driver.quit(); + assert.equal(server.ctx.method, 'DELETE'); + assert.equal(server.ctx.url, '/wd/hub/session/sessionId'); + assert.deepEqual(server.ctx.request.body, {}); + assert.deepEqual(server.ctx.response.body, { + sessionId: 'sessionId', + status: 0, + value: '', + }); + }); + }); + + /** + * https://macacajs.github.io/macaca-wd/#sessions + */ + describe('sessions', async () => { + beforeEach(async () => { + await driver.init({ + platformName: 'desktop', + browserName: 'chrome' + }); + }); + it('should work', async () => { + await driver.sessions(); + assert.equal(server.ctx.method, 'GET'); + assert.equal(server.ctx.url, '/wd/hub/sessions'); + assert.deepEqual(server.ctx.response.body, { + sessionId: 'sessionId', + status: 0, + value: '', + }); + }); + }); +}); diff --git a/test/helper.test.js b/test/utility.test.js similarity index 77% rename from test/helper.test.js rename to test/utility.test.js index b8d748b9..cd8db6be 100644 --- a/test/helper.test.js +++ b/test/utility.test.js @@ -4,7 +4,7 @@ const assert = require('assert'); const helper = require('../lib/helper'); -describe('test/helper.test.js', function() { +describe('test/utility.test.js', function() { it('should be ok', function() { assert.ok(helper); });