cybernaut
Version:
Reliable, zero configuration end-to-end testing in BDD-style.
178 lines • 9.54 kB
JavaScript
// tslint:disable no-any
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const proxyquire = require("proxyquire");
const ava_1 = require("ava");
const selenium_webdriver_1 = require("selenium-webdriver");
const sinon_1 = require("sinon");
const description_1 = require("../description");
const stubs_1 = require("./stubs");
proxyquire.noPreserveCache();
proxyquire.preserveCache();
proxyquire('../element', { './utils': { translate: stubs_1.elementStubs.translate } });
const element_1 = require("../element");
function createTestName(method, result) {
return `\`Element.${method}\` should return an ${result}`;
}
let element;
ava_1.default.beforeEach(() => {
stubs_1.resetAll(stubs_1.elementStubs);
element = new element_1.Element('selector');
});
ava_1.default(createTestName('tagName', 'accessor'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(5);
const accessor = element.tagName;
t.is(description_1.format(accessor.description), 'tag name of element \'selector\'');
const getTagName = sinon_1.stub().resolves('tagName');
const findElement = sinon_1.stub().resolves({ getTagName });
t.is(yield accessor.get({ findElement }), 'tagName');
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(getTagName.callCount, 1);
}));
ava_1.default(createTestName('text', 'accessor'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(5);
const accessor = element.text;
t.is(description_1.format(accessor.description), 'text of element \'selector\'');
const getText = sinon_1.stub().resolves('text');
const findElement = sinon_1.stub().resolves({ getText });
t.is(yield accessor.get({ findElement }), 'text');
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(getText.callCount, 1);
}));
ava_1.default(createTestName('visibility', 'accessor'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(5);
const accessor = element.visibility;
t.is(description_1.format(accessor.description), 'visibility of element \'selector\'');
const isDisplayed = sinon_1.stub().resolves(true);
const findElement = sinon_1.stub().resolves({ isDisplayed });
t.is(yield accessor.get({ findElement }), true);
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(isDisplayed.callCount, 1);
}));
ava_1.default(createTestName('x', 'accessor'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(5);
const accessor = element.x;
t.is(description_1.format(accessor.description), 'x-position of element \'selector\'');
const getLocation = sinon_1.stub().resolves({ x: 123, y: 456 });
const findElement = sinon_1.stub().resolves({ getLocation });
t.is(yield accessor.get({ findElement }), 123);
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(getLocation.callCount, 1);
}));
ava_1.default(createTestName('y', 'accessor'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(5);
const accessor = element.y;
t.is(description_1.format(accessor.description), 'y-position of element \'selector\'');
const getLocation = sinon_1.stub().resolves({ x: 123, y: 456 });
const findElement = sinon_1.stub().resolves({ getLocation });
t.is(yield accessor.get({ findElement }), 456);
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(getLocation.callCount, 1);
}));
ava_1.default(createTestName('width', 'accessor'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(5);
const accessor = element.width;
t.is(description_1.format(accessor.description), 'width of element \'selector\'');
const getSize = sinon_1.stub().resolves({ width: 123, height: 456 });
const findElement = sinon_1.stub().resolves({ getSize });
t.is(yield accessor.get({ findElement }), 123);
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(getSize.callCount, 1);
}));
ava_1.default(createTestName('height', 'accessor'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(5);
const accessor = element.height;
t.is(description_1.format(accessor.description), 'height of element \'selector\'');
const getSize = sinon_1.stub().resolves({ width: 123, height: 456 });
const findElement = sinon_1.stub().resolves({ getSize });
t.is(yield accessor.get({ findElement }), 456);
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(getSize.callCount, 1);
}));
ava_1.default(createTestName('cssValue', 'accessor'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(6);
const accessor = element.cssValue('cssName');
t.is(description_1.format(accessor.description), 'css value \'cssName\' of element \'selector\'');
const getCssValue = sinon_1.stub().resolves('cssValue');
const findElement = sinon_1.stub().resolves({ getCssValue });
t.is(yield accessor.get({ findElement }), 'cssValue');
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(getCssValue.callCount, 1);
t.is(getCssValue.args[0][0], 'cssName');
}));
ava_1.default(createTestName('propertyValue', 'accessor'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(6);
const accessor = element.propertyValue('propertyName');
t.is(description_1.format(accessor.description), 'property value \'propertyName\' of element \'selector\'');
const getAttribute = sinon_1.stub().resolves('attribute');
const findElement = sinon_1.stub().resolves({ getAttribute });
t.is(yield accessor.get({ findElement }), 'attribute');
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(getAttribute.callCount, 1);
t.is(getAttribute.args[0][0], 'propertyName');
}));
ava_1.default(createTestName('clearValue', 'action'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(5);
const action = element.clearValue();
t.is(description_1.format(action.description), 'clear value of element \'selector\'');
const clear = sinon_1.stub().rejects(new Error('foo'));
const findElement = sinon_1.stub().resolves({ clear });
yield t.throws(action.perform({ findElement }), 'foo');
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(clear.callCount, 1);
}));
ava_1.default(createTestName('click', 'action'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(5);
const action = element.click();
t.is(description_1.format(action.description), 'click on element \'selector\'');
const click = sinon_1.stub().rejects(new Error('foo'));
const findElement = sinon_1.stub().resolves({ click });
yield t.throws(action.perform({ findElement }), 'foo');
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(click.callCount, 1);
}));
ava_1.default(createTestName('sendKeys', 'action'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(12);
stubs_1.elementStubs.translate.onFirstCall().returns('Key.CONTROL');
stubs_1.elementStubs.translate.onSecondCall().returns('a');
stubs_1.elementStubs.translate.onThirdCall().returns('Key.NULL');
const action = element.sendKeys(selenium_webdriver_1.Key.CONTROL, 'a', selenium_webdriver_1.Key.NULL);
t.is(description_1.format(action.description), 'send keys [ \'Key.CONTROL\', \'a\', \'Key.NULL\' ] to element \'selector\'');
t.is(stubs_1.elementStubs.translate.callCount, 3);
t.is(stubs_1.elementStubs.translate.args[0][0], selenium_webdriver_1.Key.CONTROL);
t.is(stubs_1.elementStubs.translate.args[1][0], 'a');
t.is(stubs_1.elementStubs.translate.args[2][0], selenium_webdriver_1.Key.NULL);
const sendKeys = sinon_1.stub().rejects(new Error('foo'));
const findElement = sinon_1.stub().resolves({ sendKeys });
yield t.throws(action.perform({ findElement }), 'foo');
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(sendKeys.callCount, 1);
t.is(sendKeys.args[0][0], selenium_webdriver_1.Key.CONTROL);
t.is(sendKeys.args[0][1], 'a');
t.is(sendKeys.args[0][2], selenium_webdriver_1.Key.NULL);
}));
ava_1.default(createTestName('submitForm', 'action'), (t) => tslib_1.__awaiter(this, void 0, void 0, function* () {
t.plan(5);
const action = element.submitForm();
t.is(description_1.format(action.description), 'submit form containing element \'selector\'');
const submit = sinon_1.stub().rejects(new Error('foo'));
const findElement = sinon_1.stub().resolves({ submit });
yield t.throws(action.perform({ findElement }), 'foo');
t.is(findElement.callCount, 1);
t.deepEqual(findElement.args[0][0], selenium_webdriver_1.By.css('selector'));
t.is(submit.callCount, 1);
}));
//# sourceMappingURL=element.test.js.map