mohawk 0.0.1 → 0.0.2

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.
Files changed (41) hide show
  1. data/Changelog +17 -0
  2. data/Gemfile +1 -5
  3. data/README.md +29 -0
  4. data/features/label.feature +4 -0
  5. data/features/menu.feature +5 -0
  6. data/features/mohawk.feature +14 -0
  7. data/features/step_definitions/label_steps.rb +3 -0
  8. data/features/step_definitions/menu_steps.rb +5 -0
  9. data/features/step_definitions/mohawk_steps.rb +15 -0
  10. data/features/step_definitions/table_steps.rb +23 -0
  11. data/features/step_definitions/text_steps.rb +4 -0
  12. data/features/step_definitions/tree_view_steps.rb +31 -0
  13. data/features/support/WindowsForms.exe +0 -0
  14. data/features/support/screens/data_entry_form.rb +6 -0
  15. data/features/support/screens/main_screen.rb +4 -0
  16. data/features/support/string.rb +4 -0
  17. data/features/table.feature +19 -0
  18. data/features/text.feature +4 -0
  19. data/features/tree_view.feature +49 -0
  20. data/lib/mohawk.rb +41 -0
  21. data/lib/mohawk/accessors.rb +182 -1
  22. data/lib/mohawk/accessors/label.rb +13 -0
  23. data/lib/mohawk/accessors/menu_item.rb +21 -0
  24. data/lib/mohawk/accessors/table.rb +50 -0
  25. data/lib/mohawk/accessors/text.rb +6 -0
  26. data/lib/mohawk/accessors/tree_view.rb +30 -0
  27. data/lib/mohawk/adapters/uia_adapter.rb +16 -0
  28. data/lib/mohawk/navigation.rb +4 -3
  29. data/lib/mohawk/version.rb +1 -1
  30. data/mohawk.gemspec +4 -2
  31. data/spec/lib/mohawk/accessors/combo_spec.rb +28 -1
  32. data/spec/lib/mohawk/accessors/label_spec.rb +25 -0
  33. data/spec/lib/mohawk/accessors/menu_spec.rb +32 -0
  34. data/spec/lib/mohawk/accessors/table_spec.rb +96 -0
  35. data/spec/lib/mohawk/accessors/text_spec.rb +9 -0
  36. data/spec/lib/mohawk/accessors/tree_view_spec.rb +86 -0
  37. data/spec/lib/mohawk_spec.rb +26 -0
  38. data/spec/lib/navigation_spec.rb +34 -0
  39. metadata +74 -9
  40. data/features/fado.feature +0 -5
  41. data/features/step_definitions/fado_steps.rb +0 -7
@@ -0,0 +1,13 @@
1
+ module Mohawk
2
+ module Accessors
3
+ class Label
4
+ def initialize(adapter, locator)
5
+ @label = adapter.window.label(locator)
6
+ end
7
+
8
+ def value
9
+ @label.value
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,50 @@
1
+ module Mohawk
2
+ module Accessors
3
+ class Table
4
+ class Row
5
+ attr_reader :row
6
+
7
+ def initialize(table, row)
8
+ @row = row
9
+ @table = table
10
+ end
11
+
12
+ def selected?
13
+ @table.selected? row.row
14
+ end
15
+
16
+ def cells
17
+ row.cells.map &:text
18
+ end
19
+
20
+ def to_hash
21
+ {:text => row.text, :row => row.row }
22
+ end
23
+ end
24
+
25
+ attr_reader :table
26
+
27
+ def initialize(adapter, locator)
28
+ @table = adapter.window.table(locator)
29
+ end
30
+
31
+ def select(which_item)
32
+ table.select which_item if which_item.is_a? Integer
33
+ end
34
+
35
+ def rows
36
+ table.rows.map do |row|
37
+ Row.new(table, row).to_hash
38
+ end
39
+ end
40
+
41
+ def row(which_row)
42
+ Row.new table, table.row(:index => which_row)
43
+ end
44
+
45
+ def view
46
+ table
47
+ end
48
+ end
49
+ end
50
+ end
@@ -2,6 +2,7 @@ module Mohawk
2
2
  module Accessors
