mirror of
https://github.com/teampoltergeist/poltergeist.git
synced 2022-11-09 12:05:00 -05:00
Merge pull request #459 from khodzha/form_submit
Added submit event triggering
This commit is contained in:
commit
a969ef40fa
3 changed files with 28 additions and 6 deletions
|
@ -75,7 +75,8 @@ class PoltergeistAgent.Node
|
|||
@EVENTS = {
|
||||
FOCUS: ['blur', 'focus', 'focusin', 'focusout'],
|
||||
MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove',
|
||||
'mouseover', 'mouseout', 'mouseup']
|
||||
'mouseover', 'mouseout', 'mouseup'],
|
||||
FORM: ['submit']
|
||||
}
|
||||
|
||||
constructor: (@agent, @element) ->
|
||||
|
@ -272,13 +273,19 @@ class PoltergeistAgent.Node
|
|||
false, false, false, false, 0, null
|
||||
)
|
||||
else if Node.EVENTS.FOCUS.indexOf(name) != -1
|
||||
event = document.createEvent('HTMLEvents')
|
||||
event.initEvent(name, true, true)
|
||||
event = this.obtainEvent(name)
|
||||
else if Node.EVENTS.FORM.indexOf(name) != -1
|
||||
event = this.obtainEvent(name)
|
||||
else
|
||||
throw "Unknown event"
|
||||
|
||||
@element.dispatchEvent(event)
|
||||
|
||||
obtainEvent: (name) ->
|
||||
event = document.createEvent('HTMLEvents')
|
||||
event.initEvent(name, true, true)
|
||||
event
|
||||
|
||||
mouseEventTest: (x, y) ->
|
||||
frameOffset = this.frameOffset()
|
||||
|
||||
|
|
|
@ -145,7 +145,8 @@ PoltergeistAgent.InvalidSelector = (function() {
|
|||
PoltergeistAgent.Node = (function() {
|
||||
Node.EVENTS = {
|
||||
FOCUS: ['blur', 'focus', 'focusin', 'focusout'],
|
||||
MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup']
|
||||
MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup'],
|
||||
FORM: ['submit']
|
||||
};
|
||||
|
||||
function Node(agent, element) {
|
||||
|
@ -405,14 +406,22 @@ PoltergeistAgent.Node = (function() {
|
|||
event = document.createEvent('MouseEvent');
|
||||
event.initMouseEvent(name, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||
} else if (Node.EVENTS.FOCUS.indexOf(name) !== -1) {
|
||||
event = document.createEvent('HTMLEvents');
|
||||
event.initEvent(name, true, true);
|
||||
event = this.obtainEvent(name);
|
||||
} else if (Node.EVENTS.FORM.indexOf(name) !== -1) {
|
||||
event = this.obtainEvent(name);
|
||||
} else {
|
||||
throw "Unknown event";
|
||||
}
|
||||
return this.element.dispatchEvent(event);
|
||||
};
|
||||
|
||||
Node.prototype.obtainEvent = function(name) {
|
||||
var event;
|
||||
event = document.createEvent('HTMLEvents');
|
||||
event.initEvent(name, true, true);
|
||||
return event;
|
||||
};
|
||||
|
||||
Node.prototype.mouseEventTest = function(x, y) {
|
||||
var el, frameOffset, origEl;
|
||||
frameOffset = this.frameOffset();
|
||||
|
|
|
@ -555,6 +555,12 @@ describe Capybara::Session do
|
|||
expect { @session.find(:xpath, '#remove_me') }.to raise_error(Capybara::Poltergeist::InvalidSelector)
|
||||
end
|
||||
|
||||
it 'should submit form' do
|
||||
@session.visit('/poltergeist/send_keys')
|
||||
@session.find(:css, '#without_submit_button').trigger('submit')
|
||||
expect(@session.find(:css, '#without_submit_button input').value).to eq('Submitted')
|
||||
end
|
||||
|
||||
context 'whitespace stripping tests' do
|
||||
before do
|
||||
@session.visit '/poltergeist/filter_text_test'
|
||||
|
|
Loading…
Add table
Reference in a new issue