mohawk 0.1.4 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/.gitmodules +3 -3
  2. data/Changelog +6 -1
  3. data/Rakefile +2 -3
  4. data/cucumber.yml +1 -1
  5. data/features/combo_box.feature +8 -0
  6. data/features/menu.feature +8 -0
  7. data/features/step_definitions/button_steps.rb +1 -1
  8. data/features/step_definitions/combo_box_steps.rb +13 -1
  9. data/features/step_definitions/control_steps.rb +1 -1
  10. data/features/step_definitions/menu_steps.rb +7 -2
  11. data/features/support/WindowsForms.exe +0 -0
  12. data/features/support/screens/main_screen.rb +3 -0
  13. data/features/table.feature +7 -7
  14. data/features/text.feature +4 -0
  15. data/lib/mohawk/accessors.rb +3 -0
  16. data/lib/mohawk/adapters/uia/button.rb +14 -0
  17. data/lib/mohawk/adapters/uia/checkbox.rb +22 -0
  18. data/lib/mohawk/adapters/uia/control.rb +83 -0
  19. data/lib/mohawk/adapters/uia/element_locator.rb +19 -0
  20. data/lib/mohawk/adapters/uia/menu_item.rb +48 -0
  21. data/lib/mohawk/adapters/uia/radio.rb +22 -0
  22. data/lib/mohawk/adapters/uia/select_list.rb +53 -0
  23. data/lib/mohawk/adapters/uia/spinner.rb +30 -0
  24. data/lib/mohawk/adapters/uia/tab_control.rb +26 -0
  25. data/lib/mohawk/adapters/uia/table.rb +62 -0
  26. data/lib/mohawk/adapters/uia/table_row.rb +73 -0
  27. data/lib/mohawk/adapters/uia/text_box.rb +47 -0
  28. data/lib/mohawk/adapters/uia/tree_view.rb +22 -0
  29. data/lib/mohawk/adapters/uia/value_control.rb +20 -0
  30. data/lib/mohawk/adapters/uia/window.rb +64 -0
  31. data/lib/mohawk/adapters/uia_adapter.rb +36 -50
  32. data/lib/mohawk/version.rb +1 -1
  33. data/lib/mohawk/waiter.rb +18 -0
  34. data/lib/mohawk/win_32.rb +12 -0
  35. data/lib/mohawk.rb +26 -14
  36. data/mohawk.gemspec +2 -2
  37. data/spec/lib/mohawk/adapters/uia/control_spec.rb +46 -0
  38. data/spec/lib/mohawk/adapters/uia/table_row_spec.rb +36 -0
  39. data/spec/lib/mohawk/waiter_spec.rb +39 -0
  40. data/spec/lib/mohawk_spec.rb +115 -92
  41. data/spec/lib/navigation_spec.rb +14 -20
  42. data/spec/spec_helper.rb +1 -1
  43. metadata +49 -67
  44. data/lib/mohawk/accessors/button.rb +0 -20
  45. data/lib/mohawk/accessors/checkbox.rb +0 -24
  46. data/lib/mohawk/accessors/combo.rb +0 -37
  47. data/lib/mohawk/accessors/control.rb +0 -24
  48. data/lib/mohawk/accessors/label.rb +0 -15
  49. data/lib/mohawk/accessors/link.rb +0 -9
  50. data/lib/mohawk/accessors/menu_item.rb +0 -21
  51. data/lib/mohawk/accessors/radio.rb +0 -19
  52. data/lib/mohawk/accessors/spinner.rb +0 -27
  53. data/lib/mohawk/accessors/table.rb +0 -69
  54. data/lib/mohawk/accessors/table_row.rb +0 -62
  55. data/lib/mohawk/accessors/tabs.rb +0 -30
  56. data/lib/mohawk/accessors/text.rb +0 -29
  57. data/lib/mohawk/accessors/tree_view.rb +0 -32
  58. data/spec/lib/mohawk/accessors/button_spec.rb +0 -45
  59. data/spec/lib/mohawk/accessors/checkbox_spec.rb +0 -46
  60. data/spec/lib/mohawk/accessors/combo_spec.rb +0 -119
  61. data/spec/lib/mohawk/accessors/control_spec.rb +0 -47
  62. data/spec/lib/mohawk/accessors/label_spec.rb +0 -29
  63. data/spec/lib/mohawk/accessors/link_spec.rb +0 -34
  64. data/spec/lib/mohawk/accessors/menu_spec.rb +0 -32
  65. data/spec/lib/mohawk/accessors/radio_spec.rb +0 -35
  66. data/spec/lib/mohawk/accessors/spinner_spec.rb +0 -43
  67. data/spec/lib/mohawk/accessors/table_row_spec.rb +0 -28
  68. data/spec/lib/mohawk/accessors/table_spec.rb +0 -262
  69. data/spec/lib/mohawk/accessors/tabs_spec.rb +0 -58
  70. data/spec/lib/mohawk/accessors/text_spec.rb +0 -51
  71. data/spec/lib/mohawk/accessors/tree_view_spec.rb +0 -98
  72. data/spec/lib/mohawk/adapters/uia_adapter_spec.rb +0 -55
  73. data/spec/table_stubber.rb +0 -55
