druid-ts 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +27 -0
  3. data/cucumber.yml +6 -2
  4. data/features/area.feature +33 -0
  5. data/features/audio.feature +66 -0
  6. data/features/canvas.feature +35 -0
  7. data/features/element.feature +9 -0
  8. data/features/html/hover.html +11 -0
  9. data/features/html/planets.gif +0 -0
  10. data/features/html/static_elements.html +43 -0
  11. data/features/html/sun.gif +0 -0
  12. data/features/html/sun.html +7 -0
  13. data/features/list_item.feature +1 -0
  14. data/features/page_level_actions.feature +25 -0
  15. data/features/sample-app/public/04-Death_Becomes_Fur.mp4 +0 -0
  16. data/features/sample-app/public/04-Death_Becomes_Fur.oga +0 -0
  17. data/features/sample-app/public/movie.mp4 +0 -0
  18. data/features/sample-app/public/movie.ogg +0 -0
  19. data/features/select_list.feature +5 -1
  20. data/features/step_definations/area_steps.rb +23 -0
  21. data/features/step_definations/audio_steps.rb +31 -0
  22. data/features/step_definations/canvas_steps.rb +19 -0
  23. data/features/step_definations/element_steps.rb +23 -2
  24. data/features/step_definations/page_level_actions_steps.rb +35 -0
  25. data/features/step_definations/select_list_steps.rb +4 -0
  26. data/features/step_definations/table_steps.rb +4 -0
  27. data/features/step_definations/video_steps.rb +19 -0
  28. data/features/support/page.rb +38 -2
  29. data/features/support/persistent_browser.rb +2 -1
  30. data/features/support/url_helper.rb +4 -0
  31. data/features/table.feature +8 -0
  32. data/features/video.feature +59 -0
  33. data/lib/druid/accessors.rb +162 -26
  34. data/lib/druid/assist.rb +63 -0
  35. data/lib/druid/element_locators.rb +126 -0
  36. data/lib/druid/elements.rb +29 -24
  37. data/lib/druid/elements/area.rb +29 -0
  38. data/lib/druid/elements/audio.rb +9 -0
  39. data/lib/druid/elements/canvas.rb +22 -0
  40. data/lib/druid/elements/element.rb +15 -1
  41. data/lib/druid/elements/list_item.rb +4 -0
  42. data/lib/druid/elements/media.rb +45 -0
  43. data/lib/druid/elements/select_list.rb +7 -1
  44. data/lib/druid/elements/table_row.rb +1 -0
  45. data/lib/druid/elements/video.rb +17 -0
  46. data/lib/druid/nested_elements.rb +32 -0
  47. data/lib/druid/version.rb +1 -1
  48. data/spec/druid/accessors_spec.rb +77 -0
  49. data/spec/druid/element_locators_spec.rb +89 -0
  50. data/spec/druid/elements/area_spec.rb +33 -0
  51. data/spec/druid/elements/canvas_spec.rb +28 -0
  52. data/spec/druid/elements/list_item_spec.rb +1 -1
  53. data/spec/druid/elements/select_list_spec.rb +6 -0
  54. metadata +42 -1
data/lib/druid/assist.rb CHANGED
@@ -402,6 +402,69 @@ module Druid
402
402
  find_elements("labels(identifier)", Elements::Label, identifier, 'p')
403
403
  end
404
404
 
405
+ #
406
+ # method to click on an area
407
+ #
408
+ def click_area_for(identifier)
409
+ process_call("area(identifier).click", Elements::Area, identifier, nil, 'area')
410
+ end
411
+
412
+ #
413
+ # method to retrieve an area element
414
+ #
415
+ def area_for(identifier)
416
+ find_element("area(identifier)", Elements::Area, identifier, 'area')
417
+ end
418
+
419
+ #
420
+ # method to retrieve an array of area elements
421
+ #
422
+ def areas_for(identifier)
423
+ find_elements("areas(identifier)", Elements::Area, identifier, 'area')
424
+ end
425
+
426
+ #
427
+ # method to retrieve a canvas element
428
+ #
429
+ def canvas_for(identifier)
430
+ find_element("canvas(identifier)", Elements::Canvas, identifier, 'canvas')
431
+ end
432
+
433
+ #
434
+ # method to retrieve an array of canvas elements
435
+ #
436
+ def canvases_for(identifier)
437
+ find_elements("canvases(identifier)", Elements::Canvas, identifier, 'canvas')
438
+ end
439
+
440
+ #
441
+ # method to retrieve an audio element
442
+ #
443
+ def audio_for(identifier)
444
+ find_element("audio(identifier)", Elements::Audio, identifier, 'audio')
445
+ end
446
+
447
+ #
448
+ # method to retrieve an array of audio elements
449
+ #
450
+ def audios_for(identifier)
451
+ find_elements("audios(identifier)", Elements::Audio, identifier, 'audio')
452
+ end
453
+
454
+ #
455
+ # method to retrieve an video element
456
+ #
457
+ def video_for(identifier)
458
+ find_element("video(identifier)", Elements::Video, identifier, 'video')
459
+ end
460
+
461
+ #
462
+ # method to retrieve an array of audio elements
463
+ #
464
+ def videos_for(identifier)
465
+ find_elements("videos(identifier)", Elements::Video, identifier, 'video')
466
+ end
467
+
405
468
  def element_for(tag, identifier)
