File: match_xpath_spec.rb

package info (click to toggle)
ruby-capybara 3.40.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,368 kB
  • sloc: ruby: 23,988; javascript: 752; makefile: 11
file content (25 lines) | stat: -rw-r--r-- 845 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

Capybara::SpecHelper.spec '#match_xpath?' do
  before do
    @session.visit('/with_html')
    @element = @session.find(:css, 'span.number')
  end

  it 'should be true if the given selector is on the page' do
    expect(@element).to match_xpath('//span')
    expect(@element).to match_xpath("//span[@class='number']")
  end

  it 'should be false if the given selector is not on the page' do
    expect(@element).not_to match_xpath('//abbr')
    expect(@element).not_to match_xpath('//div')
    expect(@element).not_to match_xpath("//span[@class='not_a_number']")
  end

  it 'should use xpath even if default selector is CSS' do
    Capybara.default_selector = :css
    expect(@element).not_to have_xpath("//span[@class='not_a_number']")
    expect(@element).not_to have_xpath("//div[@class='number']")
  end
end