Geb - Inconsistent behaviour in headless mode - grails

I am testing a grails application and have the tests run by Hudson. The tests are passing 100% of the time when run on local machine.
Database Is always reset when the tests initialize.
I have problem setting the value for a dynamic form. In my .gsp I have the following :
<g:xEditableRefData owner="${license}" field="isPublic" config='YN'/>
This is generating an ‘Edit’ link,. When clicked a dropdown appears which allows the user to select between Yes or No. (screenshots at the end of mail):
Following is the generated code:
<span data-url="/demo/ajax/genericSetRel"
data-source="/demo/ajax/sel2RefdataSearch/YN?format=json&oid=License%3A1"
data-name="isPublic" data-type="select" data-pk="License:1"
class="xEditableManyToOne editable editable-click editable-empty" id="License:1:isPublic">Edit
</span>
And when clicked:
<span class="editable-inline editable-container">
<div>
<div class="editableform-loading" style="display: none;"></div>
<form class="form-inline editableform" style="">
<div class="control-group">
<div>
<div class="editable-input">
<select class="input-medium">
<option value="RefdataValue:1">Yes</option>
<option value="RefdataValue:2">No</option>
</select>
</div>
<div class="editable-buttons">
<button class="btn btn-primary editable-submit" type="submit">
<i class="icon-ok icon-white"></i>
</button>
<button class="btn editable-cancel" type="button">
<i class="icon-remove"></i>
</button>
</div>
</div>
<div class="editable-error-block help-block" style="display: none;"></div>
</div>
</form>
</div>
</span>
I have the following method in my Page class for setting the value of the edit/dropdown:
editIsPublic { option ->
$("span", 'data-name': "isPublic").click()
try {
waitFor { $("form.editableform") }
} catch (geb.waiting.WaitTimeoutException e) {
throw new RequiredPageContentNotPresent()
}
$("select.input-medium").value(option)
$("button.editable-submit").click()
}
This is always successful on my local machine, but when run headless on Hudson I get about 80% failure. When it fails the tests don’t stop, but the dropdown has wrong value, and no exceptions are thrown. I have also considered passing arrow keys instead of set the value but this is not a good option for other reasons. Any ideas why the above code is not working on Hudson? Is there any other way I could set the value?
UPDATE
Adding a lot of waitFor statements seems to have fixed the issue for now. I have defined the following closure, and I am using it on everything that is interactive.
waitElement {run ->
try{
waitFor{run()}
} catch (geb.waiting.WaitTimeoutException e) {
throw new RequiredPageContentNotPresent()
}
}

I didn't spend a lot of time trying to get headless firefox working, because I read of many issues such as these. I decided to give PhantomJS a try instead and it has been working exactly as expected so far.
To set up the PhantomJSDriver you need to:
Download/install PhantomJS per their docs
Add the PhantomJSDriver to your test dependencies 'com.github.detro.ghostdriver:phantomjsdriver:1.1.0'
Set a system property that points to the PhantomJS binary
Set PhantomJSDriver in the GebConfig file
Here's a simple example of what I put in my GebConfig:
System.setProperty("phantomjs.binary.path", "path/to/phantomjs/binary")
driver = {
def pjsDriver = new PhantomJSDriver()
// set window size manually because the default size is very small
pjsDriver.manage().window().size = new Dimension(1680, 1050)
pjsDriver
}
Sorry that doesn't directly answer the question of "why" some tests are having issues, but hopefully that will resolve it!

Related

Bootstrap checkbox does not display in IOS

I have a responsive page built upon bootstrap. For some reason, I cannot get the checkbox to display in an iOS built device. The checkboxes work in every browser imaginable, and even work in the developer module of chrome (emulating iOS devices) and even works in the iOS reader. It just will not display on an iPhone. Is it being hidden behind another element?
Thanks in advance!
http://www.johnstoncc.edu/FA/2/depnbrhhc.html
Changing the column sizes to the following fixes it.
<div>
<div class="col-xs-2 col-sm-2 col-lg-1" style="margin-top:20px;">
<input id="OBKey_Signed_1" type="checkbox" name="OBKey_Signed_1"
value="Y" required="" data-com.agilebits.onepassword.user-edited="yes"
style="-webkit-appearance: radio;">
</div>
<div class="col-xs-10 col-sm-10 col-lg-11">
By checking this box, I ratify the use of my typed name and
Student ID number as an electronic representation of my signature.
</div>
</div>

