rautomation 0.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/History.rdoc +16 -1
  2. data/LICENSE +1 -1
  3. data/README.rdoc +25 -7
  4. data/Rakefile +4 -0
  5. data/VERSION +1 -1
  6. data/ext/IAccessibleDLL/IAccessibleDLL.sln +20 -0
  7. data/ext/IAccessibleDLL/IAccessibleDLL.suo +0 -0
  8. data/ext/IAccessibleDLL/IAccessibleDLL/IAccessibleDLL.cpp +36 -0
  9. data/ext/IAccessibleDLL/IAccessibleDLL/IAccessibleDLL.vcxproj +100 -0
  10. data/ext/IAccessibleDLL/IAccessibleDLL/IAccessibleDLL.vcxproj.filters +39 -0
  11. data/ext/IAccessibleDLL/IAccessibleDLL/IAccessibleDLL.vcxproj.user +3 -0
  12. data/ext/IAccessibleDLL/IAccessibleDLL/ReadMe.txt +48 -0
  13. data/ext/IAccessibleDLL/IAccessibleDLL/dllmain.cpp +19 -0
  14. data/ext/IAccessibleDLL/IAccessibleDLL/stdafx.cpp +8 -0
  15. data/ext/IAccessibleDLL/IAccessibleDLL/stdafx.h +16 -0
  16. data/ext/IAccessibleDLL/IAccessibleDLL/targetver.h +8 -0
  17. data/ext/IAccessibleDLL/Release/IAccessibleDLL.dll +0 -0
  18. data/ext/IAccessibleDLL/Release/IAccessibleDLL.exp +0 -0
  19. data/ext/IAccessibleDLL/Release/IAccessibleDLL.lib +0 -0
  20. data/ext/WindowsForms/bin/WindowsForms.exe +0 -0
  21. data/ext/WindowsForms/src/WindowsForms/WindowsForms.sln +20 -0
  22. data/ext/WindowsForms/src/WindowsForms/WindowsForms.suo +0 -0
  23. data/ext/WindowsForms/src/WindowsForms/WindowsForms/AboutBox.Designer.cs +80 -0
  24. data/ext/WindowsForms/src/WindowsForms/WindowsForms/AboutBox.cs +103 -0
  25. data/ext/WindowsForms/src/WindowsForms/WindowsForms/AboutBox.resx +120 -0
  26. data/ext/WindowsForms/src/WindowsForms/WindowsForms/DataEntryForm.Designer.cs +167 -0
  27. data/ext/WindowsForms/src/WindowsForms/WindowsForms/DataEntryForm.cs +45 -0
  28. data/ext/WindowsForms/src/WindowsForms/WindowsForms/DataEntryForm.resx +120 -0
  29. data/ext/WindowsForms/src/WindowsForms/WindowsForms/MainFormWindow.Designer.cs +278 -0
  30. data/ext/WindowsForms/src/WindowsForms/WindowsForms/MainFormWindow.cs +78 -0
  31. data/ext/WindowsForms/src/WindowsForms/WindowsForms/MainFormWindow.resx +120 -0
  32. data/ext/WindowsForms/src/WindowsForms/WindowsForms/PersonForm.Designer.cs +119 -0
  33. data/ext/WindowsForms/src/WindowsForms/WindowsForms/PersonForm.cs +34 -0
  34. data/ext/WindowsForms/src/WindowsForms/WindowsForms/PersonForm.resx +120 -0
  35. data/ext/WindowsForms/src/WindowsForms/WindowsForms/Program.cs +21 -0
  36. data/ext/WindowsForms/src/WindowsForms/WindowsForms/Properties/AssemblyInfo.cs +36 -0
  37. data/ext/WindowsForms/src/WindowsForms/WindowsForms/Properties/Resources.Designer.cs +71 -0
  38. data/ext/WindowsForms/src/WindowsForms/WindowsForms/Properties/Resources.resx +117 -0
  39. data/ext/WindowsForms/src/WindowsForms/WindowsForms/Properties/Settings.Designer.cs +30 -0
  40. data/ext/WindowsForms/src/WindowsForms/WindowsForms/Properties/Settings.settings +7 -0
  41. data/ext/WindowsForms/src/WindowsForms/WindowsForms/SimpleElementsForm.Designer.cs +93 -0
  42. data/ext/WindowsForms/src/WindowsForms/WindowsForms/SimpleElementsForm.cs +19 -0
  43. data/ext/WindowsForms/src/WindowsForms/WindowsForms/SimpleElementsForm.resx +120 -0
  44. data/ext/WindowsForms/src/WindowsForms/WindowsForms/WindowsForms.csproj +123 -0
  45. data/ext/WindowsForms/src/WindowsForms/WindowsForms/bin/Debug/WindowsForms.exe +0 -0
  46. data/ext/WindowsForms/src/WindowsForms/WindowsForms/bin/Debug/WindowsForms.pdb +0 -0
  47. data/ext/WindowsForms/src/WindowsForms/WindowsForms/bin/Debug/WindowsForms.vshost.exe +0 -0
  48. data/ext/WindowsForms/src/WindowsForms/WindowsForms/bin/Debug/WindowsForms.vshost.exe.manifest +11 -0
  49. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache +0 -0
  50. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache +0 -0
  51. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/GenerateResource.read.1.tlog +0 -0
  52. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/GenerateResource.write.1.tlog +0 -0
  53. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/ResolveAssemblyReference.cache +0 -0
  54. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.AboutBox.resources +0 -0
  55. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.DataEntryForm.resources +0 -0
  56. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.MainFormWindow.resources +0 -0
  57. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.PersonForm.resources +0 -0
  58. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.Properties.Resources.resources +0 -0
  59. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.SimpleElementsForm.resources +0 -0
  60. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.csproj.FileListAbsolute.txt +25 -0
  61. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.exe +0 -0
  62. data/ext/WindowsForms/src/WindowsForms/WindowsForms/obj/x86/Debug/WindowsForms.pdb +0 -0
  63. data/lib/{RAutomation.rb → rautomation.rb} +3 -1
  64. data/lib/rautomation/adapter/autoit/button.rb +7 -4
  65. data/lib/rautomation/adapter/autoit/locators.rb +4 -2
  66. data/lib/rautomation/adapter/autoit/text_field.rb +8 -5
  67. data/lib/rautomation/adapter/autoit/window.rb +23 -7
  68. data/lib/rautomation/adapter/win_ffi.rb +9 -3
  69. data/lib/rautomation/adapter/win_ffi/button.rb +3 -34
  70. data/lib/rautomation/adapter/win_ffi/button_helper.rb +24 -0
  71. data/lib/rautomation/adapter/win_ffi/checkbox.rb +12 -0
  72. data/lib/rautomation/adapter/win_ffi/constants.rb +21 -0
  73. data/lib/rautomation/adapter/win_ffi/control.rb +46 -0
  74. data/lib/rautomation/adapter/win_ffi/functions.rb +52 -1
  75. data/lib/rautomation/adapter/win_ffi/locators.rb +2 -1
  76. data/lib/rautomation/adapter/win_ffi/radio.rb +12 -0
  77. data/lib/rautomation/adapter/win_ffi/select_list.rb +64 -0
  78. data/lib/rautomation/adapter/win_ffi/table.rb +18 -0
  79. data/lib/rautomation/adapter/win_ffi/text_field.rb +4 -20
  80. data/lib/rautomation/adapter/win_ffi/window.rb +48 -10
  81. data/lib/rautomation/element_collections.rb +44 -0
  82. data/lib/rautomation/window.rb +29 -5
  83. data/spec/adapter/win_ffi/checkbox_spec.rb +29 -0
  84. data/spec/adapter/win_ffi/radio_spec.rb +21 -0
  85. data/spec/adapter/win_ffi/select_list_spec.rb +41 -0
  86. data/spec/adapter/win_ffi/table_spec.rb +20 -0
  87. data/spec/adapter/win_ffi/window_spec.rb +6 -12
  88. data/spec/button_spec.rb +28 -20
  89. data/spec/buttons_spec.rb +21 -0
  90. data/spec/spec_helper.rb +46 -37
  91. data/spec/text_field_spec.rb +11 -11
  92. data/spec/text_fields_spec.rb +22 -0
  93. data/spec/window_spec.rb +11 -19
  94. data/spec/windows_spec.rb +55 -0
  95. metadata +84 -9
  96. data/.gitignore +0 -25
  97. data/rautomation.gemspec +0 -90
  98. data/spec/test.html +0 -15