406
469
  find_element("#{tag.to_s}(identifier)", Elements::Element, identifier, tag.to_s)
407
470
  end
@@ -899,6 +899,132 @@ module Druid
899
899
  labels_for identifier.clone
900
900
  end
901
901
 
902
+ #
903
+ # Finds an area
904
+ #
905
+ # @param [Hash] identifier how we find an area. You can use a multiple parameters
906
+ # by combining of any of the following except xpath. It defaults to {:index => 0}
907
+ # which will return the first file field. The valid keys are:
908
+ # * :class
909
+ # * :id
910
+ # * :index
911
+ # * :name
912
+ # * :xpath
913
+ #
914
+ def area_element(identifier={:index => 0})
915
+ area_for(identifier.clone)
916
+ end
917
+
918
+ #
919
+ # Finds all areas that matches the provided identifier
920
+ #
921
+ # @param [Hash] identifier how we find an area. You can use a multiple parameters
922
+ # by combining of any of the following except xpath. It defaults to empty hash
923
+ # which will return all file fields. The valid keys are:
924
+ # * :class
925
+ # * :id
926
+ # * :index
927
+ # * :name
928
+ # * :xpath
929
+ #
930
+ def area_elements(identifier={})
931
+ areas_for(identifier.clone)
932
+ end
933
+
934
+ #
935
+ # Finds an canvas
936
+ #
937
+ # @param [Hash] identifier how we find an canvas. You can use a multiple parameters
938
+ # by combining of any of the following except xpath. It defaults to {:index => 0}
939
+ # which will return the first file field. The valid keys are:
940
+ # * :class
941
+ # * :id
942
+ # * :index
943
+ # * :name
944
+ # * :xpath
945
+ #
946
+ def canvas_element(identifier={:index => 0})
947
+ canvas_for(identifier.clone)
948
+ end
949
+
950
+ #
951
+ # Finds all canvases that matches the provided identifier
952
+ #
953
+ # @param [Hash] identifier how we find an canvas. You can use a multiple parameters
954
+ # by combining of any of the following except xpath. It defaults to empty hash
955
+ # which will return all file fields. The valid keys are:
956
+ # * :class
957
+ # * :id
958
+ # * :index
959
+ # * :name
960
+ # * :xpath
961
+ #
962
+ def canvas_elements(identifier={})
963
+ canvases_for(identifier.clone)
964
+ end
965
+
966
+ #
967
+ # Finds an audio element
968
+ #
969
+ # @param [Hash] identifier how we find an audio. You can use a multiple parameters
970
+ # by combining of any of the following except xpath. It defaults to {:index => 0}
971
+ # which will return the first file field. The valid keys are:
972
+ # * :class
973
+ # * :id
974
+ # * :index
975
+ # * :name
976
+ # * :xpath
977
+ #
978
+ def audio_element(identifier={:index => 0})
979
+ audio_for(identifier.clone)
980
+ end
981
+
982
+ #
983
+ # Finds all audios that matches the provided identifier
984
+ #
985
+ # @param [Hash] identifier how we find an audio. You can use a multiple parameters
986
+ # by combining of any of the following except xpath. It defaults to empty hash
987
+ # which will return all file fields. The valid keys are:
988
+ # * :class
989
+ # * :id
990
+ # * :index
991
+ # * :name
992
+ # * :xpath
993
+ #
994
+ def audio_elements(identifier={})
995
+ audios_for(identifier.clone)
996
+ end
997
+ #
998
+ # Finds an video element
999
+ #
1000
+ # @param [Hash] identifier how we find an video. You can use a multiple parameters
1001
+ # by combining of any of the following except xpath. It defaults to {:index => 0}
1002
+ # which will return the first file field. The valid keys are:
1003
+ # * :class
1004
+ # * :id
1005
+ # * :index
1006
+ # * :name
1007
+ # * :xpath
1008
+ #
1009
+ def video_element(identifier={:index => 0})
1010
+ video_for(identifier.clone)
1011
+ end
1012
+
1013
+ #
1014
+ # Finds all videos that matches the provided identifier
1015
+ #
1016
+ # @param [Hash] identifier how we find an video. You can use a multiple parameters
1017
+ # by combining of any of the following except xpath. It defaults to empty hash
1018
+ # which will return all file fields. The valid keys are:
1019
+ # * :class
1020
+ # * :id
1021
+ # * :index
1022
+ # * :name
1023
+ # * :xpath
1024
+ #
1025
+ def video_elements(identifier={})
1026
+ videos_for(identifier.clone)
1027
+ end
902
1028
  #