Not able to follow link | Behat/Mink

Am not able to click on links using Behat/Mink. There's a desired text in <span> tags so maybe this could be the reason?
This is part of my *.feature file:
Scenario: Tryin' to make it freakin' workin' yo!
Given I am on "/home/"
And I follow "Test"
Then I should be on "/test/"
And this is part of the page am trying to focus on:
<li id="ApplicationItem_test" class=" " data-placement="right" rel="popover" data-offset="-6" data-content="" data-original-title="test">
<a href="/app/tests/e76ee2a8d9094e11b6bb9c928c5d61e3/" data-subscription-id="e76ee2a8-d909-4e11-b6bb-9c928c5d61e3">
<i class="picon-money-icon-16"></i>
<span class="expand-element">test
</span>
<div id="nodeCounter_c592e0ce62c849fab427fc9f2a04b557" style="display:inline-block">
</div> </a>
</li>
<script type="text/javascript">
var node = { id: '#nodeCounter_c592e0ce62c849fab427fc9f2a04b557', action: '/app/tests/e76ee2a8d9094e11b6bb9c928c5d61e3/GetSidebarActionCount' };
Access.SideBar.nodesWithCounters.push(node);
</script>
And this is the error I'm getting:
And I follow "Test"
FeatureContext::clickLink()
Link with id|title|alt|text "Test" not found. (Behat\Mink\Exception\ElementNotFoundException)
Have tried all possible CSS selector functions found on the internet. Also am wondering if I shouldn't use the Selenium extension for Behat here (because of the JS?)
So answer is: I wasn't on the right page.
Basically Scenarios should be independent - that means my previous session was burnt and I missed some previous steps (login, for example.)

ASP.NET MVC Unobtrusive validation not working on IE9

I am working on code written by someone else.
Its a Reset Password form. The current client side validation works on most browsers including IE 10 and IE 11. On IE 9 the Confirm Password does not match error keeps getting displayed even though I am sure I am typing the exact same thing in both fields.
The code:
<div class="form-group">
<div class="input-group input-phone">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<input type="password" id="Password" name="Password" class="form-control input-lg default-focus" data-val="true" data-val-required="Password is required." placeholder="Password" autocomplete="off">
</div>
<div class="field-validation-valid" data-valmsg-for="Password" data-valmsg-replace="true"></div>
</div>
<div class="form-group form-group-login-bottom">
<div class="input-group input-pin">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<input type="password" id="ConfirmPassword" name="ConfirmPassword" class="form-control input-lg" data-val="true" data-val-equalto="Confirm Password does not match." data-val-equalto-other="*.Password" placeholder="Confirm Password" autocomplete="off">
</div>
<div class="field-validation-valid" data-valmsg-for="ConfirmPassword" data-valmsg-replace="true"></div>
</div>
I searched a lot yesterday but none of the solution seems to work.
I tried: updating the jquery.validate.js and jquery.validate.unobtrusive.js files.
I tried debugging, in the jquery.validate.js file, this snippet,
// http://docs.jquery.com/Plugins/Validation/Methods/equalTo
equalTo: function( value, element, param ) {
// bind to the blur event of the target in order to revalidate whenever the target field is updated
// TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
var target = $(param);
if ( this.settings.onfocusout ) {
target.unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
$(element).valid();
});
}
return value === target.val();
},
target is the input field with id Password. On IE 10 and IE 11, alerting target.val()
returns the correct value of type in. On IE 9 it returns empty. Cannot figure out why it does not work on IE 9 specifically. Any suggestions would be helpful.
What versions of jQuery, jQuery validate and ASP MVC are you using?
I just created a fiddle using your html and including the latest versions of those libraries (jquery 2.1.0, validate 1.13 and validate-unobtrusive from MVC 5). I verified the validation works on IE9 (Mine is version 9.0.8112.16421)
However I have found this issue which means you may find this error in IE9 with incorrect html on your page. You could make sure you don´t have any open tags (like a <p> without its corresponding </p>). For example if in the fiddle you just add a <p> right before the <form> the validation stops working in IE9 but not in Firefox. (See this updated fiddle that doesn´t work on IE9)
In case this doesn´t help, I would check the library versions and any other library that you might be loading in your page that could interfere (If you could replicate your issue in a fiddle that would be great!). If nothing helps, you can try removing the validate-unobtrusive library from the fiddle (it is added on external references) and uncomment the JS code to manually use the validation plugin. At least that would let you find out if the issue is related with jquery.validate or with Microsoft´s jquery.validate-unobtrusive:
//This is commented in the fiddle. Only uncomment to try jquery.validate without jquery.validate-unobtrusive
$(document).ready(function () {
$("#testForm").validate({
debug: false,
rules: {
Password: {
required: true
},
ConfirmPassword: {
required: true,
equalTo: "#Password"
}
},
submitHandler: function (form) {
// just for the fiddle demo
alert('valid form submitted');
return false;
}
});
});

