page-object-lds 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../lib/TNR360/components/dependencies.rb')
2
+ class LdsLov < LdsTextField
3
+ @clicked=false
4
+ @opened=false
5
+ #click Lov
6
+ def click
7
+ @clicked=false
8
+ @browser.text_field(:id => @idField).when_present.click
9
+ @clicked=true
10
+ puts "Lov clicked " +@clicked.to_s
11
+ end
12
+
13
+ def selectFromLov
14
+ @browser.select_list(id => @idField).when_present.clear
15
+ puts @browser.select_list(:id => @idField).when_present.options
16
+ @browser.select_list(:id => @idField).when_present.select_value('SOCI02 - SA SOCI02').select
17
+
18
+ end
19
+ #click to open Lov
20
+ def clickToOpenLov
21
+ @opened=false
22
+ @current_element.parent.img.when_present.click
23
+ @opened=true
24
+ puts "Lov opened " +@opened.to_s
25
+ end
26
+ private :update
27
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../lib/TNR360/components/dependencies.rb')
2
+ class LdsMenu
3
+ @browser
4
+ @menu_item_text=nil
5
+ @menuSelected=nil
6
+ @exists=false
7
+ @current_element
8
+ #constructor
9
+ def initialize(browser,menu_item_text)
10
+ @browser =browser
11
+ @menu_item_text=menu_item_text
12
+ @exists
13
+ end
14
+ #print object
15
+ def to_s
16
+ "\n***** Menu *****"+
17
+ "\nMenu item text : "+ bool_no_null(@menu_item_text.to_s)+
18
+ "\n**********"
19
+ end
20
+
21
+
22
+ def click
23
+ menu_path = @menu_item_text.split('/')
24
+ raise "Provide at least one level of menu item" if (menu_path.length < 1)
25
+ for i in 0..(menu_path.length-1)
26
+ puts "Value of local variable is #{i}"
27
+ case i
28
+ when 0
29
+ @browser.div.li(:id => menu_path[i]).when_present.click
30
+ sleep($small_wait_time)
31
+ when 1
32
+ @browser.div.table(:id=> menu_path[i]).button.when_present.click
33
+ sleep($small_wait_time)
34
+ when i==menu_path.length-1
35
+ @browser.a(:text=>menu_path[i]).when_present.click
36
+ sleep($small_wait_time)
37
+ else
38
+ @browser.a(:text=>menu_path[i]).when_present.hover
39
+ sleep($small_wait_time)
40
+ if i==menu_path.length-1
41
+ @browser.a(:text=>menu_path[i]).when_present.click
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+
49
+
50
+
@@ -0,0 +1,195 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../lib/TNR360/components/dependencies.rb')
2
+ class LdsRadio
3
+ @browser
4
+ @idField=nil
5
+ @idBlock=nil
6
+ @idScreen=nil
7
+ @exists=false
8
+ @value=nil
9
+ @visible=false
10
+ @editable=false
11
+ @label=nil
12
+ @checked=false
13
+ @current_element
14
+ #constructor
15
+ def initialize(browser,idField,idBlock=nil,idScreen=nil)
16
+ @browser =browser
17
+ @idField= idField
18
+ @idBlock=idBlock
19
+ @idScreen=idScreen
20
+ update
21
+ @exists
22
+ end
23
+
24
+ #refresh object status from browser
25
+ def refresh
26
+ #Look for element in browser
27
+ @current_element= findElement @idField
28
+ #update other data
29
+ update
30
+ @exists
31
+ end
32
+
33
+ #private method to update/save the status of the object
34
+ def update
35
+ @exists=false
36
+
37
+ #Look for element in browser
38
+ @current_element||= findElement @idField
39
+ #fill label
40
+ @label=@browser.label(:xpath => "//label[contains(@for,'"+@idField+"')]").when_present.text
41
+ @checked= @current_element.set?
42
+ @value=@current_element.set?
43
+ #fill visible
44
+ @visible=@current_element.visible?
45
+ #fill editable
46
+ @editable=!(@current_element.readonly?)
47
+ #everything exists
48
+ @exists=true
49
+
50
+ end
51
+
52
+ #method locate current element
53
+ def findElement idElement
54
+
55
+ # @browser.div(:id => idElement).radio(:index => 0)
56
+ @current_element=nil
57
+
58
+ #wait for screen to become visible (find screen forcefully)
59
+ proc=Proc.new {isScreenDisplayed }
60
+ puts 'Screen found = '+ force_find_element(proc).to_s
61
+
62
+ #wait for screen to become visible (find screen forcefully)
63
+ proc=Proc.new {elementExists?(idElement) }
64
+ @exists=force_find_element(proc)
65
+ puts 'Radio found = '+@exists.to_s
66
+
67
+
68
+
69
+ if (@browser.divs(:id => idElement).length>1 && @idBlock!=nil)
70
+ #utiliser le id bloc
71
+ @bloc=LdsBlock.new(@browser, @idBlock)
72
+ @current_element=@bloc.getElement.div(:id => idElement).radio(:index => 0).when_present
73
+ else
74
+ if (@browser.divs(:id => idElement).length>1)
75
+ @browser.divs(:id => idElement).each do |field|
76
+ if field.visible?
77
+ @current_element=field.radio(:index => 0)
78
+ break
79
+ end
80
+ end
81
+ else
82
+ @current_element=@browser.div(:id => idElement).radio(:index => 0).when_present
83
+ end
84
+ end
85
+ if @current_element.visible?
86
+ puts 'element is visible'
87
+ else
88
+ puts 'element is NOT visible'
89
+ end
90
+ @current_element
91
+ end
92
+
93
+ def elementExists?(idElement)
94
+ #this method assumes the screen/tab is already loaded
95
+ oneIsVisible=false
96
+ #if element not yet available in screen, wait for some time
97
+ if (!@browser.div(:id => idElement).radio(:index => 0).exists?)
98
+ @browser.div(:id => idElement).radio(:index => 0).when_present(10)
99
+ oneIsVisible=true
100
+ else
101
+ if (!@browser.divs(:id => idElement).visible?)
102
+ @browser.div(:id => idElement).each do |field|
103
+ if field.visible?
104
+ oneIsVisible=true
105
+ break
106
+ end
107
+ end
108
+ if !oneIsVisible
109
+ @browser.div(:id => idElement).radio(:index => 0).when_present(10)
110
+ oneIsVisible=true
111
+ end
112
+ end
113
+ end
114
+ oneIsVisible
115
+ end
116
+
117
+
118
+ def isScreenDisplayed
119
+ if (@idScreen!=nil)
120
+ @scr=LdsScreen.new(@browser, @idScreen)
121
+ @scr.isVisible?
122
+ else
123
+ false
124
+ end
125
+ end
126
+
127
+ #print object
128
+ def to_s
129
+ "\n***** Radio *****"+
130
+ "\nId : "+no_null(@idField.to_s) +
131
+ "\nIdBlock : "+ no_null(@IdBlock.to_s)+
132
+ "\nIdScreen : "+ no_null(@IdScreen.to_s) +
133
+ "\nValue : "+ no_null(@value.to_s)+
134
+ "\nLabel : "+ no_null(@label.to_s)+
135
+ "\nVisible : "+ no_null(@visible.to_s)+
136
+ "\nEditable : "+ no_null( @editable.to_s)+
137
+ "\nExists : "+ no_null(@exists.to_s)+
138
+ "\nChecked : "+ no_null(@checked.to_s)+
139
+ "\n**********"
140
+ end
141
+
142
+ ##LdsScreen Actions
143
+ def check
144
+ if(@exists)
145
+ @browser.div(:id => @idField).radio(:index => 0).when_present.set
146
+ @exists=true
147
+ update
148
+ end
149
+ end
150
+
151
+
152
+ ####Getters
153
+ def getElement
154
+ @current_element
155
+ end
156
+
157
+ def getIdentifier
158
+ @idField
159
+ end
160
+ def getIdBlock
161
+ @idBlock
162
+ end
163
+ def getIdScreen
164
+ @idScreen
165
+ end
166
+ def isChecked
167
+ puts @checked
168
+ end
169
+
170
+ def getValue
171
+ @value
172
+ end
173
+
174
+ def getLabel
175
+ @label
176
+ end
177
+
178
+ def isVisible?
179
+ @visible
180
+ end
181
+
182
+ def isEditable?
183
+ @editable
184
+ end
185
+
186
+ def isExist
187
+ @exists
188
+ end
189
+
190
+ #private method list
191
+ private :update
192
+ end
193
+
194
+
195
+
@@ -0,0 +1,234 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../lib/TNR360/components/dependencies.rb')
2
+
3
+ class LdsScreen
4
+
5
+ @browser
6
+ @idScreen=nil
7
+ @title=nil
8
+ @visible=false
9
+ @exists=false
10
+ @type=nil
11
+ @isRootTab=true
12
+
13
+ @parentRootTab=nil
14
+ @rootTitle=nil
15
+ @current_element
16
+
17
+
18
+ #constructor
19
+ def initialize(browser, idScreen)
20
+ @browser =browser
21
+ @idScreen=idScreen
22
+ update
23
+ @exists
24
+ end
25
+
26
+
27
+ #refresh object status from browser
28
+ def refresh
29
+ #Look for element in browser
30
+ @current_element= findElement @idScreen
31
+ #update other data
32
+ update
33
+ @exists
34
+ end
35
+
36
+ #private method to update/save the status of the object
37
+ def update
38
+ @exists=false
39
+
40
+ #Look for element in browser
41
+ @current_element||= findElement @idScreen
42
+ #fill @title
43
+ extractTitle
44
+ #fill visible
45
+ @visible=@current_element.visible?
46
+
47
+ #deal with subtabs
48
+ @isRootTab=!@current_element.id.to_s.include?('functionTab')
49
+ extractSubTabs @idScreen
50
+
51
+ #fill type
52
+ extractType
53
+ #everything exists
54
+ @exists=true
55
+ end
56
+
57
+
58
+ #internal methods
59
+ def extractType
60
+
61
+ end
62
+
63
+
64
+ def extractTitle
65
+ @title=@current_element.text
66
+ end
67
+
68
+ def extractSubTabs idElement
69
+ if (!@isRootTab)
70
+ ind=0
71
+
72
+ #find parent of current element that holds all frame contents of the tab
73
+ element, previousElement = findParentWithClass "x-tab-panel-body x-tab-panel-body-top",@current_element
74
+
75
+ #find the correct order of this frame, in order to identify the order of the tab
76
+ element.divs(:xpath =>'*').each do |adiv|
77
+ if(adiv.class_name==previousElement.class_name)
78
+ break;
79
+ end
80
+ ind=ind+1
81
+ end
82
+
83
+ #now that we have the order, navigate through root tabs, and find the one with the same order ind
84
+ @browser.divs(:xpath =>'//div[contains(@class,"x-tab-panel-header")]').each do |divr|
85
+ if(!(divr.li.id.start_with? 'GLOBALMENU') && !(divr.li.id.start_with? 'functionTab'))
86
+ @parentRootTab=divr.li(:index => ind)
87
+ break
88
+ end
89
+ end
90
+
91
+ #get the title of that root tab
92
+ @rootTitle=@parentRootTab.text
93
+ end
94
+ end
95
+
96
+
97
+
98
+
99
+ #method locate current element
100
+ def findElement idElement
101
+ @isRootTab=true
102
+ @parentRootTab=nil
103
+ @rootTitle=nil
104
+ #wait for screen to become visible (find screen forcefully)
105
+ proc=Proc.new { elementExists?(idElement) }
106
+ found=@exists=force_find_element(proc)
107
+
108
+ #show proof
109
+ puts 'Tab Element ' +idElement+' found = '+@exists.to_s
110
+
111
+ @current_element=@browser.li(:xpath => "//li[contains(@id,'"+idElement+"')]").when_present($wait_time.to_i)
112
+ @current_element
113
+ end
114
+
115
+
116
+ def elementExists?(idElement)
117
+ #this method assumes the screen/tab is already loaded
118
+ oneIsThere=false
119
+ #if element not yet available in screen, wait for some time
120
+ if (!@browser.li(:xpath => "//li[contains(@id,'"+idElement+"')]").exists?)
121
+ @browser.li(:xpath => "//li[contains(@id,'"+idElement+"')]").when_present($wait_time.to_i)
122
+ oneIsThere=true
123
+ else
124
+ oneIsThere=true
125
+ end
126
+ oneIsThere
127
+ end
128
+
129
+
130
+ #print object
131
+ def to_s
132
+ "\n***** Screen *****"+
133
+ "\nIdScreen : "+ no_null(@idScreen) +
134
+ "\nTitle : "+ no_null(@title)+
135
+ "\nVisible : "+ bool_no_null(@visible.to_s)+
136
+ "\nExists : "+ bool_no_null(@exists.to_s)+
137
+ "\nType :"+ no_null(@type.to_s)+
138
+ "\nIsRootTab : "+ bool_no_null(@isRootTab.to_s)+
139
+ "\nRootTitle : "+ ((no_null(@rootTitle.to_s)=='')?(@title.to_s):(@rootTitle.to_s))+
140
+ "\nType :"+ no_null(@type.to_s)+
141
+ "\n**********"
142
+ end
143
+
144
+
145
+ ##LdsScreen Actions
146
+ def click
147
+ success=false
148
+ if(@current_element.present? && @current_element.visible?)
149
+ @current_element.click
150
+ sleep($small_wait_time)
151
+ #wait for screen to become visible
152
+ proc=Proc.new { @current_element.visible? }
153
+ success=@exists=force_find_element(proc)
154
+
155
+ else
156
+ if(@parentRootTab!=nil && @parentRootTab.present?)
157
+ @parentRootTab.click
158
+ #wait for screen to become visible
159
+ proc=Proc.new { @current_element.visible? }
160
+ success=@exists=force_find_element(proc)
161
+ @current_element.click
162
+ success=@current_element.visible?
163
+ end
164
+ end
165
+ success
166
+ end
167
+
168
+ def closeTab
169
+ @current_element.a(:class => 'x-tab-strip-close').click
170
+ if(!@isRootTab)
171
+ @parentRootTab.a(:class => 'x-tab-strip-close').click
172
+ end
173
+ done=false
174
+ #make sure screen closed : Trigger Action => any action on it throws a not found error
175
+ begin
176
+ update
177
+ rescue
178
+ done=true
179
+ ensure
180
+ done
181
+ end
182
+ end
183
+
184
+ def closeRootTab
185
+ @current_element.a(:class => 'x-tab-strip-close').click
186
+ if(!@isRootTab)
187
+ @parentRootTab.a(:class => 'x-tab-strip-close').click
188
+ end
189
+ done=false
190
+ #make sure screen closed : Trigger Action => any action on it throws a not found error
191
+ begin
192
+ update
193
+ rescue
194
+ done=true
195
+ ensure
196
+ done
197
+ end
198
+ end
199
+
200
+ ####Getters
201
+ def getElement
202
+ @current_element
203
+ end
204
+
205
+ def getIdScreen
206
+ @idScreen
207
+ end
208
+
209
+ def getTitle
210
+ @title
211
+ end
212
+
213
+ def getRootTitle
214
+ @rootTitle
215
+ end
216
+ def getType
217
+ @type
218
+ end
219
+
220
+ def isVisible?
221
+ @visible
222
+ end
223
+
224
+ def isExist?
225
+ @exists
226
+ end
227
+
228
+ #private method list
229
+ private :update, :extractTitle, :extractType , :elementExists? , :findElement , :extractSubTabs
230
+ end
231
+
232
+
233
+
234
+