903
1029
  # Finds an element
904
1030
  #
@@ -22,27 +22,32 @@ module Druid
22
22
  end
23
23
  end
24
24
 
25
- require 'druid/elements/element.rb'
26
- require 'druid/elements/ordered_list.rb'
27
- require 'druid/elements/unordered_list.rb'
28
- require 'druid/elements/table.rb'
29
- require 'druid/elements/table_row.rb'
30
- require 'druid/elements/select_list.rb'
31
- require 'druid/elements/link.rb'
32
- require 'druid/elements/button.rb'
33
- require 'druid/elements/check_box.rb'
34
- require 'druid/elements/radio_button.rb'
35
- require 'druid/elements/text_field.rb'
36
- require 'druid/elements/div.rb'
37
- require 'druid/elements/table_cell.rb'
38
- require 'druid/elements/image.rb'
39
- require 'druid/elements/span.rb'
40
- require 'druid/elements/hidden_field.rb'
41
- require 'druid/elements/list_item.rb'
42
- require 'druid/elements/text_area.rb'
43
- require 'druid/elements/form.rb'
44
- require 'druid/elements/option.rb'
45
- require 'druid/elements/heading.rb'
46
- require 'druid/elements/paragraph.rb'
47
- require 'druid/elements/file_field.rb'
48
- require 'druid/elements/label.rb'
25
+ require 'druid/elements/element'
26
+ require 'druid/elements/ordered_list'
27
+ require 'druid/elements/unordered_list'
28
+ require 'druid/elements/table'
29
+ require 'druid/elements/table_row'
30
+ require 'druid/elements/select_list'
31
+ require 'druid/elements/link'
32
+ require 'druid/elements/button'
33
+ require 'druid/elements/check_box'
34
+ require 'druid/elements/radio_button'
35
+ require 'druid/elements/text_field'
36
+ require 'druid/elements/div'
37
+ require 'druid/elements/table_cell'
38
+ require 'druid/elements/image'
39
+ require 'druid/elements/span'
40
+ require 'druid/elements/hidden_field'
41
+ require 'druid/elements/list_item'
42
+ require 'druid/elements/text_area'
43
+ require 'druid/elements/form'
44
+ require 'druid/elements/option'
45
+ require 'druid/elements/heading'
46
+ require 'druid/elements/paragraph'
47
+ require 'druid/elements/file_field'
48
+ require 'druid/elements/label'
49
+ require 'druid/elements/area'
50
+ require 'druid/elements/canvas'
51
+ require 'druid/elements/media'
52
+ require 'druid/elements/audio'
53
+ require 'druid/elements/video'
@@ -0,0 +1,29 @@
1
+ module Druid
2
+ module Elements
3
+ class Area < Element
4
+
5
+ #
6
+ # Return the coordinates of the area
7
+ #
8
+ def coords
9
+ attribute(:coords)
10
+ end
11
+
12
+ #
13
+ # Return the shape of the area
14
+ #
15
+ def shape
16
+ attribute(:shape)
17
+ end
18
+
19
+ #
20
+ # Return the href of the area
21
+ #
22
+ def href
23
+ attribute(:href)
24
+ end
25
+ end
26
+
27
+ Druid::Elements.type_to_class[:area] = Druid::Elements::Area
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ module Druid
2
+ module Elements
3
+ class Audio < Media
4
+
5
+ end
6
+
7
+ Druid::Elements.type_to_class[:audio] = Druid::Elements::Audio
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module Druid
2
+ module Elements
3
+ class Canvas < Element
4
+
5
+ #
6
+ # return the width of the canvas
7
+ #
8
+ def width
9
+ attribute(:width).to_i
10
+ end
11
+
12
+ #
13
+ # return the height of the canvas
14
+ #
15
+ def height
16
+ attribute(:height).to_i
17
+ end
18
+ end
19
+
20
+ Druid::Elements.type_to_class[:canvas] = Druid::Elements::Canvas
21
+ end
22
+ end
@@ -144,6 +144,13 @@ module Druid
144
144
  element.focus