@@ -0,0 +1,123 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <PropertyGroup>
4
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6
+ <ProductVersion>8.0.30703</ProductVersion>
7
+ <SchemaVersion>2.0</SchemaVersion>
8
+ <ProjectGuid>{79C33EDA-58C4-41EF-93DC-BA679895BD43}</ProjectGuid>
9
+ <OutputType>WinExe</OutputType>
10
+ <AppDesignerFolder>Properties</AppDesignerFolder>
11
+ <RootNamespace>WindowsForms</RootNamespace>
12
+ <AssemblyName>WindowsForms</AssemblyName>
13
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
15
+ <FileAlignment>512</FileAlignment>
16
+ </PropertyGroup>
17
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
18
+ <PlatformTarget>x86</PlatformTarget>
19
+ <DebugSymbols>true</DebugSymbols>
20
+ <DebugType>full</DebugType>
21
+ <Optimize>false</Optimize>
22
+ <OutputPath>bin\Debug\</OutputPath>
23
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
24
+ <ErrorReport>prompt</ErrorReport>
25
+ <WarningLevel>4</WarningLevel>
26
+ </PropertyGroup>
27
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
28
+ <PlatformTarget>x86</PlatformTarget>
29
+ <DebugType>pdbonly</DebugType>
30
+ <Optimize>true</Optimize>
31
+ <OutputPath>bin\Release\</OutputPath>
32
+ <DefineConstants>TRACE</DefineConstants>
33
+ <ErrorReport>prompt</ErrorReport>
34
+ <WarningLevel>4</WarningLevel>
35
+ </PropertyGroup>
36
+ <ItemGroup>
37
+ <Reference Include="System" />
38
+ <Reference Include="System.Core" />
39
+ <Reference Include="System.Xml.Linq" />
40
+ <Reference Include="System.Data.DataSetExtensions" />
41
+ <Reference Include="Microsoft.CSharp" />
42
+ <Reference Include="System.Data" />
43
+ <Reference Include="System.Deployment" />
44
+ <Reference Include="System.Drawing" />
45
+ <Reference Include="System.Windows.Forms" />
46
+ <Reference Include="System.Xml" />
47
+ </ItemGroup>
48
+ <ItemGroup>
49
+ <Compile Include="AboutBox.cs">
50
+ <SubType>Form</SubType>
51
+ </Compile>
52
+ <Compile Include="AboutBox.Designer.cs">
53
+ <DependentUpon>AboutBox.cs</DependentUpon>
54
+ </Compile>
55
+ <Compile Include="DataEntryForm.cs">
56
+ <SubType>Form</SubType>
57
+ </Compile>
58
+ <Compile Include="DataEntryForm.Designer.cs">
59
+ <DependentUpon>DataEntryForm.cs</DependentUpon>
60
+ </Compile>
61
+ <Compile Include="SimpleElementsForm.cs">
62
+ <SubType>Form</SubType>
63
+ </Compile>
64
+ <Compile Include="SimpleElementsForm.Designer.cs">
65
+ <DependentUpon>SimpleElementsForm.cs</DependentUpon>
66
+ </Compile>
67
+ <Compile Include="PersonForm.cs">
68
+ <SubType>Form</SubType>
69
+ </Compile>
70
+ <Compile Include="PersonForm.Designer.cs">
71
+ <DependentUpon>PersonForm.cs</DependentUpon>
72
+ </Compile>
73
+ <Compile Include="MainFormWindow.cs">
74
+ <SubType>Form</SubType>
75
+ </Compile>
76
+ <Compile Include="MainFormWindow.Designer.cs">
77
+ <DependentUpon>MainFormWindow.cs</DependentUpon>
78
+ </Compile>
79
+ <Compile Include="Program.cs" />
80
+ <Compile Include="Properties\AssemblyInfo.cs" />
81
+ <EmbeddedResource Include="AboutBox.resx">
82
+ <DependentUpon>AboutBox.cs</DependentUpon>
83
+ </EmbeddedResource>
84
+ <EmbeddedResource Include="DataEntryForm.resx">
85
+ <DependentUpon>DataEntryForm.cs</DependentUpon>
86
+ </EmbeddedResource>
87
+ <EmbeddedResource Include="SimpleElementsForm.resx">
88
+ <DependentUpon>SimpleElementsForm.cs</DependentUpon>
89
+ </EmbeddedResource>
90
+ <EmbeddedResource Include="PersonForm.resx">
91
+ <DependentUpon>PersonForm.cs</DependentUpon>
92
+ </EmbeddedResource>
93
+ <EmbeddedResource Include="MainFormWindow.resx">
94
+ <DependentUpon>MainFormWindow.cs</DependentUpon>
95
+ </EmbeddedResource>
96
+ <EmbeddedResource Include="Properties\Resources.resx">
97
+ <Generator>ResXFileCodeGenerator</Generator>
98
+ <LastGenOutput>Resources.Designer.cs</LastGenOutput>
99
+ <SubType>Designer</SubType>
100
+ </EmbeddedResource>
101
+ <Compile Include="Properties\Resources.Designer.cs">
102
+ <AutoGen>True</AutoGen>
103
+ <DependentUpon>Resources.resx</DependentUpon>
104
+ </Compile>
105
+ <None Include="Properties\Settings.settings">
106
+ <Generator>SettingsSingleFileGenerator</Generator>
107
+ <LastGenOutput>Settings.Designer.cs</LastGenOutput>
108
+ </None>
109
+ <Compile Include="Properties\Settings.Designer.cs">
110
+ <AutoGen>True</AutoGen>
111
+ <DependentUpon>Settings.settings</DependentUpon>
112
+ <DesignTimeSharedInput>True</DesignTimeSharedInput>
113
+ </Compile>
114
+ </ItemGroup>
115
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
116
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
117
+ Other similar extension points exist, see Microsoft.Common.targets.
118
+ <Target Name="BeforeBuild">
119
+ </Target>
120
+ <Target Name="AfterBuild">
121
+ </Target>
122
+ -->
123
+ </Project>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
3
+ <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
4
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
5
+ <security>
6
+ <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
7
+ <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
8
+ </requestedPrivileges>
9
+ </security>
10
+ </trustInfo>
11
+ </assembly>
@@ -0,0 +1,25 @@
1
+ C:\Projects\RAutomation\RAutomation\ext\src\WindowsForms\WindowsForms\bin\Debug\WindowsForms.exe
2
+ C:\Projects\RAutomation\RAutomation\ext\src\WindowsForms\WindowsForms\bin\Debug\WindowsForms.pdb
3
+ C:\Projects\RAutomation\RAutomation\ext\src\WindowsForms\WindowsForms\obj\x86\Debug\ResolveAssemblyReference.cache
4
+ C:\Projects\RAutomation\RAutomation\ext\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.Properties.Resources.resources
5
+ C:\Projects\RAutomation\RAutomation\ext\src\WindowsForms\WindowsForms\obj\x86\Debug\GenerateResource.read.1.tlog
6
+ C:\Projects\RAutomation\RAutomation\ext\src\WindowsForms\WindowsForms\obj\x86\Debug\GenerateResource.write.1.tlog
7
+ C:\Projects\RAutomation\RAutomation\ext\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.exe
8
+ C:\Projects\RAutomation\RAutomation\ext\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.pdb
9
+ C:\Projects\RAutomation\RAutomation\ext\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.MainFormWindow.resources
10
+ C:\Projects\RAutomation\RAutomation\ext\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.AboutBox.resources
11
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\bin\Debug\WindowsForms.exe
12
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\bin\Debug\WindowsForms.pdb
13
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\ResolveAssemblyReference.cache
14
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.AboutBox.resources
15
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.DataEntryForm.resources
16
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.PersonForm.resources
17
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.MainFormWindow.resources
18
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.Properties.Resources.resources
19
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\GenerateResource.read.1.tlog
20
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\GenerateResource.write.1.tlog
21
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.exe
22
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.pdb
23
+ C:\Projects\RAutomation\RAutomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.SimpleElementsForm.resources
24
+ C:\projects\rautomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.exe
25
+ C:\projects\rautomation\ext\WindowsForms\src\WindowsForms\WindowsForms\obj\x86\Debug\WindowsForms.pdb
@@ -1,5 +1,7 @@
1
1
  require "rautomation/wait_helper"
