Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypifiedElement add check for disabled #32

Open
evangelion1204 opened this issue Apr 28, 2014 · 14 comments
Open

TypifiedElement add check for disabled #32

evangelion1204 opened this issue Apr 28, 2014 · 14 comments

Comments

@evangelion1204
Copy link
Contributor

Some tests require to check if elements are enabled / disabled. TypifiedElement or WebElement should have a function to check this status.
Something like isDisabled or isEnabled.

@aik099
Copy link
Member

aik099 commented Apr 28, 2014

Common methods for all typified elements are located in TypifiedElement class (see https://github.com/aik099/qa-tools/blob/45483780c702e9cded81c8c8ab4cb6dc7c8b8426/library/aik099/QATools/HtmlElements/Element/TypifiedElement.php). However the isDisabled check isn't common for all typified elements. It only makes sense if an element is input, textarea or select.

This might not be obvious at first, but being a subclass of TypifiedElement class doesn't immediately mean that element has anything to do with form tag or even can be submitted. There can be (in future) elements like lists (from UL/LI) and images (already have task for that), which doesn't feature that ability.

I propose this:

  1. create the abstract FormElement extends TypifiedElement class with the isDisabled method
  2. from list of current elements (see https://github.com/aik099/qa-tools/tree/master/library/aik099/QATools/HtmlElements/Element) extract sub-set of ones that can be submitted on form (and can be disabled because of this)
  3. sub-class them from FromElement instead of TypifiedElement
  4. update tests to reflect that

@aik099
Copy link
Member

aik099 commented Apr 28, 2014

If the WebElement doesn't have such isDisabled function then it will be better to send PR to Mink to add it, rather than adding it locally in the WebElement class.

@evangelion1204
Copy link
Contributor Author

I couldn't find a function like this in Mink. I am not even sure if Mink can read the properties of elements via selenium. I currently do a workaround with hasAttribute, but disabled is a property.

@aik099
Copy link
Member

aik099 commented Apr 28, 2014

I couldn't find a function like this in Mink.

Feel free to send a PR there. Don't forgot that you need to (if you decide to PR):

  1. create tests for that
  2. add in DriverInterface
  3. add in CoreDriver
  4. add in each driver (even headless ones)
  5. send PR to each driver with a change

This is how my initial library development was. I found that Mink is missing something and sent a PR to add such feature. Then I've used it inside qa-tools :)

In this case it's very easy, since you just copy-paste where you found isChecked and make it isDisabled.

I am not even sure if Mink can read the properties of elements via selenium.

It can. Look for isChecked method for example. It's reading DOM node attribute value via JavaScript to be on the safe side.

I currently do a workaround with hasAttribute, but disabled is a property.

This is way wrong, because that doesn't cover the case when element was initially enabled and then was disabled using JavaScript.

@aik099
Copy link
Member

aik099 commented Apr 28, 2014

And IMO in tests you only need to do what user can do. User can't determine if input is disabled. User can however try to interact with disabled input and fail.

@evangelion1204
Copy link
Contributor Author

Well the user will get feedback that an element is disabled (gray background, different mouse cursor or whatever).
There may be other solutions yes, maybe I need to rethink my strategy of testing 😄 but keep in mind that if I need it it also needs to be added to Mink.

@aik099
Copy link
Member

aik099 commented Apr 28, 2014

There may be other solutions yes, maybe I need to rethink my strategy of testing 😄

Agreed,

... but keep in mind that if I need it it also needs to be added to Mink.

I'm all in for the isDisabled method. Feel free to send PR's to Mink and then once merged there to this library according to proposed plan.

@aik099
Copy link
Member

aik099 commented Apr 28, 2014

I've moved away actual architectural changes (adding of FormElement class) to the #33 issue.

Here we only need to add isDisabled method to the FormElement class, when it will be available in Mink.

@evangelion1204
Copy link
Contributor Author

Just checked the whole drivers and Mink library, are all drivers in under Behat or are there others around I need change too?

@aik099
Copy link
Member

aik099 commented Apr 28, 2014

All drivers are within the Behat company repos.

Trick however is to setup all drivers to run the tests locally.

@aik099
Copy link
Member

aik099 commented May 2, 2014

Were you able to understand how Mink works to send a PR?

@evangelion1204
Copy link
Contributor Author

No not yet, was on vacation the last few days but got a good image on how Mink and its drivers work and could start to work with. Although I need to find out if this is possible for all drivers.

@aik099
Copy link
Member

aik099 commented May 4, 2014

Although I need to find out if this is possible for all drivers.

Believe me it is. Basically the isChecked method (for every driver that has it) does that via JavaScript. So checking for another JS property of DOM node is easy. For the MinkSahiDriver the actual JS code is in the SahiClient repo.

@aik099 aik099 added this to the 1.0.0 milestone May 7, 2014
@aik099 aik099 modified the milestones: 1.0.0, 1.0.x Jul 30, 2014
@aik099 aik099 modified the milestones: 1.0.x, 1.1.0 Aug 23, 2014
@aik099 aik099 removed this from the 1.1.0 milestone Dec 13, 2014
@aik099
Copy link
Member

aik099 commented Dec 13, 2014

Unfortunately this can't be implemented until Mink itself will have driver-agnostic isDisabled method (see Behat/Mink#521), which in turn is blocked by driver-agnostic JS code execution in element context issue: Behat/Mink#499 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants