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

Remove xpath/html #80

Merged
merged 1 commit into from
May 29, 2017
Merged

Remove xpath/html #80

merged 1 commit into from
May 29, 2017

Conversation

jnicklas
Copy link
Collaborator

This is obviously a hugely breaking change, and would necessitate bumping the major version to 3.0, but since these are no longer used by Capybara, I think it's just confusing to have them be part of the gem.

@jnicklas jnicklas requested a review from twalpole May 27, 2017 09:19
Copy link
Member

@twalpole twalpole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM A couple of Capybara's specs that still use HTML methods will need to be updated, and a documentation example but nothing major.

@jnicklas jnicklas merged commit d18fe71 into master May 29, 2017
@jnicklas jnicklas deleted the remove-html branch May 29, 2017 10:00
@TylerRick
Copy link

This is a hugely breaking change! 😄 I'm surprised no one has objected.

I just upgraded my xpath gem from a bundle update and started getting errors from code depending on XPath::HTML.

I can understand your reasons for removing this. Keeps this gem simple and focused.

Just wondering if there is a recommended upgrade path for those who want to keep using the nice selectors from XPath::HTML? Maybe they could be extracted to a xpath-html gem (I don't see one).

For now, I guess my workaround will just be:

wget -O lib/xpath/html.rb https://raw.githubusercontent.com/teamcapybara/xpath/bc99e5698d5a54facd7e95a737cec3be679b0ddc/lib/xpath/html.rb
require 'xpath/html'

@twalpole
Copy link
Member

@TylerRick I'd say just copy the previous version of the file into your project if you still want it, or just lock to < 3.0 on the gem version. If you don't mind me asking, what are you using them for?

@Ajedi32
Copy link
Contributor

Ajedi32 commented Apr 4, 2019

I personally found the HTML selectors very helpful when defining custom Capybara selectors. For example:

Capybara.add_selector(:select2_field) do
  # Find select2-container objects that point to fields with the given name
  xpath { |field_name| "#{XPath.css("div.select2-container")}[substring(./@id, 6) = (#{XPath.anywhere(XPath::HTML.field(field_name).attr(:id))})]" }
end

@twalpole
Copy link
Member

twalpole commented Apr 4, 2019

@Ajedi32 Just an FYI -- you'd be better off returning an XPath::Expression from that rather than a string. Going off your expression it would be something like

xpath { |field_name| XPath.css("div.select2-container")[XPath.attr(:id).substring(6) == XPath.anywhere(XPath::HTML.field(field_name).attr(:id))] }

@Ajedi32
Copy link
Contributor

Ajedi32 commented Apr 4, 2019

Funny story... I think enabling that exact line of code to return an XPath::Expression was actually my motivation for writing b9afe8a back in 2013. I just never got around to fixing it in the application after the commit made it into a release. Thanks for the reminder. 😄

@TylerRick
Copy link

If you don't mind me asking, what are you using them for?

Late response, but I was using them in custom selectors and things, similar to @Ajedi32.

I'd also added a select_or_input for cases where a field could be a <select> or an <input> (like field but excluding textarea):

    def select_or_input(locator)
      locator = locator.to_s
      xpath = descendant(:input, :select)[~attr(:type).one_of('submit', 'image')]
      xpath = locate_field(xpath, locator)
      xpath
    end

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

Successfully merging this pull request may close these issues.

4 participants