2
2
  require "rautomation/adapter/helper"
3
+ require "rautomation/element_collections"
3
4
  require "rautomation/window"
4
5
  require "rautomation/button"
5
- require "rautomation/text_field"
6
+ require "rautomation/text_field"
7
+
@@ -4,6 +4,9 @@ module RAutomation
4
4
  class Button
5
5
  include WaitHelper
6
6
  include Locators
7
+
8
+ # Default locators used for searching buttons.
9
+ DEFAULT_LOCATORS = {:class => /button/i}
7
10
 
8
11
  # @private
9
12
  # Special-cased locators
@@ -33,8 +36,8 @@ module RAutomation
33
36
  wait_until do
34
37
  @window.activate
35
38
  @window.active? &&
36
- Window.autoit.ControlFocus(@window.locator_hwnd, "", @locators) == 1 &&
37
- Window.autoit.ControlClick(@window.locator_hwnd, "", @locators) == 1 &&
39
+ Window.autoit.ControlFocus(@window.locator_hwnd, "", @autoit_locators) == 1 &&
40
+ Window.autoit.ControlClick(@window.locator_hwnd, "", @autoit_locators) == 1 &&
38
41
  clicked = true # is clicked at least once
39
42
 
40
43
  block_given? ? yield : clicked && !exists?
