Module: E2E::Assertions

Included in:
Minitest::TestCase
Defined in:
lib/e2e/assertions.rb

Instance Method Summary collapse

Instance Method Details

#assert_current_path(expected_path) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/e2e/assertions.rb', line 52

def assert_current_path(expected_path)
  actual_path = nil
  found = E2E.wait_until do
    url = page.current_url
    actual_path = begin
      URI.parse(url).path
    rescue URI::InvalidURIError
      url
    end

    if expected_path.is_a?(Regexp)
      actual_path.match?(expected_path)
    else
      actual_path == expected_path
    end
  end

  assert found, "Expected current path to be #{expected_path.inspect}, but was #{actual_path.inspect}"
end

#assert_selector(selector) ⇒ Object



36
37
38
39
40
41
# File 'lib/e2e/assertions.rb', line 36

def assert_selector(selector)
  found = E2E.wait_until do
    page.all(selector).any?(&:visible?)
  end
  assert found, "Expected to find visible selector #{selector.inspect}"
end

#assert_text(text) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/e2e/assertions.rb', line 5

def assert_text(text)
  actual_text = nil
  found = E2E.wait_until do
    actual_text = page.text
    if text.is_a?(Regexp)
      actual_text.match?(text)
    else
      actual_text.include?(text)
    end
  end

  assert found, "Expected page to have text #{text.inspect}, but it had:
#{actual_text}"
end

#refute_current_path(expected_path) ⇒ Object Also known as: assert_no_current_path



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/e2e/assertions.rb', line 72

def refute_current_path(expected_path)
  actual_path = nil
  found = E2E.wait_until do
    url = page.current_url
    actual_path = begin
      URI.parse(url).path
    rescue URI::InvalidURIError
      url
    end

    if expected_path.is_a?(Regexp)
      !actual_path.match?(expected_path)
    else
      actual_path != expected_path
    end
  end

  assert found, "Expected current path NOT to be #{expected_path.inspect}, but it was"
end

#refute_selector(selector) ⇒ Object Also known as: assert_no_selector



43
44
45
46
47
48
# File 'lib/e2e/assertions.rb', line 43

def refute_selector(selector)
  found = E2E.wait_until do
    page.all(selector).none?(&:visible?)
  end
  assert found, "Expected NOT to find visible selector #{selector.inspect}"
end

#refute_text(text) ⇒ Object Also known as: assert_no_text



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/e2e/assertions.rb', line 20

def refute_text(text)
  actual_text = nil
  found = E2E.wait_until do
    actual_text = page.text
    if text.is_a?(Regexp)
      !actual_text.match?(text)
    else
      !actual_text.include?(text)
    end
  end

  assert found, "Expected page NOT to have text #{text.inspect}, but it did."
end