@@ -1,21 +0,0 @@
1
- module Mohawk
2
- module Accessors
3
- class MenuItem
4
- def initialize(adapter, locator)
5
- @adapter = adapter
6
- @locator = locator
7
- end
8
-
9
- def select
10
- menu_item.open
11
- end
12
-
13
- private
14
- def menu_item
15
- @locator[:path].reduce(@adapter.window) do |the_menu, menu_item|
16
- the_menu.menu :text => menu_item
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,19 +0,0 @@
1
- module Mohawk
2
- module Accessors
3
- class Radio
4
- attr_reader :view
5
-
6
- def initialize(adapter, locator)
7
- @view = adapter.window.radio(locator)
8
- end
9
-
10
- def set
11
- @view.set
12
- end
13
-
14
- def set?
15
- @view.set?
16
- end
17
- end
18
- end
19
- end
@@ -1,27 +0,0 @@
1
- module Mohawk
2
- module Accessors
3
- class Spinner
4
- attr_reader :view
5
-
6
- def initialize(adapter, locator)
7
- @view = adapter.window.spinner(locator)
8
- end
9
-
10
- def value
11
- @view.value
12
- end
13
-
14
- def value=(value)
15
- @view.set value
16
- end
17
-
18
- def increment
19
- @view.increment
20
- end
21
-
22
- def decrement
23
- @view.decrement
24
- end
25
- end
26
- end
27
- end
@@ -1,69 +0,0 @@
1
- module Mohawk
2
- module Accessors
3
- class Table
4
- attr_reader :view
5
-
6
- include Enumerable
7
-
8
- def initialize(adapter, locator)
9
- @view = adapter.window.table(locator)
10
- end
11
-
12
- def select(which_item)
13
- find_row_with(which_item).select
14
- end
15
-
16
- def add(which_item)
17
- find_row_with(which_item).add_to_selection
18
- end
19
-
20
- def clear_all
21
- view.selected_rows.each(&:clear)
22
- end
23
-
24
- def clear(which_item)
25
- find_row_with(which_item).clear
26
- end
27
-
28
- def find_row_with(row_info)
29
- found_row = case row_info
30
- when Hash
31
- find_by_hash(row_info)
32
- when Fixnum
33
- find_by_index(row_info)
34
- when String
35
- find_by_value(row_info)
36
- end
37
- raise "A row with #{row_info} was not found" unless found_row
38
- found_row
39
- end
40
-
41
- def headers
42
- RAutomation::Adapter::MsUia::UiaDll.table_headers(view.search_information)
43
- end
44
-
45
- def [](row)
46
- TableRow.new(self, row)
47
- end
48
-
49
- def each
50
- view.row_count.times.map do |row|
51
- yield TableRow.new(self, row)
52
- end
53
- end
54
-
55
- private
56
- def find_by_index(which_item)
57
- self[which_item]
58
- end
59
-
60
- def find_by_value(which_item)
61
- find { |r| r.row.value == which_item }
62
- end
63
-
64
- def find_by_hash(row_info)
65
- find { |r| r.all_match? row_info }
66
- end
67
- end
68
- end
69
- end
@@ -1,62 +0,0 @@
1
- module Mohawk
2
- module Accessors
3
- class TableRow
4
- include RAutomation::Adapter::MsUia
5
-
6
- attr_reader :row
7
-
8
- def initialize(table, row_index)
9
- @table = table
10
- @row = Row.new(@table.view, :index => row_index)
11
- end
12
-
13
- def selected?
14
- row.selected?
15
- end
16
-
17
- def select
18
- UiaDll::table_single_select(@table.view.search_information, row.row)
19
- self
20
- end
21
-
22
- def add_to_selection
23
- row.select
24
- self
25
- end
26
-
27
- def clear
28
- row.clear
29
- self
30
- end
31
-
32
- def cells
33
- row.cells.map &:text
34
- end
35
-
36
- def all_match?(hash)
37
- hash.all? do |key, value|
38
- send(key) == "#{value}"
39
- end
40
- end
41
-
42
- def value_from_header(name)
43
- which_column = header_methods.index(name)
44
- raise ArgumentError, "#{name} column does not exist in #{header_methods}" if which_column.nil?
45
- Cell.new(row, :index => which_column).text
46
- end
47
-
48
- def method_missing(name, *args)
49
- value_from_header name
50
- end
51
-
52
- def to_hash
53
- {:text => row.text, :row => row.row }
54
- end
55
-
56
- private
57
- def header_methods
58
- @headers ||= @table.headers.map(&:to_method)
59
- end
60
- end
61
- end
62
- end
@@ -1,30 +0,0 @@
1
- module Mohawk
2
- module Accessors
3
- class Tabs
4
- attr_reader :view
5
-
6
- def initialize(adapter, locator)
7
- @view = adapter.window.tab_control(locator)
8
- end
9
-
10
- def value
11
- view.value
12
- end
13
-
14
- def selected_tab=(which)
15
- case which
16
- when String
17
- view.set(which)
18
- when Regexp
19
- view.set items.find {|t| t.match which }
20
- else
21
- view.select(which)
22
- end
23
- end
24
-
25
- def items
26
- @view.items.map(&:text)
27
- end
28
- end
29
- end
30
- end
@@ -1,29 +0,0 @@
1
- module Mohawk
2
- module Accessors
3
- class Text
4
- attr_reader :view
5
-
6
- def initialize(adapter, locator)
7
- @adapter = adapter
8
- @view = adapter.window.text_field(locator)
9
- end
10
-
11
- def value
12
- @view.value
13
- end
14
-
15
- def set(text)
16
- @view.set text
17
- end
18
-
19
- def clear
20
- @view.clear
21
- end
22
-
23
- def enter(text)
24
- text_window = @adapter.window.child(:hwnd => @view.hwnd)
25
- text_window.send_keys text.split(//)
26
- end
27
- end
28
- end
29
- end
@@ -1,32 +0,0 @@
1
- module Mohawk
2
- module Accessors
3
- class TreeView
4
- attr_reader :view
5
-
6
- def initialize(adapter, locator)
7
- @view = adapter.window.select_list(locator)
8
- end
9
-
10
- def value
11
- @view.value
12
- end
13
-
14
- def items
15
- @view.options.map &:text
16
- end
17
-
18
- def expand(which_item)
19
- @view.expand which_item
20
- end
21
-
22
- def collapse(which_item)
23
- @view.collapse which_item
24
- end
25
-
26
- def select(which_item)
27
- @view.options[which_item].select if which_item.is_a? Integer
28
- @view.option(text: which_item).select if which_item.is_a? String
29
- end
30
- end
31
- end
32
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class ButtonScreen
4
- include Mohawk
5
- window(:id => nil)
6
-
7
- button(:easy, :id => "easyButton")
8
- end
9
-
10
- describe Mohawk::Accessors::Button do
11
- let(:screen) { ButtonScreen.new }
12
- let(:window) { double("RAutomation Window") }
13
- let(:button_field) { double("Button Field") }
14
-
15
- before(:each) do
16
- RAutomation::Window.stub(:new).and_return(window)
17
- window.should_receive(:button).with(:id => "easyButton").and_return(button_field)
18
- end
19
-
20
- context "accessing buttons" do
21
-
22
- it "clicks buttons" do
23
- button_field.should_receive(:click).and_yield
24
- screen.easy
25
- end
26
-
27
- it "clicks buttons and yields to a block" do
28
- button_field.should_receive(:click).and_yield
29
- result = false
30
- screen.easy do
31
- result = true
32
- end
33
- result.should be_true
34
- end
35
-
36
- it "knows the value of the button" do
37
- button_field.should_receive(:value).and_return "Button Value"
38
- screen.easy_value.should eq("Button Value")
39
- end
40
-
41
- it "can dish out the view" do
42
- screen.easy_view.should be(button_field)
43
- end
44
- end
45
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class CheckboxScreen
4
- include Mohawk
5
- window(:id => nil)
6
-
7
- checkbox(:check_yourself, :id => "checkboxId")
8
- end
9
-
10
- describe Mohawk::Accessors::CheckBox do
11
- let(:screen) { CheckboxScreen.new }
12
- let(:window) { double("RAutomation Window") }
13
- let(:checkbox_field) { double("CheckBox Field") }
14
-
15
- before(:each) do
16
- RAutomation::Window.stub(:new).and_return(window)
17
- window.should_receive(:checkbox).with(:id => "checkboxId").and_return(checkbox_field)
18
- end
19
-
20
- context "accessing checkbox controls" do
21
-
22
- it "knows if something is checked" do
23
- checkbox_field.should_receive(:set?).and_return(true)
24
- screen.check_yourself.should be_true
25
- end
26
-
27
- it "can get the text of the checkbox" do
28
- checkbox_field.should_receive(:value).and_return("CheckBox Text")
29
- screen.check_yourself_value.should eq("CheckBox Text")
30
- end
31
-
32
- it "can check items" do
33
- checkbox_field.should_receive(:set)
34
- screen.check_yourself = true
35
- end
36
-
37
- it "can uncheck items" do
38
- checkbox_field.should_receive(:clear)
39
- screen.check_yourself = false
40
- end
41
-
42
- it "can dish out the raw control" do
43
- screen.check_yourself_view.should be(checkbox_field)
44
- end
45
- end
46
- end
@@ -1,119 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class ComboBoxScreen
4
- include Mohawk
5
- window(:id => nil)
6
-
7
- combo_box(:nacho_combos, :id => "comboBoxId")
8
- dropdown(:my_default, :id => "defaultAliasId")
9
- dropdown(:my_combobox, :id => "comboboxAliasId")
10
- dropdown(:my_dropdown, :id => "dropdownAliasId")
11
- dropdown(:my_drop_down, :id => "drop_downAliasId")
12
- dropdown(:my_select_list, :id => "select_listAliasId")
13
- end
14
-
15
- class Option
16
- def initialize(text)
17
- @text = text
18
- end
19
-
20
- def text
21
- @text
22
- end
23
- end
24
-
25
- describe Mohawk::Accessors::Combo do
26
- let(:screen) { ComboBoxScreen.new }
27
- let(:window) { double("RAutomation Window") }
28
- let(:combo_box_field) { double("ComboBox Field") }
29
- let(:options) { double("ComboBox::Options").as_null_object }
30
-
31
- before(:each) do
32
- RAutomation::Window.stub(:new).and_return(window)
33
- combo_box_field.stub(:options).and_return(options)
34
- end
35
-
36
- context "accessing combo box controls" do
37
-
38
- before(:each) do
39
- window.should_receive(:select_list).with(:id => "comboBoxId").and_return(combo_box_field)
40
- end
41
-
42
- it "knows the current selected item" do
43
- combo_box_field.should_receive(:value).and_return("Selected Item")
44
- screen.nacho_combos.should eq("Selected Item")
45
- end
46
-
47
- it 'knows the currently selected items' do
48
- combo_box_field.should_receive(:values).and_return(['first', 'second'])
49
- screen.nacho_combos_selections.should eq(['first', 'second'])
50
- end
51
-
52
- it "selects items by index" do
53
- options.should_receive(:[]).with(3).and_return(double.as_null_object)
54
- screen.nacho_combos = 3
55
- end
56
-
57
- it "selects items by value" do
58
- option = double('combo option')
59
- combo_box_field.should_receive(:option).with(text: "Desired Value").and_return(option)
60
- option.should_receive(:select)
61
-
62
- screen.nacho_combos = "Desired Value"
63
- end
64
-
65
- it 'select is an alias for equals' do
66
- option = double('combo option')
67
- combo_box_field.should_receive(:option).with(text: 'Desired Value').and_return(option)
68
- option.should_receive(:select)
69
-
70
- screen.select_nacho_combos 'Desired Value'
71
- end
72
-
73
- it 'clears items by index' do
74
- option = double('combo option')
75
- options.should_receive(:[]).with(3).and_return(option)
76
- option.should_receive(:clear)
77
-
78
- screen.clear_nacho_combos 3
79
- end
80
-
81
- it 'clears items by value' do
82
- option = double('combo option')
83
- combo_box_field.should_receive(:option).with(text: 'Desired Value').and_return(option)
84
- option.should_receive(:clear)
85
-
86
- screen.clear_nacho_combos 'Desired Value'
87
- end
88
-
89
- it "is aware of the available options" do
90
- options = [Option.new("first"), Option.new("second"), Option.new("third")]
91
- combo_box_field.should_receive(:options).and_return(options)
92
- screen.nacho_combos_options.should eq(["first", "second", "third"])
93
- end
94
-
95
- it "can dish out the combo view" do
96
- screen.nacho_combos_view.should be(combo_box_field)
97
- end
98
- end
99
-
100
- context "aliases for combo_box" do
101
- let(:null_combo) { double("Null ComboBox Field").as_null_object }
102
- let(:combo_aliases) { ["default", "combobox", "dropdown", "drop_down", "select_list"] }
103
-
104
- def expected_alias(id)
105
- window.should_receive(:select_list).with(:id => "#{id}AliasId").ordered.and_return(null_combo)
106
- end
107
-
108
- it "has many aliases" do
109
- combo_aliases.each do |which_alias|
110
- expected_alias which_alias
111
- end
112
-
113
- combo_aliases.each do |which_alias|
114
- screen.send "my_#{which_alias}"
115
- end
116
- end
117
- end
118
- end
119
-
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class ControlScreen
4
- include Mohawk
5
- window(:id => nil)
6
-
7
- control(:control_yourself, :id => "controlId")
8
- end
9
-
10
- describe Mohawk::Accessors::Control do
11
- let(:screen) { ControlScreen.new }
12
- let(:window) { double("RAutomation Window") }
13
- let(:control) { double("Control Window") }
14
-
15
- before(:each) do
16
- RAutomation::Window.stub(:new).and_return(window)
17
- window.should_receive(:value_control).with(:id => 'controlId').and_return(control)
18
- end
19
-
20
- it "can get the value" do
21
- control.should_receive(:value).and_return('expected value')
22
- screen.control_yourself_value.should eq('expected value')
23
- end
24
-
25
- it "can set the value" do
26
- control.should_receive(:set).with('new value')
27
- screen.control_yourself = 'new value'
28
- end
29
-
30
- it "can click the control" do
31
- control.should_receive(:click).and_yield
32
- screen.click_control_yourself
33
- end
34
-
35
- it "can give a custom block to the click method" do
36
- control.should_receive(:click).and_yield
37
- result = false
38
- screen.click_control_yourself do
39
- result = true
40
- end
41
- result.should be_true
42
- end
43
-
44
- it "can work with the raw view" do
45
- screen.control_yourself_view.should be(control)
46
- end
47
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class LabelScreen
4
- include Mohawk
5
-
6
- window(:title => nil)
7
- label(:label_control, :id => "labelID")
8
- end
9
-
10
- describe Mohawk::Accessors::Label do
11
- let(:screen) { LabelScreen.new }
12
- let(:window) { double("RAutomation Window") }
13
- let(:label_control) { double("Label Control") }
14
-
15
- before(:each) do
16
- RAutomation::Window.stub(:new).and_return(window)
17
- window.should_receive(:label).with(:id => "labelID").and_return(label_control)
18
- end
19
-
20
- it "can retrieve the label value" do
21
- label_control.should_receive(:value).and_return("some string")
22
- screen.label_control.should eq("some string")
23
- end
24
-
25
- it "can dish out the view" do
26
- screen.label_control_view.should eq(label_control)
27
- end
28
-
29
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class LinkScreen
4
- include Mohawk
5
-
6
- window(:title => nil)
7
- link(:link_control, :id => "linkID")
8
- end
9
-
10
- describe Mohawk::Accessors::Link do
11
- let(:screen) { LinkScreen.new }
12
- let(:window) { double("RAutomation Window") }
13
- let(:link_control) { double("Link Control") }
14
-
15
- before(:each) do
16
- RAutomation::Window.stub(:new).and_return(window)
17
- window.should_receive(:label).with(:id => "linkID").and_return(link_control)
18
- end
19
-
20
- it "can retrieve the link text" do
21
- link_control.should_receive(:value).and_return("some string")
22
- screen.link_control_text.should eq("some string")
23
- end
24
-
25
- it "can click on the link" do
26
- link_control.should_receive(:click)
27
- screen.click_link_control
28
- end
29
-
30
- it "can dish out the view" do
31
- screen.link_control_view.should be(link_control)
32
- end
33
-
34
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class MenuItemScreen
4
- include Mohawk
5
- window(:id => nil)
6
-
7
- menu_item(:the_menu_item, :path => ["Path", "To", "Some Menu", "Item"])
8
- end
9
-
10
- describe Mohawk::Accessors::MenuItem do
11
- let(:screen) { MenuItemScreen.new }
12
- let(:window) { double("RAutomation Window") }
13
- let(:menu) { double("RAutomation Menu Item") }
14
-
15
- before(:each) do
16
- RAutomation::Window.stub(:new).and_return(window)
17
- end
18
-
19
- context "selecting menu items" do
20
- before(:each) do
21
- window.should_receive(:menu).with(:text => "Path").and_return(menu)
22
- end
23
-
24
- it "can open a menu item" do
25
- menu.should_receive(:menu).with(:text => "To").and_return(menu)
26
- menu.should_receive(:menu).with(:text => "Some Menu").and_return(menu)
27
- menu.should_receive(:menu).with(:text => "Item").and_return(menu)
28
- menu.should_receive(:open)
29
- screen.the_menu_item
30
- end
31
- end
32
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class RadioScreen
4
- include Mohawk
5
- window(:id => nil)
6
-
7
- radio(:radio_radio, :id => "radioId")
8
- end
9
-
10
- describe Mohawk::Accessors::Radio do
11
- let(:screen) { RadioScreen.new }
12
- let(:window) { double("RAutomation Window") }
13
- let(:radio_control) { double("Elvis Costello's Radio Radio") }
14
-
15
- before(:each) do
16
- RAutomation::Window.stub(:new).and_return(window)
17
- window.should_receive(:radio).with(:id => "radioId").and_return(radio_control)
18
- end
19
-
20
- context "working with radio controls" do
21
- it "can set the radio control" do
22
- radio_control.should_receive(:set)
23
- screen.radio_radio
24
- end
25
-
26
- it "knows if the radio is selected" do
27
- radio_control.should_receive(:set?)
28
- screen.radio_radio?
29
- end
30
-
31
- it "can dish out the raw view" do
32
- screen.radio_radio_view.should be(radio_control)
33
- end
34
- end
35
- end