@@ -43,12 +46,12 @@ module RAutomation
43
46
 
44
47
  # @see RAutomation::Button#value
45
48
  def value
46
- Window.autoit.ControlGetText(@window.locator_hwnd, "", @locators)
49
+ Window.autoit.ControlGetText(@window.locator_hwnd, "", @autoit_locators)
47
50
  end
48
51
 
49
52
  # @see RAutomation::Button#exists?
50
53
  def exists?
51
- not Window.autoit.ControlGetHandle(@window.locator_hwnd, "", @locators).empty?
54
+ not Window.autoit.ControlGetHandle(@window.locator_hwnd, "", @autoit_locators).empty?
52
55
  end
53
56
  end
54
57
  end
@@ -7,7 +7,9 @@ module RAutomation
7
7
  private
8
8
 
9
9
  def extract(locators)
10
- @locators = "[#{locators.map do |locator, value|
10
+ locators = self.class::DEFAULT_LOCATORS.merge(locators) if self.class.const_defined?(:DEFAULT_LOCATORS)
11
+ @locators = locators
12
+ @autoit_locators = "[#{@locators.map do |locator, value|
11
13
  locator_key = self.class::LOCATORS[locator] || self.class::LOCATORS[[locator, value.class]]
12
14
  value = value.to_i + 1 if locator == :index # use 0-based indexing
