browser-monkey
Advanced tools
Comparing version 1.15.6 to 1.15.7
12
index.js
@@ -466,5 +466,17 @@ var retry = require('trytryagain'); | ||
function safeActiveElement() { | ||
try { | ||
return document.activeElement; | ||
} catch ( err ) { } | ||
} | ||
Selector.prototype.typeIn = function(text, options) { | ||
return this.element(options).then(function(element) { | ||
debug('typeIn', element, text); | ||
var activeElement = safeActiveElement(); | ||
if (activeElement) { | ||
dispatchEvent(activeElement, 'blur'); | ||
} | ||
return sendkeys(element, text); | ||
@@ -471,0 +483,0 @@ }); |
{ | ||
"name": "browser-monkey", | ||
"version": "1.15.6", | ||
"version": "1.15.7", | ||
"description": "reliable dom testing", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -16,2 +16,5 @@ function dispatchEvent(el, type, char) { | ||
el.focus(); | ||
if (el.setActive) { | ||
el.setActive(); | ||
} | ||
@@ -18,0 +21,0 @@ for (var n = 0; n < text.length; ++n) { |
@@ -18,5 +18,9 @@ require('lie/polyfill'); | ||
function insertHtml(html){ | ||
$(html).appendTo(div); | ||
} | ||
function eventuallyInsertHtml(html) { | ||
setTimeout(function () { | ||
$(html).appendTo(div); | ||
insertHtml(html); | ||
}, 200); | ||
@@ -246,11 +250,31 @@ } | ||
it('should eventually enter text into an element', function () { | ||
var promise = browser.find('.element').typeIn('haha'); | ||
var clicked = false; | ||
describe('typeIn', function(){ | ||
it('should eventually enter text into an element', function () { | ||
var promise = browser.find('.element').typeIn('haha'); | ||
eventuallyInsertHtml('<input type="text" class="element"></input>'); | ||
eventuallyInsertHtml('<input type="text" class="element"></input>'); | ||
return promise.then(function () { | ||
expect($(div).find('input.element').val()).to.equal('haha'); | ||
return promise.then(function () { | ||
expect($(div).find('input.element').val()).to.equal('haha'); | ||
}); | ||
}); | ||
it('should fire the blur event on previously typed in element', function () { | ||
var blurred = false; | ||
insertHtml('<input type="text" class="one"><input type="text" class="two">'); | ||
$(div).find('.one').on('blur', function(e){ | ||
if (e.target.className === 'one') { | ||
blurred = true; | ||
} | ||
}) | ||
return browser.find('.one').typeIn('first').then(function(){ | ||
return browser.find('.two').typeIn('second'); | ||
}).then(function(){ | ||
expect(blurred).to.be.true | ||
}); | ||
}); | ||
}); | ||
@@ -257,0 +281,0 @@ |
51873
1070