145
145
  end
146
146
 
147
+ #
148
+ # get the id of element
149
+ #
150
+ def id
151
+ attribute(:id)
152
+ end
153
+
147
154
  #
148
155
  # Flash the element by temporarily changing the background color
149
156
  #
@@ -151,6 +158,13 @@ module Druid
151
158
  element.flash
152
159
  end
153
160
 
161
+ #
162
+ # hover over the element
163
+ #
164
+ def hover
165
+ element.hover
166
+ end
167
+
154
168
  #
155
169
  # Returns parent element of current element.
156
170
  def parent
@@ -250,7 +264,7 @@ module Druid
250
264
  protected
251
265
 
252
266
  def self.have_to_build_xpath(identifier)
253
- ['table', 'span', 'div', 'td', 'li', 'ol', 'ul', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'label'].include? identifier[:tag_name] and identifier[:name]
267
+ ['table', 'span', 'div', 'td', 'li', 'ol', 'ul', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'label', 'area', 'canvas', 'audio', 'video'].include? identifier[:tag_name] and identifier[:name]
254
268
  end
255
269
 
256
270
  def self.build_xpath_for identifier
@@ -2,6 +2,10 @@ module Druid
2
2
  module Elements
3
3
  class ListItem < Element
4
4
 
5
+ def self.finders
6
+ super + [:text]
7
+ end
8
+
5
9
  end
6
10
 
7
11
  Druid::Elements.tag_to_class[:li] = Druid::Elements::ListItem
@@ -0,0 +1,45 @@
1
+ module Druid
2
+ module Elements
3
+ class Media < Element
4
+
5
+ def autoplay?
6
+ attribute(:autoplay)
7
+ end
8
+
9
+ def has_controls?
10
+ attribute(:controls)
11
+ end
12
+
13
+ def paused?
14
+ attribute(:paused)
15
+ end
16
+
17
+ def duration
18
+ duration = attribute(:duration)
19
+ return duration.to_f if duration
20
+ end
21
+
22
+ def volume
23
+ volume = attribute(:volume)
24
+ return volume.to_i if volume
25
+ end
26
+
27
+ def ended?
28
+ attribute(:ended)
29
+ end
30
+
31
+ def seeking?
32
+ attribute(:seeking)
33
+ end
34
+
35
+ def loop?
36
+ attribute(:loop)
37
+ end
38
+
39
+ def muted?
40
+ attribute(:muted)
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -30,12 +30,18 @@ module Druid
30
30
  end
31
31
 
32
32
  #
33
- # @return [Array<sTRING>] An array of strings representing the text value of the currently selected options.
33
+ # @return [Array<String>] An array of strings representing the text of the currently selected options.
34
34
  #
35
35
  def selected_options
36
36
  element.selected_options.map { |e| e.text }.compact
37
37
  end
38
38
 
39
+ #
40
+ # @return [Array<String>] An array of strings representing the value of the currently selected options.
41
+ def selected_values
42
+ element.selected_options.map { |e| e.value }.compact
43
+ end
44
+
39
45
  #
40
46
  # Returns true if the select list has one or more options where text or label matches the given value.
41
47
  #
@@ -29,6 +29,7 @@ module Druid
29
29
 
30
30
  def find_index_by_title(title)
31
31
  table = element.parent
32
+ table = table.parent if table.tag_name == 'tbody'
32
33
  first_row = table[0]
33
34
  first_row.cells.find_index { |column| column.text.include? title}
34
35
  end