Module: Kelp::Attribute

Defined in:
lib/kelp/attribute.rb

Overview

This module defines helper methods for verifying attributes of HTML elements on a web page.

Instance Method Summary (collapse)

Instance Method Details

- (Object) should_be_disabled(element_id)

Verify that the HTML element with the given ID exists, and is disabled (has the disabled attribute).

Raises:

  • (Kelp::Unexpected)

    If the given element id is not found, or the element is not disabled



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kelp/attribute.rb', line 15

def should_be_disabled(element_id)
  if page.has_xpath?("//*[@id='#{element_id}']")
    if !page.has_xpath?("//*[@id='#{element_id}' and @disabled]")
      raise Kelp::Unexpected,
        "Expected element with id='#{element_id}' to be disabled," + \
        " but the 'disabled' attribute is not present."
    end
  else
    raise Kelp::Unexpected,
      "Element with id='#{element_id}' not found."
  end
end

- (Object) should_be_enabled(element_id)

Verify that the HTML element with the given ID exists, and is enabled (does not have the disabled attribute).

Raises:

  • (Kelp::Unexpected)

    If the given element id is not found, or the element is not enabled



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kelp/attribute.rb', line 38

def should_be_enabled(element_id)
  if page.has_xpath?("//*[@id='#{element_id}']")
    if page.has_xpath?("//*[@id='#{element_id}' and @disabled]")
      raise Kelp::Unexpected,
        "Expected element with id='#{element_id}' to be enabled," + \
        " but the 'disabled' attribute is present."
    end
  else
    raise Kelp::Unexpected,
      "Element with id='#{element_id}' not found."
  end
end