How to use geb to check element attribute value after page event

After a little help here, I am writing a functional web test using Geb and I want to test the value of the disabled attribute for the submit button of the form both before and after the event, the stream should be as follows:

  • The download page, the submit button is declared as disabled in the page source, so it should be disabled, for example. <input type="submit" class="submit" disabled="true"/> .
  • Check the box on the page, this will lead to the execution of part of the jQuery code, which will activate the disabled submit button using: $('input.submit').attr('disabled', false);

My first attempt was to use the $('input.submit').@disabled == 'true' statement $('input.submit').@disabled == 'true' , this seemed to work for an initial check after the page loaded, but after running my jQuery code to enable the button, a subsequent check still returns the same result. This made me wonder if this kind of check can only report the value at the time the page loads and does not see any subsequent programmatic changes?

Then I discovered that jbery jquery itegration, I was hoping that I could use this to return the value of the submit button and fulfill my statement on this, for example. $('input.submit').jquery.attr('disabled') == false however the Geb documentation confirms that all calls to the .jquery property return a Geb Navigator instance so sad that I don’t think I can return the information I need .

I also doubted whether the JQuery code really switched the button's sending state, I tested it with Firebug and I can confirm that it works fine in the browser, so I suspect that this is either a problem with my understanding of Geb or possibly a limitation Geb?

It seems to me that checking the value of the attribute of an element after performing any action on the page can be a normal use case, so I rather hope that I missed some easy way to do this. I would be very grateful for any pointers that will help me figure this out.

Greetings

Edd

+8
groovy spock geb
source share
2 answers

They did a little more tests and achieved a satisfactory result. I did a couple of things that I suppose are inproper, namely, to set the value of the disabled attribute to invalid values ​​true and false as follows:

 $('input.submit').attr('disabled', true); $('input.submit').attr('disabled', false); 

Looking at the specification of HTML forms , the attribute is disabled, as shown, does not take a value, and only its presence indicates that the element is disabled, Modifying my code for this and removing the attribute to indicate the activation of the element seems to have done the trick:

 $('input.submit').attr('disabled', true); //This time we remove the disabled attribute rather than setting it to false. $('input.submit').removeAttr('disabled'); 

Note. I am still setting the value disabled to true , since I cannot determine how to set the attribute without setting the value, see this SO post for more details.

Using the above, I can now use Geb to state the status of disabled / activated elements as follows:

 //Check that something is disabled. deleteSelectedButton.@disabled == 'true' //Check that something is enabled. deleteSelectedButton.@disabled == 'false' 

Note. It seems that Geb requires a string literal indicating the expected status, and not a boolean, which iirc caused my statements to crash.

So, now everything works beautifully, and I'm running, writing loads of Geb tests! Hope this explanation is helpful to others.

+10
source share

Forwarding my message on the Geb mailing list:

After executing the jQuery code that includes the button, is it possible that you check the result before the code actually activates the button? For example, they do something like:

 waitFor { $("input.submit").@disabled == "false" } 
+3
source share

All Articles