te3270 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,78 @@
1
+
2
+ module TE3270
3
+ #
4
+ # Creates methods that are mixed in with the +TE3270+ module that represent all of the
5
+ # function keys that can be send to the system. These keys would typically be sent to
6
+ # the +send_keys_ method.
7
+ #
8
+ # @example Using a function key
9
+ # on(MyScreen).send_keys TE3270.Enter
10
+ #
11
+ module FunctionKeys
12
+
13
+ KEYS = [
14
+ 'Attn',
15
+ 'BackSpace',
16
+ 'BackTab',
17
+ 'CapsLock',
18
+ 'Clear',
19
+ 'Down',
20
+ 'Left',
21
+ 'Left2',
22
+ 'Right',
23
+ 'Right2',
24
+ 'CursorSelect',
25
+ 'Up',
26
+ 'Delete',
27
+ 'Dup',
28
+ 'Enter',
29
+ 'EraseEOF',
30
+ 'EraseInput',
31
+ 'FieldMark',
32
+ 'Home',
33
+ 'Insert',
34
+ 'BackTab',
35
+ 'NewLIne',
36
+ 'PenSel',
37
+ 'Print',
38
+ 'Reset',
39
+ 'ShiftOn',
40
+ 'SysReq',
41
+ 'Tab',
42
+ 'Pa1',
43
+ 'Pa2',
44
+ 'Pa3',
45
+ 'Pf1',
46
+ 'Pf2',
47
+ 'Pf3',
48
+ 'Pf4',
49
+ 'Pf5',
50
+ 'Pf6',
51
+ 'Pf7',
52
+ 'Pf8',
53
+ 'Pf9',
54
+ 'Pf10',
55
+ 'Pf11',
56
+ 'Pf12',
57
+ 'Pf13',
58
+ 'Pf14',
59
+ 'Pf15',
60
+ 'Pf16',
61
+ 'Pf17',
62
+ 'Pf18',
63
+ 'Pf19',
64
+ 'Pf20',
65
+ 'Pf21',
66
+ 'Pf22',
67
+ 'Pf23',
68
+ 'Pf24',
69
+ ]
70
+
71
+ KEYS.each do |key|
72
+ define_method(key) do
73
+ "<#{key}>"
74
+ end
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,50 @@
1
+ require 'page_navigation'
2
+
3
+ module TE3270
4
+ #
5
+ # Module to facilitate to creating of screen objects in step definitions. You
6
+ # can make the methods below available to all of your step definitions by adding
7
+ # this module to World.
8
+ #
9
+ # @example Making the ScreenFactory available to your step definitions
10
+ # World TE3270::ScreenFactory
11
+ #
12
+ # @example using a screen in a Scenario
13
+ # on MyScreen do |screen|
14
+ # screen.name = 'Cheezy'
15
+ # end
16
+ #
17
+ # If you plan to use the +navigate_to+ method you will need to ensure
18
+ # you setup the possible routes ahead of time. You must always have
19
+ # a default route in order for this to work. Here is an example of
20
+ # how you define routes:
21
+ #
22
+ # @example Example routes defined in env.rb
23
+ # TE3270::ScreenFactory.routes = {
24
+ # :default => [[ScreenOne,:method1], [ScreenTwo,:method2], [ScreenThree,:method3]],
25
+ # :another_route => [[ScreenOne,:method1, "arg1"], [ScreenTwo,:method2b], [ScreenThree,:method3]]
26
+ # }
27
+ #
28
+ # Notice the first entry of :another_route is passing an argument
29
+ # to the method.
30
+ #
31
+ module ScreenFactory
32
+ include PageNavigation
33
+
34
+ #
35
+ # Create a screen object. Also sets an instance variable +@current_screen
36
+ #
37
+ # @param [Class] screen_class a class that has included the TE3270 module
38
+ # @param [block] an optional block to be called
39
+ # @return [ScreenObject] the newly created screen object
40
+ #
41
+ def on(screen_class, &block)
42
+ return super(screen_class, &block) unless screen_class.ancestors.include? TE3270
43
+ raise '@emulator instance variable must be available to use the ScreenFactory methods' unless @emulator
44
+ @current_screen = screen_class.new @emulator
45
+ block.call @current_screen if block
46
+ @current_screen
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,33 @@
1
+
2
+ module TE3270
3
+ module ScreenPopulator
4
+
5
+ #
6
+ # This method will populate all matched screen text fields from the
7
+ # Hash passed as an argument. The way it find an element is by
8
+ # matching the Hash key to the name you provided when declaring
9
+ # the text field on your screen.
10
+ #
11
+ # @example
12
+ # class ExampleScreen
13
+ # include TE3270
14
+ #
15
+ # text_field(:username, 1, 2, 20)
16
+ # end
17
+ #
18
+ # ...
19
+ #
20
+ # @emulator = TE3270::emulator_for :quick3270
21
+ # example_screen = ExampleScreen.new(@emulator)
22
+ # example_screen.populate_screen_with :username => 'a name'
23
+ #
24
+ # @param [Hash] hsh the data to use to populate this screen.
25
+ #
26
+ def populate_screen_with(hsh)
27
+ hsh.each do |key, value|
28
+ self.send("#{key}=", value) if self.respond_to? "#{key}=".to_sym
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ module TE3270
2
+ VERSION = "0.6.0"
3
+ end
4
+
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ class AccessorsTestScreen
4
+ include TE3270
5
+
6
+ text_field(:method_name, 1, 2, 10, true)
7
+ text_field(:read_only, 2, 3, 12, false)
8
+ text_field(:default_editable, 3, 4, 14)
9
+ end
10
+
11
+ describe TE3270::Accessors do
12
+
13
+ let(:platform) { double('platform') }
14
+ let(:screen_object) { AccessorsTestScreen.new platform }
15
+
16
+ before(:each) do
17
+ screen_object.stub(:platform).and_return platform
18
+ end
19
+
20
+ describe "text_field accessors" do
21
+
22
+ it 'should generate a method to retrieve the value' do
23
+ screen_object.should respond_to :method_name
24
+ end
25
+
26
+ it 'should generate a method to set the value' do
27
+ screen_object.should respond_to :method_name=
28
+ end
29
+
30
+ it 'should not generate a method to set the value if it is not editable' do
31
+ screen_object.should_not respond_to :read_only=
32
+ end
33
+
34
+ it 'should default to being editable when it is not specified' do
35
+ screen_object.should respond_to :default_editable=
36
+ end
37
+
38
+ it 'should use the platform to get the text value' do
39
+ platform.should_receive(:get_string).with(1, 2, 10).and_return('abc')
40
+ screen_object.method_name.should == 'abc'
41
+ end
42
+
43
+ it 'should use the platform to set the text value' do
44
+ platform.should_receive(:put_string).with('abc', 1, 2)
45
+ screen_object.method_name = 'abc'
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,186 @@
1
+ if Gem.win_platform?
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TE3270::Emulators::Extra do
6
+
7
+ let(:extra) { TE3270::Emulators::Extra.new }
8
+
9
+ before(:each) do
10
+ WIN32OLE.stub(:new).and_return extra_system
11
+ extra.instance_variable_set(:@session_file, 'the_file')
12
+ File.stub(:exists).and_return false
13
+ end
14
+
15
+
16
+ describe "global behaviors" do
17
+ it 'should start a new terminal' do
18
+ WIN32OLE.should_receive(:new).and_return(extra_system)
19
+ extra.connect
20
+ end
21
+
22
+ it 'should open a session' do
23
+ extra_sessions.should_receive(:Open).and_return(extra_session)
24
+ extra.connect
25
+ end
26
+
27
+ it 'should not display the splash screen if version is higher than 9' do
28
+ extra_system.should_receive(:Version).and_return("9.2")
29
+ extra_sessions.should_receive(:VisibleOnStartup=).with(true)
30
+ extra.connect
31
+ end
32
+
33
+ it 'should call a block allowing the session file to be set' do
34
+ extra_sessions.should_receive(:Open).with('blah.edp').and_return(extra_session)
35
+ extra.connect do |platform|
36
+ platform.session_file = 'blah.edp'
37
+ end
38
+ end
39
+
40
+ it 'should raise an error when the session file is not set' do
41
+ extra.instance_variable_set(:@session_file, nil)
42
+ expect { extra.connect }.to raise_error('The session file must be set in a block when calling connect with the Extra emulator.')
43
+ end
44
+
45
+ it 'should take the visible value from a block' do
46
+ extra_session.should_receive(:Visible=).with(false)
47
+ extra.connect do |platform|
48
+ platform.visible = false
49
+ end
50
+ end
51
+
52
+ it 'should default to visible when not specified' do
53
+ extra_session.should_receive(:Visible=).with(true)
54
+ extra.connect
55
+ end
56
+
57
+ it 'should take the window state value from the block' do
58
+ extra_session.should_receive(:WindowState=).with(2)
59
+ extra.connect do |platform|
60
+ platform.window_state = :maximized
61
+ end
62
+ end
63
+
64
+ it 'should default to window state normal when not specified' do
65
+ extra_session.should_receive(:WindowState=).with(1)
66
+ extra.connect
67
+ end
68
+
69
+ it 'should default to being visible' do
70
+ extra_session.should_receive(:Visible=).with(true)
71
+ extra.connect
72
+ end
73
+
74
+ it 'should get the screen for the active session' do
75
+ extra_session.should_receive(:Screen).and_return(extra_screen)
76
+ extra.connect
77
+ end
78
+
79
+ it 'should get the area from the screen' do
80
+ extra_screen.should_receive(:SelectAll).and_return(extra_area)
81
+ extra.connect
82
+ end
83
+
84
+ it 'should disconnect from a session' do
85
+ extra_session.should_receive(:Close)
86
+ extra.connect
87
+ extra.disconnect
88
+ end
89
+ end
90
+
91
+ describe "interacting with text fields" do
92
+ it 'should get the value from the screen' do
93
+ extra_screen.should_receive(:GetString).with(1, 2, 10).and_return('blah')
94
+ extra.connect
95
+ extra.get_string(1, 2, 10).should == 'blah'
96
+ end
97
+
98
+ it 'should put the value on the screen' do
99
+ wait_collection = double('wait')
100
+ extra_screen.should_receive(:PutString).with('blah', 1, 2)
101
+ extra_screen.should_receive(:WaitHostQuiet).and_return(wait_collection)
102
+ wait_collection.should_receive(:Wait).with(1000)
103
+ extra.connect
104
+ extra.put_string('blah', 1, 2)
105
+ end
106
+ end
107
+
108
+ describe "interacting with the screen" do
109
+ it 'should know how to send function keys' do
110
+ wait_collection = double('wait')
111
+ extra_screen.should_receive(:SendKeys).with('<Clear>')
112
+ extra_screen.should_receive(:WaitHostQuiet).and_return(wait_collection)
113
+ wait_collection.should_receive(:Wait).with(1000)
114
+ extra.connect
115
+ extra.send_keys(TE3270.Clear)
116
+ end
117
+
118
+ it 'should wait for a string to appear' do
119
+ wait_col = double('wait')
120
+ extra_screen.should_receive(:WaitForString).with('The String', 3, 10).and_return(wait_col)
121
+ extra_system.should_receive(:TimeoutValue).and_return(30000)
122
+ wait_col.should_receive(:Wait).with(30000)
123
+ extra.connect
124
+ extra.wait_for_string('The String', 3, 10)
125
+ end
126
+
127
+ it 'should wait for the host to be quiet' do
128
+ wait_col = double('wait')
129
+ extra_screen.should_receive(:WaitHostQuiet).and_return(wait_col)
130
+ wait_col.should_receive(:Wait).with(4000)
131
+ extra.connect
132
+ extra.wait_for_host(4)
133
+ end
134
+
135
+ it 'should wait until the cursor is at a position' do
136
+ wait_col = double('wait')
137
+ extra_screen.should_receive(:WaitForCursor).with(5, 8).and_return(wait_col)
138
+ extra_system.should_receive(:TimeoutValue).and_return(30000)
139
+ wait_col.should_receive(:Wait).with(30000)
140
+ extra.connect
141
+ extra.wait_until_cursor_at(5, 8)
142
+ end
143
+
144
+ it 'should take screenshots' do
145
+ take = double('Take')
146
+ extra_session.should_receive(:WindowHandle).and_return(123)
147
+ Win32::Screenshot::Take.should_receive(:of).with(:window, hwnd: 123).and_return(take)
148
+ take.should_receive(:write).with('image.png')
149
+ extra.connect
150
+ extra.screenshot('image.png')
151
+ end
152
+
153
+ it 'should make the window visible before taking a screenshot' do
154
+ take = double('Take')
155
+ extra_session.should_receive(:WindowHandle).and_return(123)
156
+ Win32::Screenshot::Take.should_receive(:of).with(:window, hwnd: 123).and_return(take)
157
+ take.should_receive(:write).with('image.png')
158
+ extra_session.should_receive(:Visible=).once.with(true)
159
+ extra_session.should_receive(:Visible=).twice.with(false)
160
+ extra.connect do |emulator|
161
+ emulator.visible = false
162
+ end
163
+ extra.screenshot('image.png')
164
+ end
165
+
166
+ it 'should delete the file for the screenshot if it already exists' do
167
+ File.should_receive(:exists?).and_return(true)
168
+ File.should_receive(:delete)
169
+ take = double('Take')
170
+ extra_session.should_receive(:WindowHandle).and_return(123)
171
+ Win32::Screenshot::Take.should_receive(:of).with(:window, hwnd: 123).and_return(take)
172
+ take.should_receive(:write).with('image.png')
173
+ extra.connect
174
+ extra.screenshot('image.png')
175
+ end
176
+
177
+ it "should get the screen text" do
178
+ extra_area.should_receive(:Value).and_return('blah')
179
+ extra.connect
180
+ extra.text.should == 'blah'
181
+ end
182
+
183
+ end
184
+ end
185
+
186
+ end
@@ -0,0 +1,170 @@
1
+ if Gem.win_platform?
2
+
3
+ require 'spec_helper'
4
+
5
+ describe TE3270::Emulators::Quick3270 do
6
+
7
+ let(:quick) { TE3270::Emulators::Quick3270.new }
8
+
9
+ before(:each) do
10
+ WIN32OLE.stub(:new).and_return quick_system
11
+ quick.instance_variable_set(:@session_file, 'the_host')
12
+ end
13
+
14
+ describe "global behaviors" do
15
+ it 'should start new terminal' do
16
+ WIN32OLE.should_receive(:new).and_return(quick_system)
17
+ quick.connect
18
+ end
19
+
20
+ it 'should establish a session' do
21
+ quick_system.should_receive(:ActiveSession).and_return(quick_session)
22
+ quick.connect
23
+ end
24
+
25
+ it 'should get the screen from the active session' do
26
+ quick_session.should_receive(:Screen).and_return(quick_screen)
27
+ quick.connect
28
+ end
29
+
30
+ it 'should take the Visible value from a block' do
31
+ quick_system.should_receive(:Visible=).with(false)
32
+ quick.connect do |platform|
33
+ platform.visible = false
34
+ end
35
+ end
36
+
37
+ it 'should take the session file from a block' do
38
+ quick.should_receive(:session_file=).with('blah.txt')
39
+ quick.connect do |platform|
40
+ platform.session_file = 'blah.txt'
41
+ end
42
+ end
43
+
44
+ it 'should display an error when the session file is not set' do
45
+ quick.instance_variable_set(:@session_file, nil)
46
+ expect { quick.connect }.to raise_error('The session file must be set in a block when calling connect with the Quick3270 emulator.')
47
+ end
48
+
49
+ it 'should open the connection using the sesion file' do
50
+ quick_session.should_receive(:Open).with('blah.txt')
51
+ quick.connect do |platform|
52
+ platform.session_file = 'blah.txt'
53
+ end
54
+ end
55
+
56
+ it 'should default to Visible being true when not provided' do
57
+ quick_system.should_receive(:Visible=).with(true)
58
+ quick.connect
59
+ end
60
+
61
+ it 'should make the connection via the session' do
62
+ quick_session.should_receive(:Connect)
63
+ quick.connect
64
+ end
65
+
66
+ it 'should check to make sure the connection is successful before continuing' do
67
+ quick_session.should_receive(:Connected).once.and_return(false)
68
+ quick_screen.should_receive(:WaitHostQuiet).once.with(1000)
69
+ quick_session.should_receive(:Connected).once.and_return(true)
70
+ quick.connect
71
+ end
72
+
73
+ it 'should disconnect from a session' do
74
+ application = double('application')
75
+ quick_session.should_receive(:Disconnect)
76
+ quick_system.should_receive(:Application).and_return(application)
77
+ application.should_receive(:Quit)
78
+ quick.connect
79
+ quick.disconnect
80
+ end
81
+ end
82
+
83
+ describe "interacting with text fields" do
84
+ it 'should get the value from the screen' do
85
+ quick_screen.should_receive(:GetString).with(1, 2, 7).and_return('blah')
86
+ quick.connect
87
+ quick.get_string(1, 2, 7).should == 'blah'
88
+ end
89
+
90
+ it 'should put a value on the screen' do
91
+ quick_screen.should_receive(:MoveTo).with(15, 56)
92
+ quick_screen.should_receive(:PutString).with('blah')
93
+ quick_screen.should_receive(:WaitHostQuiet).with(3000)
94
+ quick.connect
95
+ quick.put_string('blah', 15, 56)
96
+ end
97
+ end
98
+
99
+ describe "interacting with the screen" do
100
+ it 'should know how to send function keys' do
101
+ quick_screen.should_receive(:SendKeys).with('<Home>')
102
+ quick_screen.should_receive(:WaitHostQuiet).with(3000)
103
+ quick.connect
104
+ quick.send_keys(TE3270.Home)
105
+ end
106
+
107
+ it 'should wait for a string to appear' do
108
+ quick_screen.should_receive(:WaitForString).with('string', 3, 10)
109
+ quick.connect
110
+ quick.wait_for_string('string', 3, 10)
111
+ end
112
+
113
+ it 'should wait for the host to be quiet' do
114
+ quick_screen.should_receive(:WaitHostQuiet).with(6000)
115
+ quick.connect
116
+ quick.wait_for_host(6)
117
+ end
118
+
119
+ it 'should wait until the cursor is at a position' do
120
+ quick_screen.should_receive(:WaitForCursor).with(5, 8)
121
+ quick.connect
122
+ quick.wait_until_cursor_at(5,8)
123
+ end
124
+
125
+ it 'should take screenshots' do
126
+ take = double('Take')
127
+ quick_system.should_receive(:WindowTitle).and_return('The Title')
128
+ Win32::Screenshot::Take.should_receive(:of).with(:window, title: 'The Title').and_return(take)
129
+ take.should_receive(:write).with('image.png')
130
+ quick.connect
131
+ quick.screenshot('image.png')
132
+ end
133
+
134
+ it 'should delete the file for the screenshot if it already exists' do
135
+ File.should_receive(:exists?).and_return(true)
136
+ File.should_receive(:delete)
137
+ take = double('Take')
138
+ quick_system.should_receive(:WindowTitle).and_return('The Title')
139
+ Win32::Screenshot::Take.should_receive(:of).with(:window, title: 'The Title').and_return(take)
140
+ take.should_receive(:write).with('image.png')
141
+ quick.connect
142
+ quick.screenshot('image.png')
143
+ end
144
+
145
+ it 'should make the window visible before taking a screenshot' do
146
+ take = double('Take')
147
+ quick_system.should_receive(:WindowTitle).and_return('The Title')
148
+ Win32::Screenshot::Take.should_receive(:of).with(:window, title: 'The Title').and_return(take)
149
+ take.should_receive(:write).with('image.png')
150
+ quick_system.should_receive(:Visible=).once.with(true)
151
+ quick_system.should_receive(:Visible=).twice.with(false)
152
+ quick.connect do |emulator|
153
+ emulator.visible = false
154
+ end
155
+ quick.screenshot('image.png')
156
+ end
157
+
158
+ it 'should get the screen text' do
159
+ quick_screen.should_receive(:Rows).and_return(3)
160
+ quick_screen.should_receive(:Cols).and_return(10)
161
+ 3.times do |time|
162
+ quick_screen.should_receive(:GetString).with(time+1, 1, 10).and_return("row #{time}")
163
+ end
164
+ quick.connect
165
+ quick.text.should == 'row 0\nrow 1\nrow 2\n'
166
+ end
167
+ end
168
+ end
169
+
170
+ end