- carlosRomero
- Posts : 1
Join date : 2012-06-26
Selenium testing - events seem not to be fired.
Tue Jun 26, 2012 9:32 pm
I'm using embedded glassfish to deploy my web application and test it with arquillian remote control. While everything's been going nice so far, we found a problem when trying to deal with a suggestions feature in the application. It basically consists of a text box which offers a list of possibly matching items once 3 or more characters have been typed.
Some events are added so these suggestions are properly displayed, as follows (in the following code, the parameter inputNode) is the textbox itself where the user types...there is where we add the events):
When the application is deployed normally (for no testing purposes, without selenium) it works as expected and when typing something the suggestions are displayed. However, when using Selenium no matter what is typed in the box nothing happens. We've tried many possibilities and combinations with .keyDown(), .keyPress(), .keyUp() with their char, keyCode and native variants. Also, .type(), .typeKeys()....all of them to no avail. It would seem as though for some reasons the events are ignored (the funny thing is, if we hand-type some text in the browser selenium opens for testing the application, the suggestions -do- display. They only don't when it's selenium doing the typing).
Any help would be greatly appreciated. Not sure if I made complete sense, we'd be happy to clarify.
Greetings.
[code]
- Code:
<div class="uiModuleSelectingConcepts suggestion_${cc.id}">
<div class="searchBox">
<fieldset>
<input type="text"
class="sample"
value="${cc.attrs.input_label}"
placeholder="${cc.attrs.input_label}"/>
<i></i>
</fieldset>
</div>
<a4j:outputPanel id="suggestion_component_container"
styleClass="suggestionsWrapper"
layout="block">
<div class="suggestionsList_${cc.id}">
</div>
</a4j:outputPanel>
</div>
Some events are added so these suggestions are properly displayed, as follows (in the following code, the parameter inputNode) is the textbox itself where the user types...there is where we add the events):
- Code:
this.addEventHandlers = function (inputNode, suggestionCallback, params) {
var parent = this;
inputNode
/*
* keypress event.
*/
.keypress(function(event) {
if (event.keyCode === 13) {
event.preventDefault();
}
})
/*
* keyup event.
*/
.keyup(function(event) {
switch (event.keyCode) {
/**
* Up arrow.
*/
case 38:
event.stopPropagation();
event.preventDefault();
var suggestionsWrapper = parent._params.list;
var currentSelectedValue = null;
if (suggestionsWrapper.find(".suggestionItem").length) {
if (suggestionsWrapper.find(".suggestionItem:first").hasClass("focused")) {
suggestionsWrapper.find(".focused").removeClass("focused");
suggestionsWrapper.find(".suggestionItem:last").addClass("focused");
//currentSelectedValue = suggestionsWrapper.find(".suggestionItem:last").val();
} else {
suggestionsWrapper.find(".focused").removeClass("focused").prev().addClass("focused");
};
//set the selected value to input.
http://console.debug("Current Valiue", suggestionsWrapper.find(".focused"));
var e = suggestionsWrapper.find(".focused");
if (e.length > 0) {
http://console.debug("Current e", e);
currentSelectedValue = typeof e === 'undefined' ? null : e.attr('data-suggest');
http://console.debug("Current Valiue", currentSelectedValue);
if (currentSelectedValue != null) {
jQuery(this).val(Encoder.htmlDecode(currentSelectedValue));
}
}
}
parent._blur = false;
break;
/**
* Down arrow.
*/
case 40:
var suggestionsWrapper = parent._params.list;
var currentSelectedValue = null;
if (suggestionsWrapper.find(".suggestionItem").length) {
if (suggestionsWrapper.find(
".suggestionItem:last").hasClass("focused")) {
suggestionsWrapper.find(".focused").removeClass("focused");
suggestionsWrapper.find(".suggestionItem:first").addClass("focused");
} else {
suggestionsWrapper.find(".focused").removeClass("focused").next().addClass("focused");
};
http://console.debug("Current Valiue", suggestionsWrapper.find(".focused"));
var e = suggestionsWrapper.find(".focused");
http://console.debug("Current e", e);
if (e.length > 0) {
currentSelectedValue = typeof e === 'undefined' ? null : e.attr('data-suggest');
http://console.debug("Current Valiue", currentSelectedValue);
if (currentSelectedValue != null) {
jQuery(this).val(Encoder.htmlDecode(currentSelectedValue));
}
}
}
parent._blur = false;
break;
/**
* ENTER key
*/
case 13:
event.stopPropagation();
event.preventDefault();
var suggestionsWrapper = parent._params.list;
var oConcept = suggestionsWrapper.find(".focused");
if (typeof oConcept !== "undefined") {
oConcept.trigger("click");
}
parent._blur = true;
parent._cleanSuggestions();
jQuery(this).blur();
break;
/**
* ESC key event.
*/
case 27:
event.stopPropagation();
event.preventDefault();
var sValue = jQuery(this).attr("data-default");
sValue = jQuery.trim(sValue);
if (sValue === jQuery(this).attr("data-default")) {
jQuery(this).addClass("sample").blur();
}
parent._blur = true;
parent._cleanSuggestions();
jQuery(this).val("");
jQuery(this).blur();
break;
default:
var suggestionsWrapper = parent._params.list;
//var typeRight = jQuery(this).parents(".tabContent").attr("id");
var sValue = jQuery.trim(jQuery(this).val());
//var oThisInput = jQuery(this);
if (sValue.length > MEDIA.configuration.SUGGESTION_LIMIT) {
suggestionsWrapper.find(".suggestionItem").remove();
global.uiDelay( function() {
parent.displayLoading();
suggestionCallback(sValue, MEDIA.util.getTrueFalseValue(parent._params.retrieveOnlyClasses) ? suggestOnlyConcepts : "");
}, 1000);
} else {
parent.writeMore();
}
parent._blur = true;
break;
};
}).keydown(function(event) {
switch (event.keyCode) {
case 38: // up
event.stopPropagation();
event.preventDefault();
break;
case 40: // down
event.stopPropagation();
event.preventDefault();
break;
default:
break;
};
}).focus(function() {
jQuery(this).val("");
parent._blur = true;
// when suggestions lose focus
}).blur(function() {
if (parent._blur) {
jQuery(this).val("");
parent._cleanSuggestions();
}
});
};
When the application is deployed normally (for no testing purposes, without selenium) it works as expected and when typing something the suggestions are displayed. However, when using Selenium no matter what is typed in the box nothing happens. We've tried many possibilities and combinations with .keyDown(), .keyPress(), .keyUp() with their char, keyCode and native variants. Also, .type(), .typeKeys()....all of them to no avail. It would seem as though for some reasons the events are ignored (the funny thing is, if we hand-type some text in the browser selenium opens for testing the application, the suggestions -do- display. They only don't when it's selenium doing the typing).
Any help would be greatly appreciated. Not sure if I made complete sense, we'd be happy to clarify.
Greetings.
[code]
- SouravActive particpant
- Posts : 17
Join date : 2012-06-28
Re: Selenium testing - events seem not to be fired.
Thu Jun 28, 2012 8:28 pm
You may get this error in IE. I also faced similar issue for onchange while adding methods dynamically. For me, I had to call java script methods using Execute Javascript. If you have to do the same, remember to put 'window.'.
Permissions in this forum:
You cannot reply to topics in this forum