Class: Celerity::Image

Inherits:
Element show all
Includes:
ClickableElement
Defined in:
lib/celerity/elements/image.rb,
lib/celerity/watir_compatibility.rb

Constant Summary collapse

TAGS =
[ Identifier.new('img') ]
ATTRIBUTES =
BASE_ATTRIBUTES | [
  :align,
  :alt,
  :border,
  :height,
  :hspace,
  :ismap,
  :longdesc,
  :name,
  :src,
  :usemap,
  :vspace,
  :width,
]
DEFAULT_HOW =
:src

Constants inherited from Element

Element::BASE_ATTRIBUTES, Element::CELLHALIGN_ATTRIBUTES, Element::CELLVALIGN_ATTRIBUTES, Element::HTML_401_TRANSITIONAL

Instance Attribute Summary

Attributes inherited from Element

#container

Attributes included from Container

#browser

Instance Method Summary collapse

Methods included from ClickableElement

#click, #click_and_attach, #double_click, #download, #right_click

Methods inherited from Element

#==, #assert_exists, #attribute_string, #attribute_value, #exists?, #fire_event, #focus, #focused?, #initialize, #javascript_object, #locate, #method_missing, #methods, #object, #parent, #respond_to?, #text, #to_s, #to_xml, #visible?, #xpath

Methods included from Container

#area, #areas, #button, #buttons, #cell, #cells, #check_box, #checkboxes, #container=, #contains_text, #dd, #dds, #del, #dels, #div, #divs, #dl, #dls, #dt, #dts, #em, #ems, #file_field, #file_fields, #form, #forms, #frame, #frames, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #hidden, #hiddens, #image, #images, #ins, #inses, #inspect, #label, #labels, #li, #link, #links, #lis, #map, #maps, #meta, #metas, #ol, #ols, #option, #p, #pre, #pres, #ps, #radio, #radios, #row, #rows, #select_list, #select_lists, #span, #spans, #strong, #strongs, #table, #tables, #tbodies, #tbody, #text_field, #text_fields, #tfoot, #tfoots, #th, #thead, #theads, #ths, #ul, #uls

Methods included from ShortInspect

#short_inspect

Constructor Details

This class inherits a constructor from Celerity::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Celerity::Element

Instance Method Details

#file_created_dateObject Also known as: fileCreatedDate

returns the file created date of the image



28
29
30
31
32
# File 'lib/celerity/elements/image.rb', line 28

def file_created_date
  assert_exists
  web_response = @object.getWebResponse(true)
  Time.parse(web_response.getResponseHeaderValue("Last-Modified").to_s)
end

#file_sizeObject Also known as: fileSize

returns the file size of the image in bytes



38
39
40
41
42
# File 'lib/celerity/elements/image.rb', line 38

def file_size
  assert_exists
  web_response = @object.getWebResponse(true)
  web_response.getContentAsBytes.length
end

#heightObject

returns the height in pixels of the image, as a string



57
58
59
60
# File 'lib/celerity/elements/image.rb', line 57

def height
  assert_exists
  @object.getHeight
end

#loaded?Boolean Also known as: hasLoaded?

returns true if the image is loaded

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
# File 'lib/celerity/elements/image.rb', line 66

def loaded?
  assert_exists
  begin
    @object.getImageReader
    true
  rescue
    false
  end
end

#save(filename) ⇒ Object

Saves the image to the given file



80
81
82
83
84
85
86
# File 'lib/celerity/elements/image.rb', line 80

def save(filename)
  assert_exists
  image_reader = @object.getImageReader
  file = java.io.File.new(filename)
  buffered_image = image_reader.read(0);
  javax.imageio.ImageIO.write(buffered_image, image_reader.getFormatName(), file);
end

#widthObject

returns the width in pixels of the image, as a string



48
49
50
51
# File 'lib/celerity/elements/image.rb', line 48

def width
  assert_exists
  @object.getWidth
end