findcontrol 0.0.1

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.
@@ -0,0 +1,47 @@
1
+ require 'Win32API'
2
+
3
+ class FindControlGui
4
+
5
+ include GladeGUI
6
+ include Win32
7
+
8
+
9
+
10
+ def mousePosition
11
+ @@getCursorPos ||= Win32API.new("user32", "GetCursorPos", ['P'], 'V')
12
+ lpPoint = " " * 8 # store two LONGs
13
+ @@getCursorPos.Call(lpPoint)
14
+ lpPoint.unpack("ll") # get the actual values
15
+ end
16
+
17
+
18
+ def show()
19
+ load_glade(__FILE__)
20
+
21
+ my_path = File.expand_path(File.dirname(__FILE__))
22
+ @proj ||= Proj.new(File.join(my_path,"..", "lib", "testcomplete", "project", "AutomationPathProject", "AutomationPathProject.pjs").gsub("/","\\"))
23
+
24
+ @image1 = my_path + "/crosshairs.jpg"
25
+ set_glade_all()
26
+
27
+ target_flags = Gtk::Drag::TARGET_OTHER_APP #useless
28
+ action = Gdk::DragContext::ACTION_COPY #useless
29
+ dest = Gtk::Drag::DEST_DEFAULT_ALL #useless
30
+ button = Gdk::Window::BUTTON1_MASK #mouse button 1
31
+
32
+ Gtk::Drag.source_set(@builder["button1"], button, [ ], action)
33
+
34
+
35
+ show_window()
36
+ end
37
+
38
+ def button1__drag_failed(*argv)
39
+ @loc = mousePosition
40
+ control_path=@proj.get_control_automation_path_from_location(@loc[0], @loc[1], @builder["include_text"].active?)
41
+ Clipboard.set_data(control_path)
42
+ @builder["label1"].text = control_path
43
+ false
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,85 @@
1
+ <?xml version="1.0"?>
2
+ <interface>
3
+ <requires lib="gtk+" version="2.16"/>
4
+ <!-- interface-naming-policy project-wide -->
5
+ <object class="GtkWindow" id="window1">
6
+ <property name="visible">True</property>
7
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_STRUCTURE_MASK</property>
8
+ <property name="resizable">False</property>
9
+ <property name="modal">True</property>
10
+ <property name="window_position">mouse</property>
11
+ <signal name="destroy" handler="destroy_window"/>
12
+ <child>
13
+ <object class="GtkVBox" id="vbox2">
14
+ <property name="visible">True</property>
15
+ <child>
16
+ <object class="GtkHBox" id="hbox2">
17
+ <property name="visible">True</property>
18
+ <child>
19
+ <object class="GtkLabel" id="label3">
20
+ <property name="visible">True</property>
21
+ <property name="xalign">0</property>
22
+ <property name="label" translatable="yes">Control Path:</property>
23
+ </object>
24
+ <packing>
25
+ <property name="expand">False</property>
26
+ <property name="position">0</property>
27
+ </packing>
28
+ </child>
29
+ <child>
30
+ <object class="GtkCheckButton" id="include_text">
31
+ <property name="label" translatable="yes">include text?</property>
32
+ <property name="visible">True</property>
33
+ <property name="can_focus">True</property>
34
+ <property name="receives_default">False</property>
35
+ <property name="draw_indicator">True</property>
36
+ </object>
37
+ <packing>
38
+ <property name="expand">False</property>
39
+ <property name="padding">43</property>
40
+ <property name="position">1</property>
41
+ </packing>
42
+ </child>
43
+ <child>
44
+ <object class="GtkButton" id="button1">
45
+ <property name="label" translatable="yes">DragMe</property>
46
+ <property name="visible">True</property>
47
+ <property name="can_focus">True</property>
48
+ <property name="receives_default">True</property>
49
+ <property name="image">image1</property>
50
+ </object>
51
+ <packing>
52
+ <property name="position">2</property>
53
+ </packing>
54
+ </child>
55
+ </object>
56
+ <packing>
57
+ <property name="position">0</property>
58
+ </packing>
59
+ </child>
60
+ <child>
61
+ <object class="GtkHBox" id="hbox1">
62
+ <property name="visible">True</property>
63
+ <child>
64
+ <object class="GtkLabel" id="label1">
65
+ <property name="visible">True</property>
66
+ <property name="label" translatable="yes">label</property>
67
+ </object>
68
+ <packing>
69
+ <property name="position">0</property>
70
+ </packing>
71
+ </child>
72
+ </object>
73
+ <packing>
74
+ <property name="padding">5</property>
75
+ <property name="position">1</property>
76
+ </packing>
77
+ </child>
78
+ </object>
79
+ </child>
80
+ </object>
81
+ <object class="GtkImage" id="image1">
82
+ <property name="visible">True</property>
83
+ <property name="stock">gtk-missing-image</property>
84
+ </object>
85
+ </interface>
@@ -0,0 +1,117 @@
1
+ require 'win32ole'
2
+ require 'rubygems'
3
+ require 'pry'
4
+
5
+ include WIN32OLE::VARIANT
6
+
7
+
8
+ class TCLibrary
9
+ def initialize(name, tc)
10
+ @framework, @unit = name.split(".")
11
+ @integration = tc.integration
12
+ end
13
+ def method_missing(meth, *args, &blk)
14
+ @integration.RunRoutineEx(@framework, @unit, meth.to_s, WIN32OLE_VARIANT.new(args.map{|a|
15
+ a.is_a?(String) ? WIN32OLE_VARIANT.new(a, VT_BSTR) : WIN32OLE_VARIANT.new(a, VT_VARIANT|VT_BYREF)}
16
+ ))
17
+ end
18
+ end
19
+
20
+ class TC
21
+ def initialize
22
+ @tc = TC.get_TC
23
+ end
24
+
25
+ def library(name)
26
+ TCLibrary.new(name, @tc)
27
+ end
28
+
29
+ def method_missing(meth, *args, &blk)
30
+ @tc.send(meth, *args, &blk)
31
+ end
32
+
33
+ def StartProcess(executable, parameter, timeout)
34
+ shell = WIN32OLE.new('WScript.Shell')
35
+ shell.Run("#{executable} \"#{parameter}\"")
36
+
37
+ processName = executable.split(/[\/\\]/).last.split(/\./).first
38
+ sys = @tc.GetObjectByName("Sys")
39
+ x = Now + timeout
40
+
41
+ begin
42
+ process = sys.Find("ProcessName", processName)
43
+ end while(!process.Exists && Now < x)
44
+ return process
45
+ end
46
+
47
+
48
+ def LaunchIe(url, timeout)
49
+ executable = "C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe"
50
+ StartProcess(executable, url, timeout)
51
+ end
52
+
53
+ private
54
+ def self.get_TC
55
+ tc = get_OLE("TestComplete.TestCompleteApplication.8")
56
+ tc = get_OLE("TestExecute.TestExecuteApplication.8") unless tc
57
+ tc
58
+ end
59
+
60
+ def self.get_OLE(strAutomationEngine)
61
+ begin
62
+ tc = WIN32OLE.connect(strAutomationEngine)
63
+ rescue WIN32OLERuntimeError
64
+ begin
65
+ tc = WIN32OLE.new(strAutomationEngine)
66
+ rescue WIN32OLERuntimeError
67
+ end
68
+ end
69
+ tc
70
+ end
71
+ end
72
+
73
+ def run_test(filename)
74
+ integration = TC.new.integration
75
+ raise("Test Complete is already Running a test") if(integration.IsRunning)
76
+ integration.OpenProjectSuite("C:\\LeicaAutomation\\LeicaAutomation.pjs")
77
+ integration.RunRoutineEx("Framework", "MainProcessors", "ExecuteStandaloneTest", WIN32OLE_VARIANT.new(filename, VT_BSTR))
78
+
79
+ sleep(1) while integration.IsRunning
80
+ end
81
+
82
+ def run_qc_test_or_timeout(testId, runId, timeout_time, i= nil)
83
+ integration = i || TC.get_TC.integration
84
+ raise("Test Complete is already Running a test") if(integration.IsRunning)
85
+ integration.OpenProjectSuite("C:\\LeicaAutomation\\LeicaAutomation.pjs")
86
+ integration.RunRoutineEx("Framework", "MainProcessors", "ExecuteFromQC", WIN32OLE_VARIANT.new( "#{testId}|#{runId}", VT_BSTR))
87
+ sleep(1) while integration.IsRunning
88
+ end
89
+
90
+ def PageLoaded(process)
91
+ page = process.Page("*")
92
+ return false if !page.Exists
93
+ end
94
+
95
+ # exit if Object.const_defined?(:Ocra)
96
+
97
+ # if(__FILE__ == $0 )
98
+
99
+ # filename = ARGV[0] || "\\\\bedrock\\bsd srg\\Projects\\Tool Validation\\Automation framework\\Verification\\CerebroAutomation\\nigel.ts"
100
+
101
+ # tc = TC.new
102
+ # integration = tc.integration
103
+ # Sys = integration.GetObjectByName("Sys")
104
+ # #run_qc_test_or_timeout(1515, 485, Time.now + 120, integration)
105
+ # #puts integration.GetLastResultDescription().Status == 0 ? "Passed" : "Failed"
106
+ # integration.OpenProjectSuite("C:\\LeicaAutomation\\LeicaAutomation.pjs")
107
+
108
+ # kw = tc.library("Framework.CommonKeywords")
109
+ # ac = tc.library("Framework.ApplicationClass")
110
+ # pc = tc.library("Framework.ProcessClass")
111
+ # fl = tc.library("Framework.FrameworkLibrary")
112
+ # fl.Framework_Initialise
113
+
114
+ # binding.pry
115
+
116
+ # end
117
+
data/findcontrol.rb ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'vrlib'
4
+ require 'win32ole'
5
+ require 'win32/clipboard'
6
+
7
+ #make program output in real time so errors visible in VR.
8
+ STDOUT.sync = true
9
+ STDERR.sync = true
10
+
11
+ #everything in these directories will be included
12
+ my_path = File.expand_path(File.dirname(__FILE__))
13
+ require_all Dir.glob(my_path + "/bin/**/*.rb")
14
+ require_all Dir.glob(my_path + "/lib/*.rb")
15
+
16
+ FindControlGui.new().show
17
+
18
+
19
+
20
+ # begin
21
+ # @proj ||= Proj.new(File.join(my_path, "lib", "testcomplete", "project", "AutomationPathProject", "AutomationPathProject.pjs").gsub("/","\\"))
22
+ # control_path=@proj.AutomationPathProject.Helper.GetAutomationPathForControlUnderMouse
23
+ # Clipboard.set_data(control_path)
24
+ # puts control_path
25
+ # rescue => e
26
+ # puts e
27
+ # end
28
+
data/lib/TCLib.rb ADDED
@@ -0,0 +1,162 @@
1
+ require 'win32ole'
2
+ require 'rubygems'
3
+ require 'pry'
4
+
5
+ include WIN32OLE::VARIANT
6
+
7
+ class String
8
+ def strip_quotes
9
+ gsub(/\A['"]+|['"]+\Z/, "").gsub("\\\\","\\")
10
+ end
11
+ end
12
+
13
+ class TCFramework
14
+ def initialize(name, tc)
15
+ @name, @tc = name, tc
16
+ end
17
+
18
+ private
19
+ def method_missing(meth, *args, &blk)
20
+ TCLibrary.new(@name+"."+meth.to_s, @tc)
21
+ end
22
+ end
23
+
24
+ class TCLibrary
25
+ def initialize(name, tc)
26
+ @framework, @unit = name.split(".")
27
+ @integration = tc.integration
28
+ end
29
+
30
+ private
31
+ def method_missing(meth, *args, &blk)
32
+ raise("Test Complete is already Running a test") if(@integration.IsRunning)
33
+ @integration.RunRoutineEx(@framework, @unit, meth.to_s, WIN32OLE_VARIANT.new(args.map{|a|
34
+ a.is_a?(String) ? WIN32OLE_VARIANT.new(a, VT_BSTR) : WIN32OLE_VARIANT.new(a, VT_VARIANT|VT_BYREF)}
35
+ ))
36
+ while @integration.IsRunning
37
+ sleep(1)
38
+ end
39
+ @integration.RoutineResult
40
+ end
41
+ end
42
+
43
+ class Proj
44
+ def initialize(proj_file)
45
+ @tc = TC.new
46
+ @integration = @tc.integration
47
+ raise("Test Complete is already Running a test") if(@integration.IsRunning)
48
+ if (!@integration.IsProjectSuiteOpened || @integration.ProjectSuiteFileName != proj_file)
49
+ @suite = @integration.OpenProjectSuite(proj_file)
50
+ end
51
+ raise "can't open project" unless @integration.IsProjectSuiteOpened
52
+ end
53
+
54
+ def get_current_control_automation_path(include_text = true)
55
+ sys = @integration.GetObjectByName("Sys")
56
+ get_control_automation_path_from_location(sys.Desktop.MouseX, sys.Desktop.MouseY, include_text)
57
+ end
58
+
59
+ def get_control_automation_path_from_location(x,y,include_text)
60
+ sys = @integration.GetObjectByName("Sys")
61
+ sys.Refresh
62
+ objTest = sys.Desktop.ObjectFromPoint( x, y )
63
+ get_automation_path(objTest, include_text)
64
+ end
65
+
66
+ private
67
+
68
+ def get_automation_path(object, include_text)
69
+ object = object.Parent until object.nil? || object.Name.to_s.start_with?("UIAObject")
70
+ return "" unless object && object.Exists
71
+ return "Process" if(object.Name.to_s.start_with? "Process")
72
+ return "#{get_automation_path(object.Parent, include_text)}/#{get_automation_name(object, include_text)}"
73
+ end
74
+
75
+ def get_automation_name(object, include_text)
76
+ return "" if object.nil?
77
+ begin
78
+ automation_id = object.AutomationID
79
+ rescue
80
+ end
81
+ begin
82
+ class_name = object.ClassName
83
+ rescue
84
+ end
85
+ begin
86
+ text = object.NativeUIAObject.Name if include_text
87
+ rescue
88
+ end
89
+
90
+ id= ''
91
+ id+= automation_id if automation_id && automation_id.is_a?(String) && !automation_id.empty?
92
+ id+= "(#{class_name})" if class_name && class_name.is_a?(String) && !class_name.empty?
93
+ id+= "\"#{text}\"" if text && text.is_a?(String) && !text.empty?
94
+ id+= "Unknown Control" if id.empty?
95
+ id
96
+ end
97
+
98
+ def method_missing(meth, *args, &blk)
99
+ TCFramework.new(meth.to_s, @tc)
100
+ end
101
+ end
102
+
103
+ class TC
104
+ def initialize
105
+ @tc = TC.get_TC
106
+ end
107
+
108
+ def self.get_TC
109
+ tc = get_OLE("TestComplete.TestCompleteApplication.8")
110
+ tc = get_OLE("TestExecute.TestExecuteApplication.8") unless tc
111
+ tc
112
+ end
113
+
114
+ def self.get_OLE(strAutomationEngine)
115
+ begin
116
+ tc = WIN32OLE.connect(strAutomationEngine)
117
+ rescue WIN32OLERuntimeError
118
+ begin
119
+ tc = WIN32OLE.new(strAutomationEngine)
120
+ rescue WIN32OLERuntimeError
121
+ end
122
+ end
123
+ tc
124
+ end
125
+
126
+ def library(name)
127
+ TCLibrary.new(name, @tc)
128
+ end
129
+
130
+ def method_missing(meth, *args, &blk)
131
+ @tc.send(meth, *args, &blk)
132
+ end
133
+
134
+ def StartProcess(executable, parameter, timeout)
135
+ shell = WIN32OLE.new('WScript.Shell')
136
+ shell.Run("#{executable} \"#{parameter}\"")
137
+
138
+ processName = executable.split(/[\/\\]/).last.split(/\./).first
139
+ sys = @tc.integration.GetObjectByName("Sys")
140
+ x = Now + timeout
141
+
142
+ begin
143
+ process = sys.Find("ProcessName", processName)
144
+ end while(!process.Exists && Now < x)
145
+ return process
146
+ end
147
+
148
+ def LaunchIe(url, timeout)
149
+ executable = "C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe"
150
+ StartProcess(executable, url, timeout)
151
+ end
152
+ end
153
+
154
+ if $0 == __FILE__
155
+ #testId, runId = *ARGV
156
+
157
+ #proj = Proj.new("C:\\LeicaAutomation\\LeicaAutomation.pjs")
158
+ #proj.run_qc_test_or_timeout(testId, runId)
159
+
160
+ proj.get_current_control_automation_path
161
+
162
+ end
@@ -0,0 +1,71 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE Nodes [
3
+
4
+ <!ENTITY % NameValue "CDATA">
5
+ <!ENTITY % PropType "(I|S|D|L|H|B)">
6
+ <!ENTITY % VersionValue "CDATA">
7
+
8
+ <!ELEMENT Prp (#PCDATA)>
9
+ <!ELEMENT Node (Node|Prp)*>
10
+ <!ELEMENT Nodes (Node)+>
11
+
12
+ <!ATTLIST Nodes version CDATA "1">
13
+
14
+ <!ATTLIST Node name CDATA #REQUIRED>
15
+
16
+ <!ATTLIST Prp name CDATA #REQUIRED>
17
+ <!ATTLIST Prp type CDATA #REQUIRED>
18
+ <!ATTLIST Prp value CDATA #REQUIRED>
19
+ ]>
20
+ <Nodes version="1">
21
+ <Node name="root">
22
+ <Node name="analysis">
23
+ <Prp name="key" type="S" value="{04BF666E-7F31-473C-A151-12DF5C009F71}"/>
24
+ </Node>
25
+ <Node name="child list">
26
+ <Node name="item0000000000">
27
+ <Node name="item data">
28
+ <Prp name="relpath" type="S" value="AutomationPathProject\AutomationPathProject.mds"/>
29
+ </Node>
30
+ <Prp name="index" type="I" value="0"/>
31
+ <Prp name="key" type="S" value="{9216F808-DE60-489C-AF9C-530CCDDD2B35}"/>
32
+ <Prp name="type" type="S" value="{362A8EE5-675E-43A9-869D-06ECE80B0CB4}"/>
33
+ <Prp name="typename" type="S" value="Project"/>
34
+ </Node>
35
+ </Node>
36
+ <Node name="files">
37
+ <Node name="automationpathproject\automationpathproject.mds"/>
38
+ </Node>
39
+ <Node name="folders">
40
+ <Node name="folders"/>
41
+ </Node>
42
+ <Node name="scc"/>
43
+ <Node name="settings">
44
+ <Node name="{5a85e200-b5d2-4f74-972a-0221f2956a19}">
45
+ <Prp name="type" type="I" value="5"/>
46
+ <Prp name="value" type="S" value="Log"/>
47
+ </Node>
48
+ <Prp name="key" type="S" value="{83202538-1411-4CA8-BFEF-AABB8A57D941}"/>
49
+ <Prp name="settingsversion" type="S" value="8.70"/>
50
+ </Node>
51
+ <Node name="test data">
52
+ <Node name="child list">
53
+ <Node name="item0000000000">
54
+ <Prp name="description" type="S" value=""/>
55
+ <Prp name="enabled" type="B" value="-1"/>
56
+ <Prp name="index" type="I" value="0"/>
57
+ <Prp name="key" type="S" value="{9216F808-DE60-489C-AF9C-530CCDDD2B35}"/>
58
+ <Prp name="stoponerror" type="B" value="-1"/>
59
+ <Prp name="timeout" type="I" value="0"/>
60
+ </Node>
61
+ </Node>
62
+ <Prp name="key" type="S" value="{C1B71503-885A-47E1-82DD-9C8D1DB24D8C}"/>
63
+ </Node>
64
+ <Node name="variables">
65
+ <Prp name="key" type="S" value="{93F2EC91-B2B2-491E-AE45-7DA877EA87CE}"/>
66
+ </Node>
67
+ <Prp name="key" type="S" value="{5A62B844-22C0-40D8-89C8-678519FAB81E}"/>
68
+ <Prp name="signature" type="S" value="{24B6FA0B-0143-461A-9758-AEB9E9A9428B}"/>
69
+ <Prp name="version" type="S" value="8.0"/>
70
+ </Node>
71
+ </Nodes>