13
15
  value = value.to_s(16) if locator == :hwnd
@@ -17,4 +19,4 @@ module RAutomation
17
19
  end
18
20
  end
19
21
  end
20
- end
22
+ end
@@ -5,6 +5,9 @@ module RAutomation
5
5
  include WaitHelper
6
6
  include Locators
7
7
 
8
+ # Default locators used for searching text fields.
9
+ DEFAULT_LOCATORS = {:class => /edit/i}
10
+
8
11
  # @private
9
12
  # Special-cased locators
10
13
  LOCATORS = {
@@ -32,8 +35,8 @@ module RAutomation
32
35
  wait_until do
33
36
  @window.activate
34
37
  @window.active? &&
35
- Window.autoit.ControlFocus(@window.locator_hwnd, "", @locators) == 1 &&
36
- Window.autoit.ControlSetText(@window.locator_hwnd, "", @locators, text) == 1 &&
38
+ Window.autoit.ControlFocus(@window.locator_hwnd, "", @autoit_locators) == 1 &&
39
+ Window.autoit.ControlSetText(@window.locator_hwnd, "", @autoit_locators, text) == 1 &&
37
40
  value == text
38
41
  end
39
42
  end
@@ -45,14 +48,14 @@ module RAutomation
45
48
 
46
49
  # @see RAutomation::TextField#value
47
50
  def value
48
- Window.autoit.ControlGetText(@window.locator_hwnd, "", @locators)
51
+ Window.autoit.ControlGetText(@window.locator_hwnd, "", @autoit_locators)
49
52
  end
50
53
 
51
54
  # @see RAutomation::TextField#exists?
52
55
  def exists?
53
- not Window.autoit.ControlGetHandle(@window.locator_hwnd, "", @locators).empty?
56
+ not Window.autoit.ControlGetHandle(@window.locator_hwnd, "", @autoit_locators).empty?
54
57
  end
55
58
  end
56
59
  end
57
60
  end
58
- end
61
+ end
@@ -30,9 +30,9 @@ module RAutomation
30
30
  # @private
31
31
  # Special-cased locators
32
32
  LOCATORS = {
33
- [:title, Regexp] => :regexptitle,
34
- :index => :instance,
35
- :hwnd => :handle
33
+ [:title, Regexp] => :regexptitle,
34
+ :index => :instance,
35
+ :hwnd => :handle
36
36
  }
37
37
 
38
38
  # Creates the window object.
@@ -46,6 +46,8 @@ module RAutomation
46
46
  # @see RAutomation::Window#initialize
47
47
  def initialize(locators)
48
48
  @hwnd = locators[:hwnd]
49
+ @locator_index = locators.delete(:index) if locators[:index] && locators.size == 1
50
+ @locator_pid = locators.delete(:pid).to_i if locators[:pid]
49
51
  @locator_text = locators.delete(:text)
50
52
  extract(locators)
51
53
  end
@@ -54,14 +56,28 @@ module RAutomation
54
56
  # @note Searches only for visible windows.
55
57
  # @see RAutomation::Window#hwnd
56
58
  def hwnd
57
- @hwnd ||= @@autoit.WinList(@locators, @locator_text).pop.compact.
58
- find {|handle| self.class.new(:hwnd => handle.hex).visible?}.
59
- hex rescue nil
59
+ @hwnd ||= begin
60
+ locators = @autoit_locators
61
+ if @locator_index || @locator_pid
62
+ # @todo Come up with some better solution for this case
63
+ locators = "[regexptitle:]" # match all, needed for the case when only :index or :pid is used
64
+ end
65
+ windows = @@autoit.WinList(locators, @locator_text).pop.compact.
66
+ map {|handle| self.class.new(:hwnd => handle.hex)}
67
+ windows.delete_if {|window| !window.visible?}
68
+
69
+ if @locator_pid
70
+ window = windows.find {|win| win.pid == @locator_pid}
71
+ else
72
+ window = windows[@locator_index || 0]
73
+ end
74
+ window ? window.hwnd : nil
75
+ end
60
76
  end
61
77
 
62
78
  # @see RAutomation::Window#pid
63
79
  def pid
64
- @@autoit.WinGetProcess(hwnd)
80
+ @@autoit.WinGetProcess(locator_hwnd).to_i
65
81
  end
66
82
 
67
83
  # @see RAutomation::Window#title
@@ -1,12 +1,18 @@
1
1
  begin
2
- gem "ffi", "0.6.3"
2
+ gem "ffi"
3
3
  rescue Gem::LoadError
4
- raise Gem::LoadError, "Unable to load FFI gem. Install it with:\n\tgem install ffi -v 0.6.3"
4
+ raise Gem::LoadError, "Unable to load FFI gem. Install it with:\n\tgem install ffi"
5
5
  end
6
6
  require "ffi"
7
7
  require File.dirname(__FILE__) + "/win_ffi/constants"
8
8
  require File.dirname(__FILE__) + "/win_ffi/functions"
9
9
  require File.dirname(__FILE__) + "/win_ffi/locators"
10
10
  require File.dirname(__FILE__) + "/win_ffi/window"
11
+ require File.dirname(__FILE__) + "/win_ffi/button_helper"
12
+ require File.dirname(__FILE__) + "/win_ffi/control"
11
13
  require File.dirname(__FILE__) + "/win_ffi/button"
12
- require File.dirname(__FILE__) + "/win_ffi/text_field"
14
+ require File.dirname(__FILE__) + "/win_ffi/checkbox"
15
+ require File.dirname(__FILE__) + "/win_ffi/radio"
16
+ require File.dirname(__FILE__) + "/win_ffi/text_field"
17
+ require File.dirname(__FILE__) + "/win_ffi/select_list"
18
+ require File.dirname(__FILE__) + "/win_ffi/table"
@@ -1,49 +1,18 @@
1
1
  module RAutomation
2
2
  module Adapter
3
3
  module WinFfi
4
- class Button
4
+ class Button < Control
5
5
  include WaitHelper
6
6
  include Locators
7
7
 
8
- # Creates the button object.
9
- # @note this method is not meant to be accessed directly, but only through {RAutomation::Window#button}!
10
- # @param [RAutomation::Window] window this button belongs to.
11
- # @param [Hash] locators for searching the button.
12
- # @option locators [String, Regexp] :value Value (text) of the button
13
- # @option locators [String, Regexp] :class Internal class name of the button
14
- # @option locators [String, Fixnum] :id Internal ID of the button
15
- # @option locators [String, Fixnum] :index 0-based index to specify n-th button if all other criteria match
16
- # @see RAutomation::Window#button
17
- def initialize(window, locators)
18
- @window = window
19
- extract(locators)
20
- end
21
-
22
- # @see RAutomation::Button#click
23
- def click
24
- clicked = false
25
- wait_until do
26
- hwnd = Functions.control_hwnd(@window.hwnd, @locators)
27
- @window.activate
28
- @window.active? &&
29
- Functions.set_control_focus(hwnd) &&
30
- Functions.control_click(hwnd) &&
31
- clicked = true # is clicked at least once
32
-
33
- block_given? ? yield : clicked && !exists?
34
- end
35
- end
8
+ # Default locators used for searching buttons.
9
+ DEFAULT_LOCATORS = {:class => /button/i}
36
10
 
37
11
  # @see RAutomation::Button#value
38
12
  def value
39
13
  Functions.control_value(Functions.control_hwnd(@window.hwnd, @locators))
40
14
  end
41
15
 
42
- # @see RAutomation::Button#exists?
43
- def exists?
44
- !!Functions.control_hwnd(@window.hwnd, @locators)
45
- end
46
-
47
16
  end
48
17
  end
49
18
  end
@@ -0,0 +1,24 @@
1
+ module RAutomation
2
+ module Adapter
3
+ module WinFfi
4
+ module ButtonHelper
5
+
6
+ def set?
7
+ control_hwnd = Functions.control_hwnd(@window.hwnd, @locators)
8
+ Functions.control_set? control_hwnd
9
+ end
10
+
11
+ # @todo call a windows function to do this without clicking
12
+ def clear
13
+ click {!set?} if set?
14
+ end
15
+
16
+ # @todo call a windows function to do this without clicking
17
+ def set
18
+ click {set?} unless set?
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end