melomel 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/melomel/bridge/messaging.rb +2 -14
- data/lib/melomel/bridge/ui.rb +82 -1
- data/lib/melomel/cucumber/alert_steps.rb +29 -0
- data/lib/melomel/cucumber/button_steps.rb +11 -0
- data/lib/melomel/cucumber/color_picker_steps.rb +12 -0
- data/lib/melomel/cucumber/data_grid_steps.rb +62 -0
- data/lib/melomel/cucumber/date_steps.rb +16 -0
- data/lib/melomel/cucumber/list_steps.rb +24 -0
- data/lib/melomel/cucumber/slider_steps.rb +14 -0
- data/lib/melomel/cucumber/text_steps.rb +11 -0
- data/lib/melomel/cucumber.rb +127 -0
- data/lib/melomel/date.rb +19 -0
- data/lib/melomel/flex.rb +45 -0
- data/lib/melomel/object_proxy.rb +18 -0
- data/lib/melomel/version.rb +1 -1
- data/lib/melomel.rb +4 -2
- data/lib/object.rb +30 -0
- metadata +16 -5
- data/lib/melomel/ui.rb +0 -42
@@ -113,22 +113,10 @@ module Melomel
|
|
113
113
|
#
|
114
114
|
###########################################################################
|
115
115
|
|
116
|
-
# Creates an object proxy from a hash
|
117
|
-
def create_hash(hash)
|
118
|
-
proxy = create_object('Object')
|
119
|
-
hash.each_pair do |k,v|
|
120
|
-
v = create_hash(v) if !v.nil? && v.is_a?(Hash)
|
121
|
-
proxy.set_property(k, v)
|
122
|
-
end
|
123
|
-
return proxy
|
124
|
-
end
|
125
|
-
|
126
116
|
# Formats a Ruby value into an XML message
|
127
117
|
def format_message_value(xml, value)
|
128
|
-
# Automatically convert simple
|
129
|
-
|
130
|
-
value = create_hash(value)
|
131
|
-
end
|
118
|
+
# Automatically convert simple objects to proxies.
|
119
|
+
value = value.to_object_proxy(self) unless value.nil?
|
132
120
|
|
133
121
|
if value.nil?
|
134
122
|
xml['dataType'] = 'null'
|
data/lib/melomel/bridge/ui.rb
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
module Melomel
|
3
3
|
class Bridge
|
4
4
|
# Finds a list of display objects matching a class and hash of properties.
|
5
|
+
#
|
6
|
+
# class_name - The type of objects to search for.
|
7
|
+
# root - The object to start searching from. (Defaults to the stage).
|
8
|
+
# properties - A list of properties to match on each object.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
#
|
12
|
+
# bridge.find_all('mx.controls.Button', :label => 'Click me')
|
13
|
+
# # => [<Melomel::ObjectProxy>, <Melomel::ObjectProxy>]
|
14
|
+
#
|
15
|
+
# Returns a list of display objects contained by root that match the
|
16
|
+
# properties and class specified.
|
5
17
|
def find_all(class_name, root={}, properties={})
|
6
18
|
# Merge hashes if no root is specified
|
7
19
|
if root.is_a?(Hash)
|
@@ -12,8 +24,26 @@ module Melomel
|
|
12
24
|
# Retrieve object
|
13
25
|
get_class('melomel.core.UI').findAll(class_name, root, properties)
|
14
26
|
end
|
27
|
+
|
28
|
+
def find_all!(class_name, root={}, properties={})
|
29
|
+
objects = find_all(class_name, root, properties)
|
30
|
+
raise MelomelError.new("No objects found") if objects.empty?
|
31
|
+
return objects
|
32
|
+
end
|
15
33
|
|
16
|
-
# Finds
|
34
|
+
# Finds the first display object matching a class and hash of properties.
|
35
|
+
#
|
36
|
+
# class_name - The type of object to search for.
|
37
|
+
# root - The object to start searching from. (Defaults to the stage).
|
38
|
+
# properties - A list of properties to match on the object.
|
39
|
+
#
|
40
|
+
# Example:
|
41
|
+
#
|
42
|
+
# bridge.find('mx.controls.Button', :label => 'Click me')
|
43
|
+
# # => <Melomel::ObjectProxy>
|
44
|
+
#
|
45
|
+
# Returns the first display object contained by root that matches the
|
46
|
+
# properties and class specified.
|
17
47
|
def find(class_name, root={}, properties={})
|
18
48
|
# Merge hashes if no root is specified
|
19
49
|
if root.is_a?(Hash)
|
@@ -25,6 +55,45 @@ module Melomel
|
|
25
55
|
get_class('melomel.core.UI').find(class_name, root, properties)
|
26
56
|
end
|
27
57
|
|
58
|
+
def find!(class_name, root={}, properties={})
|
59
|
+
object = find(class_name, root, properties)
|
60
|
+
raise MelomelError.new("No object found") if object.nil?
|
61
|
+
return object
|
62
|
+
end
|
63
|
+
|
64
|
+
# Finds a component based on the label of a nearby component. This works
|
65
|
+
# by first finding a Halo or Spark label component and then recursively
|
66
|
+
# searching the label's parent's children for a component of a given class.
|
67
|
+
#
|
68
|
+
# class_name - The type of object to search for.
|
69
|
+
# label_text - The label text to search for.
|
70
|
+
# root - The object to start searching from. (Defaults to the stage).
|
71
|
+
# properties - A list of properties to match on the object.
|
72
|
+
#
|
73
|
+
# Example:
|
74
|
+
#
|
75
|
+
# bridge.find_labeled('mx.controls.TextInput', 'First Name')
|
76
|
+
# # => <Melomel::ObjectProxy>
|
77
|
+
#
|
78
|
+
# Returns the first display object which is inside the parent of a given
|
79
|
+
# label.
|
80
|
+
def find_labeled(class_name, label_text, root={}, properties={})
|
81
|
+
# Merge hashes if no root is specified
|
82
|
+
if root.is_a?(Hash)
|
83
|
+
properties.merge!(root)
|
84
|
+
root = nil
|
85
|
+
end
|
86
|
+
|
87
|
+
# Retrieve object
|
88
|
+
get_class('melomel.core.UI').findLabeled(class_name, label_text, root, properties)
|
89
|
+
end
|
90
|
+
|
91
|
+
def find_labeled!(class_name, label_text, root={}, properties={})
|
92
|
+
object = find_labeled(class_name, label_text, root, properties)
|
93
|
+
raise MelomelError.new("No object found") if object.nil?
|
94
|
+
return object
|
95
|
+
end
|
96
|
+
|
28
97
|
|
29
98
|
# Imitates a click on a component
|
30
99
|
def click(component, properties={})
|
@@ -51,5 +120,17 @@ module Melomel
|
|
51
120
|
def key_press(component, char, properties={})
|
52
121
|
get_class('melomel.core.UI').keyPress(component, char, properties)
|
53
122
|
end
|
123
|
+
|
124
|
+
|
125
|
+
# Generates a list of labels created by a data control or column based on a
|
126
|
+
# data set.
|
127
|
+
#
|
128
|
+
# component - The control or column which has an itemToLabel() method.
|
129
|
+
# data - The data set to generate labels from.
|
130
|
+
#
|
131
|
+
# Returns a Ruby array of labels.
|
132
|
+
def items_to_labels!(component, data)
|
133
|
+
get_class('melomel.core.UI').itemsToLabels!(component, data)
|
134
|
+
end
|
54
135
|
end
|
55
136
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
When /^I click the "([^"]*)" button on the alert$/ do |label|
|
2
|
+
classes = Melomel::Flex.get_component_classes('alert')
|
3
|
+
alert = Melomel.find!(classes)
|
4
|
+
button = Melomel::Cucumber.find_by_label!('mx.controls.Button', label, alert)
|
5
|
+
Melomel.click(button)
|
6
|
+
end
|
7
|
+
|
8
|
+
Then /^I should see an alert$/ do
|
9
|
+
classes = Melomel::Flex.get_component_classes('alert')
|
10
|
+
Melomel.find!(classes)
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^I should see an alert with the title: "([^"]*)"$/ do |title|
|
14
|
+
classes = Melomel::Flex.get_component_classes('alert')
|
15
|
+
alert = Melomel.find!(classes)
|
16
|
+
alert.title.should == title
|
17
|
+
end
|
18
|
+
|
19
|
+
Then /^I should see an alert with the message: "([^"]*)"$/ do |message|
|
20
|
+
classes = Melomel::Flex.get_component_classes('alert')
|
21
|
+
alert = Melomel.find!(classes)
|
22
|
+
alert.text.should == message
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^I should see an alert with the following message:$/ do |message|
|
26
|
+
classes = Melomel::Flex.get_component_classes('alert')
|
27
|
+
alert = Melomel.find!(classes)
|
28
|
+
alert.text.should == message
|
29
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
When /^I click the "([^"]*)" (button|check box|radio button)$/ do |name, type|
|
2
|
+
classes = Melomel::Flex.get_component_classes(type)
|
3
|
+
button = Melomel::Cucumber.find_by_label!(classes, name)
|
4
|
+
Melomel.click(button)
|
5
|
+
end
|
6
|
+
|
7
|
+
Then /^I should see the "([^"]*)" (button|check box|radio button) (not )?selected$/ do |name, type, neg|
|
8
|
+
classes = Melomel::Flex.get_component_classes(type)
|
9
|
+
button = Melomel::Cucumber.find_by_label!(classes, name)
|
10
|
+
button.selected.should == neg.nil?
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
When /^I set the "([^"]*)" color picker to "#([0-9A-Fa-f]{6})"$/ do |name, color|
|
2
|
+
classes = Melomel::Flex.get_component_classes('color picker')
|
3
|
+
picker = Melomel::Cucumber.find_labeled!(classes, name)
|
4
|
+
picker.selectedColor = color.hex
|
5
|
+
end
|
6
|
+
|
7
|
+
Then /^I should see the "([^"]*)" color picker set to "#([0-9A-Fa-f]{6})"$/ do |name, color|
|
8
|
+
classes = Melomel::Flex.get_component_classes('color picker')
|
9
|
+
picker = Melomel::Cucumber.find_labeled!(classes, name)
|
10
|
+
sprintf('%06X', picker.selectedColor).should == color
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
When /^I select "([^"]*)" on the "([^"]*)" data grid$/ do |value, name|
|
2
|
+
classes = Melomel::Flex.get_component_classes('data grid')
|
3
|
+
grid = Melomel::Cucumber.find_labeled!(classes, name)
|
4
|
+
|
5
|
+
# Retrieve data and take off header row
|
6
|
+
data = Melomel::Cucumber.get_grid_data(grid)[1..-1]
|
7
|
+
|
8
|
+
# Loop data and check for matches
|
9
|
+
index = nil
|
10
|
+
data.each_index do |i|
|
11
|
+
row = data[i]
|
12
|
+
row.each do |cell|
|
13
|
+
if cell.strip == value
|
14
|
+
index = i
|
15
|
+
break
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
break unless index.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
# If we couldn't find a matching cell then throw an error
|
23
|
+
raise "Cannot find '#{value}' on data grid" if index.nil?
|
24
|
+
|
25
|
+
grid.selectedIndex = index
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
Then /^I should see "([^"]*)" selected on the "([^"]*)" data grid$/ do |value, name|
|
30
|
+
classes = Melomel::Flex.get_component_classes('data grid')
|
31
|
+
grid = Melomel::Cucumber.find_labeled!(classes, name)
|
32
|
+
|
33
|
+
# Retrieve data and take off header row
|
34
|
+
data = Melomel::Cucumber.get_grid_data(grid)[1..-1]
|
35
|
+
|
36
|
+
# Loop data and check for matches
|
37
|
+
index = nil
|
38
|
+
data.each_index do |i|
|
39
|
+
row = data[i]
|
40
|
+
row.each do |cell|
|
41
|
+
if cell.strip == value
|
42
|
+
index = i
|
43
|
+
break
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
break unless index.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
grid.selectedIndex.should == index
|
51
|
+
end
|
52
|
+
|
53
|
+
Then /^I should see the following data in the "([^"]*)" data grid:$/ do |name, table|
|
54
|
+
classes = Melomel::Flex.get_component_classes('data grid')
|
55
|
+
grid = Melomel::Cucumber.find_labeled!(classes, name)
|
56
|
+
data = Melomel::Cucumber.get_grid_data(grid)
|
57
|
+
|
58
|
+
# Trim whitespace
|
59
|
+
data.each {|row| row.each {|cell| cell.strip!}}
|
60
|
+
|
61
|
+
table.diff!(data)
|
62
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
When /^I set the "([^"]*)" (date chooser|date field) to "(\d{1,2}\/\d{1,2}\/\d{4})"$/ do |name, type, date_string|
|
2
|
+
classes = Melomel::Flex.get_component_classes(type)
|
3
|
+
component = Melomel::Cucumber.find_labeled!(classes, name)
|
4
|
+
component.selectedDate = Melomel::Date.parse(date_string)
|
5
|
+
end
|
6
|
+
|
7
|
+
Then /^I should see the "([^"]*)" (date chooser|date field) set to "(\d{1,2}\/\d{1,2}\/\d{4})"$/ do |name, type, date_string|
|
8
|
+
classes = Melomel::Flex.get_component_classes(type)
|
9
|
+
component = Melomel::Cucumber.find_labeled!(classes, name)
|
10
|
+
date = Melomel::Date.parse(date_string)
|
11
|
+
|
12
|
+
component.selectedDate.should_not be_nil
|
13
|
+
date.should_not be_nil
|
14
|
+
component.selectedDate.toLocaleDateString().should == date.toLocaleDateString()
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
When /^I select "([^"]*)" on the "([^"]*)" (combo box|list)$/ do |value, name, type|
|
2
|
+
classes = Melomel::Flex.get_component_classes(type)
|
3
|
+
list = Melomel::Cucumber.find_labeled!(classes, name)
|
4
|
+
labels = Melomel.items_to_labels!(list, list.dataProvider)
|
5
|
+
|
6
|
+
# Loop over labels and set the selected index when we find a match
|
7
|
+
index = nil
|
8
|
+
labels.length.times do |i|
|
9
|
+
if labels[i] == value
|
10
|
+
index = i
|
11
|
+
end
|
12
|
+
end
|
13
|
+
raise "Cannot find '#{value}' on #{type}" if index.nil?
|
14
|
+
|
15
|
+
list.selectedIndex = index
|
16
|
+
end
|
17
|
+
|
18
|
+
Then /^I should see "([^"]*)" selected on the "([^"]*)" (combo box|list)$/ do |value, name, type|
|
19
|
+
classes = Melomel::Flex.get_component_classes(type)
|
20
|
+
list = Melomel::Cucumber.find_labeled!(classes, name)
|
21
|
+
label = list.itemToLabel(list.selectedItem)
|
22
|
+
label.should == value
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
When /^I set the "([^"]*)" (slider) to "([^"]*)"$/ do |name, type, value|
|
2
|
+
classes = Melomel::Flex.get_component_classes(type)
|
3
|
+
slider = Melomel::Cucumber.find_labeled!(classes, name)
|
4
|
+
value = value.index('.') ? value.to_f : value.to_i
|
5
|
+
slider.value = value
|
6
|
+
end
|
7
|
+
|
8
|
+
Then /^I should see the "([^"]*)" (slider) set to "([^"]*)"$/ do |name, type, value|
|
9
|
+
classes = Melomel::Flex.get_component_classes(type)
|
10
|
+
slider = Melomel::Cucumber.find_labeled!(classes, name)
|
11
|
+
value = value.index('.') ? value.to_f : value.to_i
|
12
|
+
slider.value.should == value
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
When /^I type "([^"]*)" in the "([^"]*)" (text field|text area)$/ do |text, name, type|
|
2
|
+
classes = Melomel::Flex.get_component_classes(type)
|
3
|
+
component = Melomel::Cucumber.find_labeled!(classes, name)
|
4
|
+
component.text = text
|
5
|
+
end
|
6
|
+
|
7
|
+
Then /^I should see "([^"]*)" in the "([^"]*)" (text field|text area|label)$/ do |text, name, type|
|
8
|
+
classes = Melomel::Flex.get_component_classes(type)
|
9
|
+
component = Melomel::Cucumber.find_labeled!(classes, name)
|
10
|
+
component.text.should == text
|
11
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'cucumber'
|
2
|
+
require 'melomel'
|
3
|
+
Dir.glob(File.dirname(__FILE__) + '/cucumber/*', &method(:require))
|
4
|
+
|
5
|
+
# This class holds utility methods for running Cucumber steps.
|
6
|
+
module Melomel
|
7
|
+
class Cucumber
|
8
|
+
# Finds a component by id.
|
9
|
+
#
|
10
|
+
# class_name - The class or classes to match on.
|
11
|
+
# id - The id of the component.
|
12
|
+
# root - The root component to search from. Defaults to the stage.
|
13
|
+
# properties - Additional properties to search on.
|
14
|
+
#
|
15
|
+
# Returns a component matching the id and the additional properties.
|
16
|
+
def self.find_by_id!(class_name, id, root={}, properties={})
|
17
|
+
properties['id'] = id
|
18
|
+
Melomel.find!(class_name, root, properties)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Finds a component by label. If the first character is a "#" then the
|
22
|
+
# component should be found by id. Otherwise it is found by label.
|
23
|
+
#
|
24
|
+
# class_name - The class or classes to match on.
|
25
|
+
# label - The label of the component.
|
26
|
+
# root - The root component to search from. Defaults to the stage.
|
27
|
+
# properties - Additional properties to search on.
|
28
|
+
#
|
29
|
+
# Returns a component matching the label and the additional properties.
|
30
|
+
def self.find_by_label!(class_name, label, root={}, properties={})
|
31
|
+
set_properties_key(properties, 'label', label)
|
32
|
+
Melomel.find!(class_name, root, properties)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Finds a component that shares the same parent as a given label. If the
|
36
|
+
# first character is a "#" then the component should be found by id.
|
37
|
+
# Otherwise it is found by label.
|
38
|
+
#
|
39
|
+
# class_name - The class or classes to match on.
|
40
|
+
# label - The label text.
|
41
|
+
# root - The root component to search from. Defaults to the stage.
|
42
|
+
# properties - Additional properties to search on.
|
43
|
+
#
|
44
|
+
# Returns a component labeled by another component.
|
45
|
+
def self.find_labeled!(class_name, label, root={}, properties={})
|
46
|
+
if label.index('#') == 0
|
47
|
+
find_by_id!(class_name, label[1..-1], root, properties)
|
48
|
+
else
|
49
|
+
Melomel.find_labeled!(class_name, label, root, properties)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Finds a component by title. If the first character is a "#" then the
|
54
|
+
# component should be found by id. Otherwise it is found by title.
|
55
|
+
#
|
56
|
+
# class_name - The class or classes to match on.
|
57
|
+
# title - The title of the component.
|
58
|
+
# root - The root component to search from. Defaults to the stage.
|
59
|
+
# properties - Additional properties to search on.
|
60
|
+
#
|
61
|
+
# Returns a component matching the title and the additional properties.
|
62
|
+
def self.find_by_title!(class_name, title, root={}, properties={})
|
63
|
+
set_properties_key(properties, 'title', title)
|
64
|
+
Melomel.find!(class_name, root, properties)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Finds a component by text. If the first character is a "#" then the
|
68
|
+
# component should be found by id. Otherwise it is found by text.
|
69
|
+
#
|
70
|
+
# class_name - The class or classes to match on.
|
71
|
+
# text - The text property of the component.
|
72
|
+
# root - The root component to search from. Defaults to the stage.
|
73
|
+
# properties - Additional properties to search on.
|
74
|
+
#
|
75
|
+
# Returns a component matching the text and the additional properties.
|
76
|
+
def self.find_by_text!(class_name, text, root={}, properties={})
|
77
|
+
set_properties_key(properties, 'text', text)
|
78
|
+
Melomel.find!(class_name, root, properties)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Sets the key in the properties hash. If the first character is "#" then
|
82
|
+
# the key is "id". Otherwise it is set to the value of "key".
|
83
|
+
#
|
84
|
+
# properties - The properties hash.
|
85
|
+
# key - The name of the key to set.
|
86
|
+
# name - The name of the component.
|
87
|
+
#
|
88
|
+
# Returns nothing.
|
89
|
+
def self.set_properties_key(properties, key, name)
|
90
|
+
if name.index('#') == 0
|
91
|
+
properties['id'] = name[1..-1]
|
92
|
+
else
|
93
|
+
properties[key] = name
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Retrieves grid data as a 2D array of rows of columns. The first row
|
98
|
+
# contains the grid's header.
|
99
|
+
#
|
100
|
+
# grid - The grid to generate the table from.
|
101
|
+
#
|
102
|
+
# Returns a 2D array of rows of columns of data.
|
103
|
+
def self.get_grid_data(grid)
|
104
|
+
# Retrieve as columns of rows
|
105
|
+
data = []
|
106
|
+
grid.columns.length.times do |i|
|
107
|
+
column_data = []
|
108
|
+
column = grid.columns[i]
|
109
|
+
labels = Melomel.items_to_labels!(column, grid.dataProvider)
|
110
|
+
|
111
|
+
# Add column header
|
112
|
+
column_data << column.headerText
|
113
|
+
|
114
|
+
# Add label data
|
115
|
+
labels.length.times do |j|
|
116
|
+
column_data << labels[j]
|
117
|
+
end
|
118
|
+
|
119
|
+
# Add column data to data set
|
120
|
+
data << column_data
|
121
|
+
end
|
122
|
+
|
123
|
+
# Transpose and return
|
124
|
+
return data.transpose()
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/lib/melomel/date.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Melomel
|
2
|
+
# This class contains helper methods for working with Flash dates.
|
3
|
+
class Date
|
4
|
+
# Parses a date.
|
5
|
+
#
|
6
|
+
# text - The date string to parse.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# Melomel::Date.parse('02/04/2010') # => <Melomel::ObjectProxy>
|
11
|
+
#
|
12
|
+
# Returns a proxy to a date object in Flash.
|
13
|
+
def self.parse(text)
|
14
|
+
date = Melomel.create_object!('Date')
|
15
|
+
date.time = Melomel.get_class!('Date').parse(text)
|
16
|
+
date
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/melomel/flex.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Melomel
|
2
|
+
# This class contains helper methods for working with Flex components.
|
3
|
+
class Flex
|
4
|
+
# Retrieves a list of classes associated with a commonly named component.
|
5
|
+
#
|
6
|
+
# name - The common name of the component.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# Melomel.get_component_classes('button')
|
11
|
+
# # => ['mx.controls.Button', 'spark.components.Button']
|
12
|
+
#
|
13
|
+
# Returns a list of classes associated with a component's common name.
|
14
|
+
def self.get_component_classes(name)
|
15
|
+
case name.downcase
|
16
|
+
when 'alert' then ['mx.controls.Alert']
|
17
|
+
when 'button' then ['mx.controls.Button', 'spark.components.supportClasses.ButtonBase']
|
18
|
+
when 'check box' then ['mx.controls.CheckBox', 'spark.components.CheckBox']
|
19
|
+
when 'color picker' then ['mx.controls.ColorPicker']
|
20
|
+
when 'combo box' then ['mx.controls.ComboBox', 'spark.components.ComboBox']
|
21
|
+
when 'data grid' then ['mx.controls.DataGrid']
|
22
|
+
when 'date chooser' then ['mx.controls.DateChooser']
|
23
|
+
when 'date field' then ['mx.controls.DateField']
|
24
|
+
when 'scroll bar' then ['mx.controls.HScrollBar', 'mx.controls.VScrollBar', 'spark.components.HScrollBar', 'spark.components.VScrollBar']
|
25
|
+
when 'slider' then ['mx.controls.HSlider', 'mx.controls.VSlider', 'spark.components.HSlider', 'spark.components.VSlider']
|
26
|
+
when 'image' then ['mx.controls.Image']
|
27
|
+
when 'label' then ['mx.controls.Label', 'spark.components.Label', 'spark.components.RichText']
|
28
|
+
when 'list' then ['mx.controls.List', 'spark.components.List']
|
29
|
+
when 'menu' then ['mx.controls.Menu']
|
30
|
+
when 'menu bar' then ['mx.controls.MenuBar']
|
31
|
+
when 'panel' then ['mx.containers.Panel', 'spark.components.Panel']
|
32
|
+
when 'stepper' then ['mx.controls.NumericStepper', 'spark.components.Spinner']
|
33
|
+
when 'pop up button' then ['mx.controls.PopUpButton']
|
34
|
+
when 'pop up menu button' then ['mx.controls.PopUpMenuButton']
|
35
|
+
when 'progress bar' then ['mx.controls.ProgressBar']
|
36
|
+
when 'radio button' then ['mx.controls.RadioButton', 'spark.components.RadioButton']
|
37
|
+
when 'rich text area' then ['mx.controls.RichTextEditor', 'spark.components.RichEditableText']
|
38
|
+
when 'text field' then ['mx.controls.TextInput', 'spark.components.TextInput']
|
39
|
+
when 'text area' then ['mx.controls.TextArea', 'spark.components.TextArea']
|
40
|
+
when 'tool tip' then ['mx.controls.ToolTip']
|
41
|
+
when 'tree' then ['mx.controls.Tree']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/melomel/object_proxy.rb
CHANGED
@@ -72,5 +72,23 @@ module Melomel
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
|
+
|
76
|
+
# Array accessor.
|
77
|
+
def [](index)
|
78
|
+
if index.is_a?(Fixnum)
|
79
|
+
get_property("[#{index}]")
|
80
|
+
else
|
81
|
+
get_property(index.to_s)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Array mutator.
|
86
|
+
def []=(index, value)
|
87
|
+
if index.is_a?(Fixnum)
|
88
|
+
set_property("[#{index}]", value)
|
89
|
+
else
|
90
|
+
set_property(index.to_s, value)
|
91
|
+
end
|
92
|
+
end
|
75
93
|
end
|
76
94
|
end
|
data/lib/melomel/version.rb
CHANGED
data/lib/melomel.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless $:.index(File.dirname(__FILE__))
|
2
2
|
|
3
|
+
require 'object'
|
3
4
|
require 'melomel/bridge'
|
5
|
+
require 'melomel/date'
|
4
6
|
require 'melomel/error'
|
7
|
+
require 'melomel/flex'
|
5
8
|
require 'melomel/object_proxy'
|
6
|
-
require 'melomel/ui'
|
7
9
|
require 'melomel/version'
|
8
10
|
|
9
11
|
# This class acts as a singleton instance of the bridge. This is typically the
|
@@ -25,7 +27,7 @@ module Melomel
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def method_missing(method, *args)
|
28
|
-
@bridge.
|
30
|
+
@bridge.__send__(method.to_sym, *args)
|
29
31
|
end
|
30
32
|
|
31
33
|
# Retrieves a reference to a class
|
data/lib/object.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
class Object
|
2
|
+
# Recursively generates an object proxy for the object if it is a Hash or
|
3
|
+
# and Array.
|
4
|
+
#
|
5
|
+
# bridge - The bridge to use when generating a proxy.
|
6
|
+
#
|
7
|
+
# Returns a Melomel::ObjectProxy if it is a Hash or an Array. Otherwise
|
8
|
+
# returns the object itself.
|
9
|
+
def to_object_proxy(bridge)
|
10
|
+
proxy = self
|
11
|
+
|
12
|
+
# Convert each key/value pair in a Hash
|
13
|
+
if self.is_a?(Hash)
|
14
|
+
proxy = bridge.create_object('Object')
|
15
|
+
each_pair do |k,v|
|
16
|
+
v = v.to_object_proxy(bridge) unless v.nil?
|
17
|
+
proxy.set_property!(k, v)
|
18
|
+
end
|
19
|
+
# Convert each item in an Array.
|
20
|
+
elsif is_a?(Array)
|
21
|
+
proxy = bridge.create_object('Array')
|
22
|
+
each do |item|
|
23
|
+
item = item.to_object_proxy(bridge) unless item.nil?
|
24
|
+
proxy.push!(item)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
return proxy
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: melomel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ben Johnson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-08 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -79,11 +79,22 @@ files:
|
|
79
79
|
- lib/melomel/bridge/messaging.rb
|
80
80
|
- lib/melomel/bridge/ui.rb
|
81
81
|
- lib/melomel/bridge.rb
|
82
|
+
- lib/melomel/cucumber/alert_steps.rb
|
83
|
+
- lib/melomel/cucumber/button_steps.rb
|
84
|
+
- lib/melomel/cucumber/color_picker_steps.rb
|
85
|
+
- lib/melomel/cucumber/data_grid_steps.rb
|
86
|
+
- lib/melomel/cucumber/date_steps.rb
|
87
|
+
- lib/melomel/cucumber/list_steps.rb
|
88
|
+
- lib/melomel/cucumber/slider_steps.rb
|
89
|
+
- lib/melomel/cucumber/text_steps.rb
|
90
|
+
- lib/melomel/cucumber.rb
|
91
|
+
- lib/melomel/date.rb
|
82
92
|
- lib/melomel/error.rb
|
93
|
+
- lib/melomel/flex.rb
|
83
94
|
- lib/melomel/object_proxy.rb
|
84
|
-
- lib/melomel/ui.rb
|
85
95
|
- lib/melomel/version.rb
|
86
96
|
- lib/melomel.rb
|
97
|
+
- lib/object.rb
|
87
98
|
- README.md
|
88
99
|
- CHANGELOG.md
|
89
100
|
- test/helper.rb
|
data/lib/melomel/ui.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# This class provides ease of use utility methods for finding display objects
|
2
|
-
# and interacting with them.
|
3
|
-
module Melomel
|
4
|
-
class << self
|
5
|
-
# Finds all display objects matching a class and hash of properties.
|
6
|
-
def find_all(class_name, root={}, properties={})
|
7
|
-
Melomel.bridge.find_all(class_name, root, properties)
|
8
|
-
end
|
9
|
-
|
10
|
-
# Finds a display object by class and properties.
|
11
|
-
def find(class_name, root={}, properties={})
|
12
|
-
Melomel.bridge.find(class_name, root, properties)
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
# Imitates a click on a component
|
17
|
-
def click(component, properties={})
|
18
|
-
Melomel.bridge.click(component, properties)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Imitates a double click on a component
|
22
|
-
def double_click(component, properties={})
|
23
|
-
Melomel.bridge.double_click(component, properties)
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
# Imitates a key down on a component
|
28
|
-
def key_down(component, char, properties={})
|
29
|
-
Melomel.bridge.key_down(component, char, properties)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Imitates a key up on a component
|
33
|
-
def key_up(component, char, properties={})
|
34
|
-
Melomel.bridge.key_up(component, char, properties)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Imitates a key press on a component
|
38
|
-
def key_press(component, char, properties={})
|
39
|
-
Melomel.bridge.key_press(component, char, properties)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|