Commit dccce079 authored by Wang Qiu's avatar Wang Qiu

add waitForPageLoad and refactor a little.

parent de4b6323
......@@ -15,8 +15,8 @@ module.exports = function(grunt) {
},
watch: {
test: {
files: ['./testSpec.js'],
tasks: ['connect', 'karma:e2e']
files: ['./testSpec.js', './karma-e2e-dsl.js'],
tasks: ['connect', 'uglify:build', 'karma:e2e']
},
},
karma: {
......
This diff is collapsed.
......@@ -96,34 +96,28 @@
}
function navigateTo(path) {
return function () {
var defer = $.Deferred();
return deferred(function (defer) {
ifr.load(function () {
defer.resolve();
});
ifr.attr('src', path);
return defer.promise();
};
});
}
function reload() {
return function () {
var defer = $.Deferred();
return deferred(function (defer) {
ifr.one('load', function () {
defer.resolve();
});
win().prop('location').reload();
return defer.promise();
};
});
}
function locationProp(propName, handler) {
return function () {
var defer = $.Deferred();
return deferred(function (defer) {
defer.done(handler);
defer.resolve(win().prop('location')[propName]);
return defer.promise();
};
});
}
function delay(callback, duration) {
......@@ -139,13 +133,25 @@
}
function sleep(duration) {
return function() {
var defer = $.Deferred();
return deferred(function (defer) {
var args = argsPassingThrough(arguments);
setTimeout(function () {
defer.resolve();
defer.resolve.apply(defer, args);
}, duration);
return defer.promise();
}
});
}
function argsPassingThrough(_arguments) {
return [].slice.call(_arguments, 1);
}
function waitForPageLoad() {
return deferred(function (defer) {
var args = argsPassingThrough(arguments);
ifr.one('load', function () {
defer.resolve.apply(defer, args);
});
});
}
var pauseDefer = null;
......@@ -172,6 +178,9 @@
pauseDefer.resolve();
pauseDefer = null;
},
waitForPageLoad: function () {
dslList.push(waitForPageLoad());
},
window: {
path: function (pathHandler) {
dslList.push(locationProp('pathname', pathHandler));
......@@ -260,28 +269,24 @@
}
function query(selectedElementsHandler) {
return function ($elems) {
var defer = $.Deferred();
return deferred(function (defer, $elems) {
defer.then(selectedElementsHandler);
defer.resolve($elems);
return defer.promise();
};
});
}
function select(value) {
if(typeof(value) === 'undefined') {
return prop('checked', true);
} else {
return function ($elems) {
var defer = $.Deferred();
return deferred(function (defer, $elems) {
$elems.each(function (idx, element) {
if($(element).val() == value) {
$(element).prop('checked', true);
}
});
defer.resolve();
return defer.promise();
};
});
}
}
......
......@@ -63,6 +63,7 @@ module.exports = function(config) {
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['Chrome'],
urlRoot: '/__karma/',
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
......
......@@ -196,10 +196,8 @@ describe('karma e2e dsl', function () {
it('should not be enabled', dsl(function() {
input('[type="submit"]').click();
browser.sleep(500);
browser.window.href(function (href) {
href.should.contain('dropdownlist=1');
});
browser.waitForPageLoad();
expect(browser.window.href()).toContain('dropdownlist=1');
}));
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment