Permalink
Browse files

implement #find_xpath

  • Loading branch information...
1 parent 067394d commit eedb66d1d0c86255842851e6ca5307680ba8a6de @jonleighton jonleighton committed Mar 2, 2013
View
@@ -1,4 +1,6 @@
source :rubygems
gemspec
+
gem 'rspec-rerun', github: 'jonleighton/rspec-rerun'
gem 'capybara', github: 'jnicklas/capybara'
+gem 'xpath', github: 'jnicklas/xpath'
@@ -38,8 +38,8 @@ def source
command 'source'
end
- def find(selector)
- result = command('find', selector)
+ def find(method, selector)
+ result = command('find', method, selector)
result['ids'].map { |id| [result['page_id'], id] }
end
@@ -27,7 +27,7 @@ class PoltergeistAgent
currentUrl: ->
window.location.toString()
- find: (selector, within = document) ->
+ find: (method, selector, within = document) ->
results = document.evaluate(selector, within, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
ids = []
@@ -98,8 +98,8 @@ class Poltergeist.Browser
source: ->
this.sendResponse @page.source()
- find: (selector) ->
- this.sendResponse(page_id: @page_id, ids: @page.find(selector))
+ find: (method, selector) ->
+ this.sendResponse(page_id: @page_id, ids: @page.find(method, selector))
find_within: (page_id, id, selector) ->
this.sendResponse this.node(page_id, id).find(selector)
@@ -44,7 +44,7 @@ PoltergeistAgent = (function() {
return window.location.toString();
};
- PoltergeistAgent.prototype.find = function(selector, within) {
+ PoltergeistAgent.prototype.find = function(method, selector, within) {
var i, ids, results, _i, _ref;
if (within == null) {
within = document;
@@ -124,10 +124,10 @@ Poltergeist.Browser = (function() {
return this.sendResponse(this.page.source());
};
- Browser.prototype.find = function(selector) {
+ Browser.prototype.find = function(method, selector) {
return this.sendResponse({
page_id: this.page_id,
- ids: this.page.find(selector)
+ ids: this.page.find(method, selector)
});
};
@@ -106,8 +106,12 @@ def source
browser.source.to_s
end
- def find(selector)
- browser.find(selector).map { |page_id, id| Capybara::Poltergeist::Node.new(self, page_id, id) }
+ def find(method, selector)
+ browser.find(method, selector).map { |page_id, id| Capybara::Poltergeist::Node.new(self, page_id, id) }
+ end
+
+ def find_xpath(selector)
+ find :xpath, selector
end
def click(x, y)
@@ -36,6 +36,7 @@ def find(selector)
def text
command(:text).gsub(NBSP, ' ').gsub(/\s+/u, ' ').strip
end
+ alias visible_text text
def [](name)
command :attribute, name

0 comments on commit eedb66d

Please sign in to comment.