0

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&amp;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()
        }
    }
Giannis
  • 5,286
  • 15
  • 58
  • 113

1 Answers1

0

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:

  1. Download/install PhantomJS per their docs
  2. Add the PhantomJSDriver to your test dependencies 'com.github.detro.ghostdriver:phantomjsdriver:1.1.0'
  3. Set a system property that points to the PhantomJS binary
  4. 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!

nerdherd
  • 2,508
  • 2
  • 24
  • 40
  • Thanks for your answer. PhantomJs seems to work, which will be my driver of choice for the future. Although the tests that caused the problem will be run on Solaris, so phantom is not an option. Atm adding a ton of waitFor statements seems to make tests pass, 6/6 succcess so far, will need to run them few more times to be sure. – Giannis Jun 20 '14 at 15:18
  • Also, is it possible to add phantomjs on path, instead of specifying full path in System.setProperty("phantomjs.binary.path", "path/to/phantomjs/binary")? – Giannis Jun 20 '14 at 15:20
  • I believe it looks for a system property with that name, which you could also set in other ways. I haven't tried adding it to the path, so I don't know if that would do it. If you are ultimately running the tests on Solaris you could look into running a remote web driver on a different system using phantomjs with selenium grid. – nerdherd Jun 20 '14 at 17:26