FontAwesome with Grails <g:actionSubmit

I've been trying to add icons to my save, delete, etc. buttons. I have about five buttons using the <g:actionSubmit> tag to call an action in a controller to perform the corresponding functions. My problem is that FontAwesome and bootstrap's glyphicons require the <i class="icon-***"> tag to be used like so:
<a href="http://google.com">
<i class="icon-ok"></i> Google
</a>
In grails this format of the tag in between the initial tag is not possible (at least with actionSubmit). The value attribute is the string that is displayed. Is there any work around for this? Keep in mind I still need to map the buttons action back to a controller which is why I've had issue using a straight <button> tag like what is recommended for bootstrap.
UPDATE:
I'm having a lot of problems using the current 2 answers. They both work for adding the icons, but I'm getting some nuisances that I'm having to hack a lot of things up to fix. I thought about another solution but am having some problems implementing it. I'd like to write my own tag lib using the base of the taglib as the actionSubmit tag lib below:
def actionSubmit = {attrs ->
attrs.tagName = "actionSubmit"
if (!attrs.value) {
throwTagError("Tag [$attrs.tagName] is missing required attribute [value]")
}
// add action and value
def value = attrs.remove('value')
def action = attrs.action ? attrs.remove('action') : value
out << "<input type=\"submit\" name=\"_action_${action}\" value=\"${value}\" "
// process remaining attributes
outputAttributes(attrs)
// close tag
out << '/>'
}
The only change I need to make is to give it the ability to take the
<i class="icon-ok"></i>
tag in between a:
<g:actionSubmit ...> </g:actionSubmit>
Does anyone have suggestions or for this implementation?
Don't use actionSubmit, just use a <button> and provide the link/action properties like so:
<button type="submit" class="btn">
<i class="..."></i> Update
</button>
here's a more detailed example
<button type="submit" class="btn btn-danger" name="_action_delete" value="Delete">
<i class="..."></i> ${message(code: 'default.button.delete.label', default: 'Delete')}
</button>
Note: actionSubmit passes the following input name/values for update, save and delete
name="_action_update" //update
name="_action_update" //save
name="_action_delete" //delete
so you would just need to do the same if you're app is dependent on them
Try passing the class name to remoteLink, which creates a link that uses Ajax to call a remote function and you can add your fontAwesome classes to it.
<g:remoteLink class="btn icon-ok" action="index" >
click (without i tag)
</g:remoteLink>
or
<g:remoteLink action="index" >
<i class="btn icon-ok">click (with i tag) </i>
</g:remoteLink>
Both approaches should work.

get value form simpledialog2 blank mode

I have used JQM SimpleDialog2 in my app. I am having one textbox and button in that dialog. i can't able to get the value from input while click on button in dialog. i have used blank mode.. Here is my code.. I am getting empty value from this code. please correct me.
<div id="myDialog" style="display:none"
data-options='{"mode":"blank","top":"10%","headerClose":false,"blankContent":true}'
<Center>please enter Your Amount here</center>
<input id="txtAmt" name="amy" value="" type="text" placeholder="Amount">
<div data-role="navbar" data-grid="a">
<ul>
<li>Submit</li>
<li>Cancel</li>
</ul>
</div>
function getAmount()
{
alert("amount: "+$("#txtAmt").val());
}
i didnt try this using SimpleDialog but this works just fine for me:
function getAmount(){
alert (document.getElementById('txtAmt').value);
}
By the way i would recommend using the built-in Popup-Dialog function instead of SimpleDialog. See here: http://jquerymobile.com/demos/1.2.0/docs/pages/dialog/index.html

Resources