Skip to content

Commit

Permalink
Merge pull request #2 from testiumjs/jk-cleanup
Browse files Browse the repository at this point in the history
Cleanup and more tests
  • Loading branch information
jkrems committed Oct 21, 2015
2 parents 1ea5272 + 117fcf1 commit b1eb001
Show file tree
Hide file tree
Showing 15 changed files with 616 additions and 47 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1.0.3
-----
* Initial release
37 changes: 18 additions & 19 deletions lib/assert/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ function isTextOrRegexp(textOrRegExp) {
return _.isString(textOrRegExp) || _.isRegExp(textOrRegExp);
}

exports._getElementWithProperty = function _getElementWithProperty(selector, property) {
var element = this._getElement(selector);
return [ element, element.get(property) ];
};

exports._getElement = function _getElement(selector) {
var elements = this.driver.getElements(selector);
var count = elements.length;
Expand Down Expand Up @@ -76,15 +71,16 @@ exports.elementHasText = function elementHasText(doc, selector, textOrRegExp) {
assert.hasType('elementHasText(selector, textOrRegExp) - requires selector', String, selector);
assert.truthy('elementHasText(selector, textOrRegExp) - requires textOrRegExp', isTextOrRegexp(textOrRegExp));

var result = this._getElementWithProperty(selector, 'text');
var element = this._getElement(selector);
var actualText = element.get('text');

if (textOrRegExp === '') {
assert.equal(textOrRegExp, result[1]);
assert.equal(textOrRegExp, actualText);
} else {
assert.include(doc, textOrRegExp, result[1]);
assert.include(doc, textOrRegExp, actualText);
}

return result[0];
return element;
};

exports.elementLacksText = function elementLacksText(doc, selector, textOrRegExp) {
Expand All @@ -99,10 +95,11 @@ exports.elementLacksText = function elementLacksText(doc, selector, textOrRegExp
assert.hasType('elementLacksText(selector, textOrRegExp) - requires selector', String, selector);
assert.truthy('elementLacksText(selector, textOrRegExp) - requires textOrRegExp', isTextOrRegexp(textOrRegExp));

var result = this._getElementWithProperty(selector, 'text');
var element = this._getElement(selector);
var actualText = element.get('text');

assert.notInclude(doc, textOrRegExp, result[1]);
return result[0];
assert.notInclude(doc, textOrRegExp, actualText);
return element;
};

exports.elementHasValue = function elementHasValue(doc, selector, textOrRegExp) {
Expand All @@ -117,15 +114,16 @@ exports.elementHasValue = function elementHasValue(doc, selector, textOrRegExp)
assert.hasType('elementHasValue(selector, textOrRegExp) - requires selector', String, selector);
assert.truthy('elementHasValue(selector, textOrRegExp) - requires textOrRegExp', isTextOrRegexp(textOrRegExp));

var result = this._getElementWithProperty(selector, 'value');
var element = this._getElement(selector);
var actualValue = element.get('value');

if (textOrRegExp === '') {
assert.equal(textOrRegExp, result[1]);
assert.equal(textOrRegExp, actualValue);
} else {
assert.include(doc, textOrRegExp, result[1]);
assert.include(doc, textOrRegExp, actualValue);
}

return result[0];
return element;
};

exports.elementLacksValue = function elementLacksValue(doc, selector, textOrRegExp) {
Expand All @@ -140,10 +138,11 @@ exports.elementLacksValue = function elementLacksValue(doc, selector, textOrRegE
assert.hasType('elementLacksValue(selector, textOrRegExp) - requires selector', String, selector);
assert.truthy('elementLacksValue(selector, textOrRegExp) - requires textOrRegExp', isTextOrRegexp(textOrRegExp));

var result = this._getElementWithProperty(selector, 'value');
var element = this._getElement(selector);
var actualValue = element.get('value');

assert.notInclude(doc, textOrRegExp, result[1]);
return result[0];
assert.notInclude(doc, textOrRegExp, actualValue);
return element;
};

exports.elementIsVisible = function elementIsVisible(selector) {
Expand Down
1 change: 0 additions & 1 deletion lib/assert/imgLoaded_client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* jshint browser: true */
'use strict';

// returns true if the image is loaded and decoded,
Expand Down
3 changes: 3 additions & 0 deletions lib/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ var builtIns = [
];

function Browser(driver, options) {
var invocation = 'new Browser(driver, targetUrl, commandUrl)';
assert.hasType(invocation + ' - requires (Object) driver', Object, driver);

this.driver = driver;
this.capabilities = driver.capabilities;

Expand Down
33 changes: 16 additions & 17 deletions lib/testium-driver-sync.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
'use strict';

var path = require('path');

var WebDriver = require('webdriver-http-sync');
var debug = require('debug')('testium-driver-sync:browser');
var _ = require('lodash');

var Browser = require('./browser');
var Assertions = require('./assert');

function applyMixin(obj, mixin) {
debug('Applying mixin to %s', obj.constructor.name, mixin);
var mixinFile = path.resolve(process.cwd(), mixin);
_.extend(obj, require(mixinFile));
}

function applyMixins(obj, mixins) {
_.each(mixins, _.partial(applyMixin, obj));
}

function createDriver(testium) {
var config = testium.config;

Expand All @@ -21,27 +34,13 @@ function createDriver(testium) {
});
browser.assert = new Assertions(driver, browser);

applyMixins(browser, config.get('mixins.browser', []));
applyMixins(browser.assert, config.get('mixins.assert', []));

// Default to reasonable size.
// This fixes some phantomjs element size/position reporting.
browser.setPageSize({ height: 768, width: 1024 });

var skipPriming = false;
var keepCookies = false;

if (skipPriming) {
debug('Skipping priming load');
} else {
driver.navigateTo(testium.getInitialUrl());
debug('Browser was primed');
}

if (keepCookies) {
debug('Keeping cookies around');
} else {
debug('Clearing cookies for clean state');
browser.clearCookies();
}

return testium;
}

Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
"description": "Sync interface for testium",
"main": "lib/testium-driver-sync.js",
"scripts": {
"test": "eslint lib test && mocha"
"test": "eslint lib test && mocha",
"posttest": "npub verify"
},
"files": [
"lib"
],
"repository": {
"type": "git",
"url": "git+https://github.com/testiumjs/testium-driver-sync.git"
Expand All @@ -29,7 +33,8 @@
"eslint-config-airbnb": "~0.1.0",
"mocha": "^2.3.3",
"node-static": "~0.7.7",
"testium-core": "^1.1.2",
"npub": "^2.2.0",
"testium-core": "^1.3.0",
"testium-example-app": "^1.0.4"
},
"dependencies": {
Expand Down
Loading

0 comments on commit b1eb001

Please sign in to comment.