uia 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,8 +1,12 @@
1
- === Version 0.1.1 / 2013-02-07
1
+ === Version 0.1.2 / 2014-02-11
2
+ * Enhancements
3
+ * Added #drag method to Element to drag the mouse within a client area of an element
4
+
5
+ === Version 0.1.1 / 2014-02-07
2
6
  * Bug Fixes
3
7
  * Prior to trying to click on an element, it needs to scroll to and focus it first
4
8
 
5
- === Version 0.1 / 2013-02-06
9
+ === Version 0.1 / 2014-02-06
6
10
  * Enhancements
7
11
  * changed #click to be clickable point only
8
12
  * added #click_center to try to click in the bounding_rectangle
Binary file
Binary file
@@ -114,12 +114,12 @@ namespace UIA.Helper
114
114
 
115
115
  public void ClickClickablePoint()
116
116
  {
117
- Clicker.ClickClickablePoint(_element);
117
+ Mouse.ClickClickablePoint(_element);
118
118
  }
119
119
 
120
120
  public void ClickCenter()
121
121
  {
122
- Clicker.ClickCenter(_element);
122
+ Mouse.ClickCenter(_element);
123
123
  }
124
124
 
125
125
  public static Element From(AutomationElement element)
@@ -6,7 +6,7 @@ using System.Windows.Forms;
6
6
 
7
7
  namespace UIA.Helper
