Skip to content

Commit

Permalink
test(assert): add suffix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paradite committed Apr 3, 2019
1 parent 91da61f commit c9e8e44
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ reports/
*.tgz
*.sw*
*.un~
package-lock.json
159 changes: 110 additions & 49 deletions test/assert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const assert = require('assert');

const { Server } = require('./helper');
const { elFuncFullType, elFuncSuffix } = require('../wd/lib/utils');

const wd = require('../lib/macaca-wd');

Expand All @@ -25,77 +26,137 @@ describe('test/asserter.test.js', function() {
});
};

afterEach(() => {
server.stop();
});

beforeEach(async () => {
await driver.init({
platformName: 'desktop',
browserName: 'chrome'
describe('single method tests', () => {
afterEach(() => {
server.stop();
});
});

/**
* https://macacajs.github.io/macaca-wd/#assertAttribute
*/
describe('assertAttribute', async () => {
before(async () => {
mockServer('ctx.body', {
sessionId: 'sessionId',
status: 0,
value: 'someClass'
beforeEach(async () => {
await driver.init({
platformName: 'desktop',
browserName: 'chrome'
});
});

it('should work', async () => {
await driver.assertAttribute('class', 'someClass');
assert.equal(server.ctx.url, '/wd/hub/session/sessionId/execute');
assert.equal(server.ctx.method, 'POST');
const { script, args } = server.ctx.request.body;
assert.equal(
script,
"return window.__macaca_current_element.getAttribute('class')"
);
assert.equal(args.length, 0);
/**
* https://macacajs.github.io/macaca-wd/#assertAttribute
*/
describe('assertAttribute', async () => {
before(async () => {
mockServer('ctx.body', {
sessionId: 'sessionId',
status: 0,
value: 'someClass'
});
});

it('should work', async () => {
await driver.assertAttribute('class', 'someClass');
assert.equal(server.ctx.url, '/wd/hub/session/sessionId/execute');
assert.equal(server.ctx.method, 'POST');
const { script, args } = server.ctx.request.body;
assert.equal(
script,
"return window.__macaca_current_element.getAttribute('class')"
);
assert.equal(args.length, 0);
});
});
});

/**
* https://macacajs.github.io/macaca-wd/#assertTitle
*/
describe('assertTitle', async () => {
before(async () => {
await mockServer('ctx.body', {
sessionId: 'sessionId',
status: 0,
value: 'My Title'
/**
* https://macacajs.github.io/macaca-wd/#assertTitle
*/
describe('assertTitle', async () => {
before(async () => {
await mockServer('ctx.body', {
sessionId: 'sessionId',
status: 0,
value: 'My Title'
});
});

it('should work', async () => {
await driver.assertTitle('My Title');
assert.equal(server.ctx.url, '/wd/hub/session/sessionId/title');
assert.equal(server.ctx.method, 'GET');
});
});

it('should work', async () => {
await driver.assertTitle('My Title');
assert.equal(server.ctx.url, '/wd/hub/session/sessionId/title');
assert.equal(server.ctx.method, 'GET');
/**
* https://macacajs.github.io/macaca-wd/#hasElement
*/
describe('hasElement', async () => {
before(async () => {
await mockServer('ctx.body', {
sessionId: 'sessionId',
status: 0,
value: [{ ELEMENT: 1 }, { ELEMENT: 2 }]
});
});

it('should work', async () => {
await driver.hasElement('class', 'myClass');
assert.equal(server.ctx.url, '/wd/hub/session/sessionId/elements');
assert.equal(server.ctx.method, 'POST');
const { using, value } = server.ctx.request.body;
assert.equal(using, 'class');
assert.equal(value, 'myClass');
});
});
});

/**
* https://macacajs.github.io/macaca-wd/#hasElement
* https://macacajs.github.io/macaca-wd/#hasElementByClassName
* https://macacajs.github.io/macaca-wd/#hasElementByCss
* https://macacajs.github.io/macaca-wd/#hasElementById
* https://macacajs.github.io/macaca-wd/#hasElementByName
* https://macacajs.github.io/macaca-wd/#hasElementByLinkText
* https://macacajs.github.io/macaca-wd/#hasElementByPartialLinkText
* https://macacajs.github.io/macaca-wd/#hasElementByTagName
* https://macacajs.github.io/macaca-wd/#hasElementByXPath
*/
describe('hasElement', async () => {
before(async () => {
describe('hasElement type suffix method tests', async () => {
afterEach(() => {
server.stop();
});

beforeEach(async () => {
await mockServer('ctx.body', {
sessionId: 'sessionId',
status: 0,
value: [{ ELEMENT: 1 }, { ELEMENT: 2 }]
});
await driver.init({
platformName: 'desktop',
browserName: 'chrome'
});
});

it('should work', async () => {
await driver.hasElement('class', 'myClass');
assert.equal(server.ctx.url, '/wd/hub/session/sessionId/elements');
assert.equal(server.ctx.method, 'POST');
const tests = [
'class name',
'css',
'id',
'link text',
'name',
'partial link text',
'tag name',
'xpath'
].map(type => {
return {
functionSuffix: `hasElement${elFuncSuffix(type)}`,
fullType: elFuncFullType(type)
};
});

tests.forEach(function(test) {
it(`${test.functionSuffix} should work`, async () => {
await driver[test.functionSuffix]('myValue');
assert.equal(server.ctx.url, '/wd/hub/session/sessionId/elements');
assert.equal(server.ctx.method, 'POST');
const { using, value } = server.ctx.request.body;
assert.equal(using, test.fullType);
assert.equal(value, 'myValue');
});
});
});
});

0 comments on commit c9e8e44

Please sign in to comment.