3
3
  class Text
4
4
  def initialize(adapter, locator)
5
+ @adapter = adapter
5
6
  @text = adapter.window.text_field(locator)
6
7
  end
7
8
 
@@ -16,6 +17,11 @@ module Mohawk
16
17
  def clear
17
18
  @text.clear
18
19
  end
20
+
21
+ def enter(text)
22
+ text_window = @adapter.window.child(:hwnd => @text.hwnd)
23
+ text_window.send_keys text.split(//)
24
+ end
19
25
  end
20
26
  end
21
27
  end
@@ -0,0 +1,30 @@
1
+ module Mohawk
2
+ module Accessors
3
+ class TreeView
4
+ def initialize(adapter, locator)
5
+ @tree = adapter.window.select_list(locator)
6
+ end
7
+
8
+ def value
9
+ @tree.value
10
+ end
11
+
12
+ def items
13
+ @tree.options.map &:text
14
+ end
15
+
16
+ def expand(which_item)
17
+ @tree.expand which_item
18
+ end
19
+
20
+ def collapse(which_item)
21
+ @tree.collapse which_item
22
+ end
23
+
24
+ def select(which_item)
25
+ @tree.select which_item if which_item.is_a? Integer
26
+ @tree.set which_item if which_item.is_a? String
27
+ end
28
+ end
29
+ end
30
+ end
@@ -26,6 +26,22 @@ module Mohawk
26
26
  def radio(locator)
27
27
  Mohawk::Accessors::Radio.new(self, locator)
28
28
  end
29
+
30
+ def label(locator)
31
+ Mohawk::Accessors::Label.new(self, locator)
32
+ end
33
+
34
+ def menu_item(locator)
35
+ Mohawk::Accessors::MenuItem.new(self, locator)
36
+ end
37
+
38
+ def table(locator)
39
+ Mohawk::Accessors::Table.new(self, locator)
40
+ end
41
+
42
+ def tree_view(locator)
43
+ Mohawk::Accessors::TreeView.new(self, locator)
44
+ end
29
45
  end
30
46
  end
31
47
  end
@@ -1,9 +1,10 @@
1
1
  module Mohawk
2
2
  module Navigation
3
3
  def on(cls, &block)
4
- @screen = cls.new
5
- block.call @screen if block
6
- @screen
4
+ screen = cls.new
5
+ screen.wait_until_present
6
+ block.call screen if block
7
+ screen
7
8
  end
8
9
  end
9
10
  end
@@ -1,3 +1,3 @@
1
1
  module Mohawk
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/mohawk.gemspec CHANGED
@@ -17,8 +17,10 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency 'rautomation'
20
+ gem.add_dependency 'rautomation', '>= 0.8.0'
21
21
 
22
- gem.add_development_dependency 'childprocess'
22
+ gem.add_development_dependency 'cucumber'
23
23
  gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'childprocess'
24
26
  end
@@ -5,6 +5,11 @@ class ComboBoxScreen
5
5
  window(:id => nil)
6
6
 
7
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")
8
13
  end
9
14
 
10
15
  class Option
@@ -24,11 +29,14 @@ describe Mohawk::Accessors::Combo do
24
29
 
25
30
  before(:each) do
26
31
  RAutomation::Window.stub(:new).and_return(window)
27
- window.should_receive(:select_list).with(:id => "comboBoxId").and_return(combo_box_field)
28
32
  end
29
33
 
30
34
  context "accessing combo box controls" do
31
35
 
36
+ before(:each) do
37
+ window.should_receive(:select_list).with(:id => "comboBoxId").and_return(combo_box_field)
38
+ end
39
+
32
40
  it "knows the current selected item" do
33
41
  combo_box_field.should_receive(:value).and_return("Selected Item")
34
42
  screen.nacho_combos.should eq("Selected Item")
@@ -51,5 +59,24 @@ describe Mohawk::Accessors::Combo do
51
59
  end
52
60
 
53
61
  end
62
+
63
+ context "aliases for combo_box" do
64
+ let(:null_combo) { double("Null ComboBox Field").as_null_object }
65
+ let(:combo_aliases) { ["default", "combobox", "dropdown", "drop_down", "select_list"] }
66
+
67
+ def expected_alias(id)
68
+ window.should_receive(:select_list).with(:id => "#{id}AliasId").ordered.and_return(null_combo)
69
+ end
70
+
71
+ it "has many aliases" do
72
+ combo_aliases.each do |which_alias|
73
+ expected_alias which_alias
74
+ end
75
+
76
+ combo_aliases.each do |which_alias|
77
+ screen.send "my_#{which_alias}"
78
+ end
79
+ end
80
+ end
54
81
  end
55
82
 
@@ -0,0 +1,25 @@
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
+ end
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ class TableScreen
4
+ include Mohawk
5
+ window(:id => nil)
6
+
7
+ table(:top, :id => "tableId")
8
+
9
+ # aliases
10
+ table(:my_default, :id => "defaultAliasId")
11
+ listview(:my_listview, :id => "listviewAliasId")
12
+ list_view(:my_list_view, :id => "list_viewAliasId")
13
+ end
14
+
15
+ class FakeTableRow
16
+ attr_reader :text, :row
17
+ def initialize(text, row)
18
+ @text = text
19
+ @row = row
20
+ end
21
+ end
22
+
23
+ describe Mohawk::Accessors::Table do
24
+ let(:screen) { TableScreen.new }
25
+ let(:window) { double("RAutomation Window") }
26
+ let(:table) { double("Table") }
27
+
28
+ before(:each) do
29
+ RAutomation::Window.stub(:new).and_return(window)
30
+ end
31
+
32
+ context "working with table controls" do
33
+ before(:each) do
34
+ window.should_receive(:table).with(:id => "tableId").and_return(table)
35
+ end
36
+
37
+ it "can set a value by index" do
38
+ table.should_receive(:select).with(1)
39
+ screen.top = 1
40
+ end
41
+
42
+ it "has rows" do
43
+ fake_rows = [FakeTableRow.new("First Row", 0), FakeTableRow.new("Second Row", 1)]
44
+ expected_rows = fake_rows.map {|r| {:text => r.text, :row => r.row} }
45
+ table.should_receive(:rows).and_return(fake_rows)
46
+ expected_rows.should eq(screen.top_rows)
47
+ end
48
+
49
+ it "can return the raw view" do
50
+ screen.top_view.should_not be_nil
51
+ end
52
+
53
+ describe Mohawk::Accessors::Table::Row do
54
+ let(:table_row) { double("RAutomation Table::Row") }
55
+
56
+ before(:each) do
57
+ table.should_receive(:row).with(:index => 0).and_return(table_row)
58
+ table_row.stub(:row).and_return 0
59
+ end
60
+
61
+ it "can get an individual row" do
62
+ screen.top_row(0).should_not be_nil
63
+ end
64
+
65
+ it "knows if it is selected" do
66
+ table.should_receive(:selected?).with(0).and_return(true)
67
+ screen.top_row(0).should be_selected
68
+ end
69
+
70
+ it "has cells" do
71
+ expected_cells = [FakeTableRow.new("Item 1", 0), FakeTableRow.new("Item 2", 1)]
72
+ table_row.should_receive(:cells).and_return(expected_cells)
73
+ screen.top_row(0).cells.should eq expected_cells.map &:text
74
+ end
75
+ end
76
+ end
77
+
78
+ context "aliases for table" do
79
+ let(:null_table) { double("Null ComboBox Field").as_null_object }
80
+ let(:table_aliases) { ["default", "listview", "list_view"] }
81
+
82
+ def expected_alias(id)
83
+ window.should_receive(:table).with(:id => "#{id}AliasId").ordered.and_return(null_table)
84
+ end
85
+
86
+ it "has many aliases" do
87
+ table_aliases.each do |which_alias|
88
+ expected_alias which_alias
89
+ end
90
+
91
+ table_aliases.each do |which_alias|
92
+ screen.send "my_#{which_alias}_view"
93
+ end
94
+ end
95
+ end
96
+ end
@@ -11,6 +11,7 @@ describe Mohawk::Accessors::Text do
11
11
  let(:screen) { TextScreen.new }
12
12
  let(:window) { double("RAutomation Window") }
13
13
  let(:text_field) { double("Text Field") }
14
+ let(:text_field_window) { double("Text Field Window") }
14
15
 
15
16
  before(:each) do
16
17
  RAutomation::Window.stub(:new).and_return(window)
@@ -34,5 +35,13 @@ describe Mohawk::Accessors::Text do
34
35
  screen.clear_text_id
35
36
  end
36
37
 
38
+ it "enters the text" do
39
+ text_field.should_receive(:hwnd).and_return 123
40
+ window.should_receive(:child).with(:hwnd => 123).and_return(text_field_window)
41
+ text_field_window.should_receive(:send_keys).with("entered text".split(//))
42
+
43
+ screen.enter_text_id "entered text"
44
+ end
45
+
37
46
  end
38
47
  end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ class TreeViewScreen
4
+ include Mohawk
5
+ window(:id => nil)
6
+
7
+ tree_view(:oak, :id => "treeViewId")
8
+
9
+ # aliases
10
+ tree_view(:my_default, :id => "defaultAliasId")
11
+ treeview(:my_treeview, :id => "treeviewAliasId")
12
+ tree(:my_tree, :id => "treeAliasId")
13
+ end
14
+
15
+ class FakeTreeItem
16
+ attr_reader :text
17
+
18
+ def initialize(item_text)
19
+ @text = item_text
20
+ end
21
+ end
22
+
23
+ describe Mohawk::Accessors::TreeView do
24
+ let(:screen) { TreeViewScreen.new }
25
+ let(:window) { double("RAutomation Window") }
26
+ let(:tree_field) { double("TreeView Field") }
27
+
28
+ before(:each) do
29
+ RAutomation::Window.stub(:new).and_return(window)
30
+ end
31
+
32
+ context "working with TreeView controls" do
33
+ before(:each) do
34
+ window.should_receive(:select_list).with(:id => "treeViewId").and_return(tree_field)
35
+ end
36
+
37
+ it "has a value" do
38
+ tree_field.should_receive(:value).and_return("tree value")
39
+ screen.oak.should eq "tree value"
40
+ end
41
+
42
+ it "can select items by index" do
43
+ tree_field.should_receive(:select).with(7)
44
+ screen.oak = 7
45
+ end
46
+
47
+ it "can select items by their value" do
48
+ tree_field.should_receive(:set).with("item value")
49
+ screen.oak = "item value"
50
+ end
51
+
52
+ it "can return the tree items" do
53
+ tree_field.should_receive(:options).and_return([FakeTreeItem.new("Item One"), FakeTreeItem.new("Item Two")])
54
+ screen.oak_items.should eq ["Item One", "Item Two"]
55
+ end
56
+
57
+ it "can expand items" do
58
+ tree_field.should_receive(:expand).with(7)
59
+ screen.expand_oak_item 7
60
+ end
61
+
62
+ it "can collapse items" do
63
+ tree_field.should_receive(:collapse).with("some item")
64
+ screen.collapse_oak_item "some item"
65
+ end
66
+ end
67
+
68
+ context "aliases for tree_view" do
69
+ let(:null_tree_view) { double("Null TreeView Field").as_null_object }
70
+ let(:tree_view_aliases) { ["default", "treeview", "tree"] }
71
+
72
+ def expected_alias(id)
73
+ window.should_receive(:select_list).with(:id => "#{id}AliasId").ordered.and_return(null_tree_view)
74
+ end
75
+
76
+ it "has many aliases" do
77
+ tree_view_aliases.each do |which_alias|
78
+ expected_alias which_alias
79
+ end
80
+
81
+ tree_view_aliases.each do |which_alias|
82
+ screen.send "my_#{which_alias}"
83
+ end
84
+ end
85
+ end
86
+ end