8
8
  {
9
- public class Clicker
9
+ public class Mouse
10
10
  {
11
11
  [DllImport("user32.dll")]
12
12
  static extern void mouse_event(uint flags, uint x, uint y, uint data, int extraInfo);
@@ -21,6 +21,14 @@ namespace UIA.Helper
21
21
  private const uint MOUSEEVENTLF_LEFTDOWN = 0x2;
22
22
  private const uint MOUSEEVENTLF_LEFTUP = 0x4;
23
23
 
24
+ public static void Drag(int startX, int startY, int endX, int endY)
25
+ {
26
+ Cursor.Position = new System.Drawing.Point(startX, startY);
27
+ Down();
28
+ Cursor.Position = new System.Drawing.Point(endX, endY);
29
+ Up();
30
+ }
31
+
24
32
  public static void ClickClickablePoint(AutomationElement element)
25
33
  {
26
34
  Click(element, element.GetClickablePoint);
@@ -39,10 +47,20 @@ namespace UIA.Helper
39
47
  var point = GetPoint();
40
48
 
41
49
  Cursor.Position = new System.Drawing.Point((int) point.X, (int) point.Y);
42
- mouse_event(MOUSEEVENTLF_LEFTDOWN, 0, 0, 0, 0);
50
+ Down();
51
+ Up();
52
+ }
53
+
54
+ private static void Up()
55
+ {
43
56
  mouse_event(MOUSEEVENTLF_LEFTUP, 0, 0, 0, 0);
44
57
  }
45
58
 
59
+ private static void Down()
60
+ {
61
+ mouse_event(MOUSEEVENTLF_LEFTDOWN, 0, 0, 0, 0);
62
+ }
63
+
46
64
  private static Point Center(AutomationElement element)
47
65
  {
48
66
  try
@@ -46,7 +46,7 @@
46
46
  </ItemGroup>
47
47
  <ItemGroup>
48
48
  <Compile Include="AutomationPropertyCondition.cs" />
49
- <Compile Include="Clicker.cs" />
49
+ <Compile Include="Mouse.cs" />
50
50
  <Compile Include="Element.cs" />
51
51
  <Compile Include="Extensions.cs" />
52
52
  <Compile Include="Properties\AssemblyInfo.cs" />
@@ -0,0 +1,13 @@
1
+ #include "Stdafx.h"
2
+
3
+ using namespace UIA::Helper;
4
+
5
+ extern "C" {
6
+ __declspec(dllexport) void Mouse_Drag(const int startX, const int startY, const int endX, const int endY, char* errorInformation, const int errorInformationLength) {
7
+ try {
8
+ Mouse::Drag(startX, startY, endX, endY);
9
+ } catch(Exception^ e) {
10
+ StringHelper::CopyToUnmanagedString(e->Message, errorInformation, errorInformationLength);
11
+ }
12
+ }
13
+ }
@@ -92,6 +92,7 @@
92
92
  <ClCompile Include="ElementMethods.cpp" />
93
93
  <ClCompile Include="ExpandCollapseMethods.cpp" />
94
94
  <ClCompile Include="InvokePatternMethods.cpp" />
95
+ <ClCompile Include="MouseMethods.cpp" />
95
96
  <ClCompile Include="RangeValueMethods.cpp" />
96
97
  <ClCompile Include="SelectionItemMethods.cpp" />
97
98
  <ClCompile Include="SelectionMethods.cpp" />
@@ -86,5 +86,8 @@
86
86
  <ClCompile Include="TextMethods.cpp">
87
87
  <Filter>Source Files\Patterns</Filter>
88
88
  </ClCompile>
89
+ <ClCompile Include="MouseMethods.cpp">
90
+ <Filter>Source Files</Filter>
91
+ </ClCompile>
89
92
  </ItemGroup>
90
93
  </Project>
data/lib/uia/element.rb CHANGED
@@ -26,6 +26,22 @@ module Uia
26
26
  Library::Constants::ControlTypes.find(@default) { |_, v| v == @element.control_type_id }.first
27
27
  end
28
28
 
29
+ def drag(info)
30
+ start_x, start_y = info[:start]
31
+ end_x, end_y = info[:end]
32
+ left, top = bounding_rectangle
33
+
34
+ coords = [
35
+ left + start_x,
36
+ top + start_y,
37
+ left + end_x,
38
+ top + end_y
39
+ ]
40
+
41
+ focus
42
+ Library.drag *coords
43
+ end
44
+
29
45
  def send_keys(*keys)
30
46
  Library.send_keys @element, Keys.encode(keys)
31
47
  end
@@ -74,7 +90,9 @@ module Uia
74
90
  end
75
91
 
76
92
  def focus
77
- Library.focus(@element)
93
+ until focused?
94
+ Library.focus(@element)
95
+ end
78
96
  end
79
97
  end
80
98
  end
data/lib/uia/library.rb CHANGED
@@ -75,6 +75,9 @@ module Uia
75
75
  attach_throwable_function :focus, :Element_Focus, [:pointer], :void
76
76
  attach_throwable_function :refresh, :Element_Refresh, [:pointer], :void
77
77
 
78
+ # mouse methods
79
+ attach_throwable_function :drag, :Mouse_Drag, [:int, :int, :int, :int], :void
80
+
78
81
  # WindowPattern methods
79
82
  attach_throwable_function :window_information, :Window_Information, [:pointer], WindowInformation.by_ref
80
83
  attach_throwable_function :set_visual_state, :Window_SetVisualState, [:pointer, :string], :void
data/lib/uia/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Uia
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -5,6 +5,25 @@ describe Uia::Element do
5
5
  Given(:about_box) { wait_until { Uia.find_element(id: 'AboutBox') } }
6
6
  Given { element.as(:window).visual_state = :normal }
7
7
 
8
+ context '#drag' do
9
+ Given(:text_field) do
10
+ text_field = element.find(id: 'multiLineTextField')
11
+ text_field.send_keys ['this', :enter, 'is', :enter, 'multiple', :enter, 'lines']
12
+ text_field
13
+ end
14
+ Given(:dimensions) do
15
+ r = text_field.bounding_rectangle
16
+ {width: r[2], height: r[3]}
17
+ end
18
+
19
+ When do
20
+ text_field.drag start: [2, 2], end: [dimensions[:width], dimensions[:height]]
21
+ text_field.send_keys :backspace
22
+ end
23
+
24
+ Then { expect(text_field.as(:text).text).to eq('') }
25
+ end
26
+
8
27
  context 'properties' do
9
28
  let(:raw_element) { element.instance_variable_get(:@element) }
10
29
  Then { element.handle != 0 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-07 00:00:00.000000000 Z
12
+ date: 2014-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -139,9 +139,9 @@ files:
139
139
  - Rakefile
140
140
  - ext/.gitignore
141
141
  - ext/UiaDll/UIA.Helper/AutomationPropertyCondition.cs
142
- - ext/UiaDll/UIA.Helper/Clicker.cs
143
142
  - ext/UiaDll/UIA.Helper/Element.cs
144
143
  - ext/UiaDll/UIA.Helper/Extensions.cs
144
+ - ext/UiaDll/UIA.Helper/Mouse.cs
145
145
  - ext/UiaDll/UIA.Helper/Properties/AssemblyInfo.cs
146
146
  - ext/UiaDll/UIA.Helper/UIA.Helper.csproj
147
147
  - ext/UiaDll/UiaDll.Test/AssemblyInfo.cpp
@@ -168,6 +168,7 @@ files:
168
168
  - ext/UiaDll/UiaDll/ElementStructures.h
169
169
  - ext/UiaDll/UiaDll/ExpandCollapseMethods.cpp
170
170
  - ext/UiaDll/UiaDll/InvokePatternMethods.cpp
171
+ - ext/UiaDll/UiaDll/MouseMethods.cpp
171
172
  - ext/UiaDll/UiaDll/PatternInformationStructures.h
172
173
  - ext/UiaDll/UiaDll/RangeValueMethods.cpp
173
174
  - ext/UiaDll/UiaDll/ReadMe.txt
@@ -249,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
249
250
  version: '0'
250
251
  segments:
251
252
  - 0
252
- hash: 302462739
253
+ hash: 237115197
253
254
  required_rubygems_version: !ruby/object:Gem::Requirement
254
255
  none: false
255
256
  requirements:
@@ -258,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
259
  version: '0'
259
260
  segments:
260
261
  - 0
261
- hash: 302462739
262
+ hash: 237115197
262
263
  requirements: []
263
264
  rubyforge_project:
264
265
  rubygems_version: 1.8.24