page-object-lds 0.0.12 → 0.0.13

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,153 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../lib/TNR360/components/dependencies.rb')
2
+
3
+ class LdsColumn
4
+
5
+ @browser
6
+ @idBlock=nil
7
+ @idColumn=nil
8
+ @isVisible=false
9
+ @orderInVisible=nil
10
+ @Label=nil
11
+
12
+
13
+ #constructor
14
+ def initialize(browser, idColumn, block, orderInVisible=nil)
15
+ @browser =browser
16
+ @parentBlock=block
17
+ @idColumn=idColumn
18
+ @orderInVisible=orderInVisible
19
+ update
20
+ @exists
21
+ end
22
+
23
+
24
+ #refresh object status from browser
25
+ def refresh
26
+ #Look for element in browser
27
+ @current_element= findElement @idColumn
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
+ #Look for element in browser
37
+ @current_element||= findElement @idColumn
38
+ #fill @label
39
+ @label=@current_element.div(:index => 0).span(:index => 0).text
40
+ #fill visible
41
+ @visible=@current_element.visible?
42
+ #fill idColumn
43
+ #@idColumn=@current_element.class_name
44
+ #everything exists
45
+ #changeVisibility "Payment" ,"Reject"
46
+ @exists=true
47
+ end
48
+
49
+
50
+ #method locate current element
51
+ def findElement idElement
52
+ begin
53
+ #if element not yet available in screen, wait for some time
54
+ if @parentBlock != nil
55
+ @parentBlock.getElement.div(:class,"std-fieldset-bwrap").tr(:index => 0).td(:xpath => "//td[contains(@class,'"+idElement+"')]").wait_until_present(10)
56
+ @current_element=@parentBlock.getElement.div(:class,"std-fieldset-bwrap").tr(:index => 0).td(:xpath => "//td[contains(@class,'"+idElement+"')]")
57
+ #@current_element=@parentBlock.getElement.div(:index => 2).tr(:index=>0).td(:class => "x-grid3-header x-grid3-hd x-grid3-cell x-grid3-td-"+idElement)
58
+ end
59
+ rescue
60
+
61
+ raise "Column "+idElement+" Not Found"
62
+
63
+ ensure
64
+ #rien dans finally pour ce cas
65
+ if @parentBlock == nil
66
+ if @browser.td(:xpath => "//td[contains(@class,'"+idElement+"')]").wait_until_present(10)
67
+ count=@browser.tds(:xpath => "//td[contains(@class,'"+idElement+"')]").length
68
+ end
69
+ if count==0
70
+ raise "Column "+idElement+" Not Found"
71
+ else
72
+ if count >1
73
+ raise "Several Elements with id "+idElement+" Found, specify block"
74
+ end
75
+ end
76
+ @current_element=@browser.td(:xpath => "//td[contains(@class,'"+idElement+"')]").when_present
77
+ end
78
+ end
79
+ @current_element
80
+ end
81
+
82
+ #print object
83
+ def to_s
84
+
85
+ "\n***** Column *****"+
86
+ "\nIdParentBlock : "+(no_null(@parentBlock)=="" ? "" : @parentBlock.getIdBlock)+
87
+ "\nIdColumn: "+ no_null(@idColumn)+
88
+ "\nLabel : "+ no_null(@label)+
89
+ "\nIsVisible : "+ bool_no_null(@visible.to_s)+
90
+ "\nOrderInVisible :"+ no_null(@orderInVisible.to_s)+
91
+ "\n**********"
92
+
93
+
94
+ end
95
+
96
+
97
+ def sortAscending label
98
+ @current_element.hover
99
+ @current_element.a(:index=>0).when_present.click
100
+ @browser.a(:id, label+"sort-asc-text").when_present.click
101
+ end
102
+
103
+ def sortDescending label
104
+ @current_element.hover
105
+ @current_element.a(:index=>0).when_present.click
106
+ @browser.a(:id, label+"sort-desc-text").when_present.click
107
+ end
108
+
109
+ def changeVisibility columnLabel ,elementTobeDisplayedLabel
110
+ @current_element.hover
111
+ @current_element.a(:index=>0).when_present.click
112
+ @browser.a(:id, columnLabel+"change-column-visibility").hover
113
+ @browser.div(:id,"Payment-change-visibility-menu").div(:class,"x-menu-list").a(:id,columnLabel+"-change-visibility-"+elementTobeDisplayedLabel).click
114
+ end
115
+ def displayColumns columnLabel
116
+ @current_element.hover
117
+ @current_element.a(:index=>0).when_present.click
118
+ @browser.a(:id, columnLabel+"change-column-visibility").hover
119
+ end
120
+ ####Getters
121
+
122
+ def getElement
123
+ @current_element
124
+ end
125
+
126
+ def getIdBlock
127
+ @idBlock
128
+ end
129
+
130
+ def getClassColumn
131
+ @idColumn
132
+ end
133
+
134
+ def getLabel
135
+ @label
136
+ end
137
+
138
+ def isVisible?
139
+ @isVisible
140
+ end
141
+
142
+
143
+ def isExist?
144
+ @exists
145
+ end
146
+
147
+ #private method list
148
+ private :update
149
+ end
150
+
151
+
152
+
153
+
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../lib/TNR360/components/dependencies.rb')
2
+
3
+ class LdsFKey < LdsTextField
4
+ @opened
5
+ @clicked
6
+ # click fk
7
+ def clickFK
8
+ @clicked=false
9
+ @current_element.when_present.click
10
+ @clicked=true
11
+ puts "Foreign Key Clicked " + @clicked.to_s
12
+ end
13
+ # click to open fk
14
+ def clickToOpenFK
15
+ @opened=false
16
+ @current_element.parent.img.click
17
+ @opened=true
18
+ puts "Foreign Key Clicked " + @opened.to_s
19
+ end
20
+
21
+ end
@@ -0,0 +1,332 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../lib/TNR360/components/dependencies.rb')
2
+
3
+ class LdsGrid < LdsBlock
4
+ @paginated_grid=false
5
+ @editable_grid=false
6
+ @check_selected_line=false
7
+ @selected=false
8
+ @goToPageSuccess=false
9
+ @fkClickCell=false
10
+ @doubleClickLine=false
11
+ @cellValue=nil
12
+ @isNext=false
13
+ @isPrevious=false
14
+ @isFirst=false
15
+ @isLast=false
16
+ @isCellEditable=false
17
+
18
+
19
+ #constructor
20
+ def initialize(browser, idBlock, idScreen=nil)
21
+ super(browser, idBlock, idScreen)
22
+ update
23
+ @exists
24
+ end
25
+
26
+ def update
27
+ super
28
+ check_paginated
29
+ check_editable
30
+ end
31
+
32
+ #check if paginated grid or not
33
+ def check_paginated
34
+ @paginated_grid=@current_element.class_name.include?"paging-remote"
35
+ end
36
+ #check if editable grid or not
37
+ def check_editable
38
+ @editable_grid=@current_element.div(:class, "std-fieldset-bwrap").div(:class, "std-fieldset-tbar").exists?
39
+ end
40
+
41
+ #*************************column methods****************
42
+
43
+ def extractDisplayedColumns
44
+ count=1
45
+ @columns=Array.new
46
+ while count <= @current_element.div(:class, "std-fieldset-bwrap").tr(:index => 0).tds.length
47
+ #iterate through list of columns
48
+ @current_element.div(:class, "std-fieldset-bwrap").tr(:index => 0).tds.each do |column|
49
+ @columns << LdsColumn.new(@browser, column.class_name.split("-").last, self, count)
50
+ count +=1
51
+ end
52
+ end
53
+ puts column_to_s
54
+ end
55
+
56
+ def extractAllColumns columnId
57
+ count=0
58
+ @allColumns=Array.new
59
+ @column=LdsColumn.new(@browser, columnId, self, count)
60
+ @column.displayColumns (@column.getLabel)
61
+ columnsNbr=@browser.div(:id, "Payment-change-visibility-menu").div(:class, "x-menu-list").as.length
62
+ while count< columnsNbr
63
+ @allColumns<< @browser.div(:id, "Payment-change-visibility-menu").div(:class, "x-menu-list").a(:index => count).class_name.split("-").last
64
+ count+=1
65
+ end
66
+ end
67
+
68
+ def extractColumnValues (idColumn)
69
+ lines=@current_element.div(:class, "std-fieldset-bwrap").div(:class, "x-grid3-body").tables.length
70
+ if (lines!=0)
71
+ ind =1
72
+ @columnValues=Array.new
73
+ @labelColumn= @current_element.div(:class, "std-fieldset-bwrap").div(:class, "x-grid3-body").table(:index => 0).td(:xpath => "//td[contains(@class,'"+idColumn+"')]", :index => 0).text
74
+ while ind <= lines
75
+ @columnValues << @current_element.div(:class, "std-fieldset-bwrap").div(:class, "x-grid3-body").table(:index => ind-1).td(:xpath => "//td[contains(@class,'"+idColumn+"')]", :index => ind).text
76
+ #@current_element.div(:class, "std-fieldset-bwrap").div(:class, "x-grid3-body").table(:index => lineIndex).td(:xpath => "//td[contains(@class,'"+idColumn+"')]", :index => lineIndex)
77
+ ind +=1
78
+ end
79
+ else
80
+ puts "grid is empty"
81
+ end
82
+ end
83
+
84
+ #***************************line methods******************
85
+ def extractLine (lineIndex)
86
+ #iterate through number of lines
87
+ if @current_element.div(:class, "std-fieldset-bwrap").div(:class, "x-grid3-body").table(:index => lineIndex-1).exists?
88
+ @current_element.div(:class, "std-fieldset-bwrap").div(:class, "x-grid3-body").table(:index => lineIndex-1).parent
89
+ else
90
+ puts "Line not found"
91
+ end
92
+
93
+ end
94
+
95
+ def checkSelectedLine (lineIndex)
96
+ #@selected_line= @current_element.div(:class,"std-fieldset-bwrap").div(:class, "x-grid3-body").table(:index => lineIndex-1).parent.class_name.include? "selected"
97
+ @line= extractLine lineIndex
98
+ @check_selected_line=@line.class_name.include? "selected"
99
+ puts "\nIsSelectedLine : "+ bool_no_null(@check_selected_line.to_s)
100
+
101
+ end
102
+
103
+ def selectLine (lineIndex)
104
+ #@selected_line= @current_element.div(:class,"std-fieldset-bwrap").div(:class, "x-grid3-body").table(:index => lineIndex-1).parent.class_name.include? "selected"
105
+ @line= extractLine lineIndex
106
+ @line.click
107
+ checkSelectedLine lineIndex
108
+ end
109
+
110
+ #********************************line Actions methods**************
111
+ def lineDoubleClick (lineIndex)
112
+ #@selected_line= @current_element.div(:class,"std-fieldset-bwrap").div(:class, "x-grid3-body").table(:index => lineIndex-1).parent.class_name.include? "selected"
113
+ @line= extractLine lineIndex
114
+ if (@line!=nil)
115
+ #if firefox, do the double click trick
116
+ custom_double_click @browser , @line
117
+ sleep($wait_time)
118
+ end
119
+
120
+ if (!@browser.div(:id => @idBlock).visible?)
121
+ @doubleClickLine=true
122
+ end
123
+
124
+ puts "\nDoubleClick : "+ bool_no_null(@doubleClickLine.to_s)
125
+ end
126
+
127
+
128
+
129
+ #*******************************Cell methods**********************
130
+ def extractCellByLineAndColumnIndex (lineIndex, idColumn)
131
+ if @current_element.div(:class, "std-fieldset-bwrap").div(:class, "x-grid3-body").table(:index => lineIndex-1).td(:xpath => "//td[contains(@class,'"+idColumn+"')]", :index => lineIndex).exists?
132
+ @current_element.div(:class, "std-fieldset-bwrap").div(:class, "x-grid3-body").table(:index => lineIndex-1).td(:xpath => "//td[contains(@class,'"+idColumn+"')]", :index => lineIndex)
133
+ else
134
+ puts "Cell not found"
135
+ end
136
+ end
137
+
138
+ def extractCellValue (lineIndex, idColumn)
139
+ @cell=extractCellByLineAndColumnIndex lineIndex, idColumn
140
+ if (@cell!=nil)
141
+ @cellValue=@cell.text
142
+ end
143
+ puts "\nCell value : "+ no_null(@cellValue)
144
+ end
145
+
146
+ def getCellLines (idColumn, cellValue)
147
+ extractColumnValues idColumn
148
+ @lineCell=Array.new
149
+ if (@columnValues != nil)
150
+ i=1
151
+ @columnValues.each do |column|
152
+ if column==cellValue
153
+ @lineCell<< i
154
+ end
155
+ i+=1
156
+ end
157
+ end
158
+ if (@lineCell!=nil)
159
+ puts "\n*****Lines that contain : "+ no_null(cellValue) + "*****"
160
+ @lineCell.each { |value| puts value }
161
+ end
162
+ end
163
+
164
+ def isCellEditable? (lineIndex, idColumn)
165
+ @cell=extractCellByLineAndColumnIndex lineIndex, idColumn
166
+ if (@cell!=nil)
167
+ if (@cell.class_name.include? "editable")
168
+ @isCellEditable=true
169
+ end
170
+ end
171
+ puts "\nCellEditable :"+ bool_no_null(@isCellEditable.to_s)
172
+ end
173
+
174
+ #***************************Cell Actions methods****************************
175
+ def clickFkInGrid (lineIndex, idColumn)
176
+ @cell=extractCellByLineAndColumnIndex lineIndex, idColumn
177
+ if (@cell!=nil)
178
+ @cell.click
179
+ sleep($wait_time)
180
+ end
181
+ if (!@browser.div(:id => @idBlock).visible?)
182
+ @fkClickCell=true
183
+ end
184
+ puts "\nFkClick :"+ bool_no_null(@fkClickCell.to_s)
185
+ end
186
+
187
+ #******************************Grid Actions**********************
188
+
189
+ def goFirst
190
+ @current_element.div(:class, "std-fieldset-bbar").img(:index => 0).click
191
+ #sleep($large_wait_time)
192
+ pageNumber=@current_element.div(:class, "std-fieldset-bbar").td(:class => "x-toolbar-cell", :index => 4).text_field.when_present($large_wait_time).value
193
+ if (pageNumber.to_i==1)
194
+ @isFirst=true
195
+ end
196
+ puts "\nIsFirstPage : "+ bool_no_null(@isFirst.to_s)
197
+ end
198
+
199
+ def goPrevious
200
+ pageNumber=@current_element.div(:class, "std-fieldset-bbar").td(:class => "x-toolbar-cell", :index => 4).text_field.value
201
+ @current_element.div(:class, "std-fieldset-bbar").img(:index => 1).click
202
+ #sleep($large_wait_time)
203
+ newPageNumber=@current_element.div(:class, "std-fieldset-bbar").td(:class => "x-toolbar-cell", :index => 4).text_field.when_present($large_wait_time).value
204
+ if (newPageNumber.to_i==pageNumber.to_i-1)
205
+ @isPrevious=true
206
+ end
207
+ puts "\nIsPreviousPage : "+ bool_no_null(@isPrevious.to_s)
208
+ end
209
+
210
+ def goNext
211
+ pageNumber=@current_element.div(:class, "std-fieldset-bbar").td(:class => "x-toolbar-cell", :index => 4).text_field.value
212
+ @current_element.div(:class, "std-fieldset-bbar").img(:index => 2).click
213
+ #sleep($large_wait_time)
214
+ newPageNumber=@current_element.div(:class, "std-fieldset-bbar").td(:class => "x-toolbar-cell", :index => 4).text_field.when_present($large_wait_time).value
215
+ if (newPageNumber.to_i==pageNumber.to_i+1)
216
+ @isNext=true
217
+ end
218
+ puts "\nIsNextPage : "+ bool_no_null(@isNext.to_s)
219
+ end
220
+
221
+ def goLast
222
+ lastPageNumber=@current_element.div(:class, "std-fieldset-bbar").td(:class => "x-toolbar-cell", :index => 5).div(:index => 0).text.split(" ").last
223
+ @current_element.div(:class, "std-fieldset-bbar").img(:index => 3).click
224
+ #sleep($large_wait_time)
225
+ newPageNumber=@current_element.div(:class, "std-fieldset-bbar").td(:class => "x-toolbar-cell", :index => 4).text_field.when_present($large_wait_time).value
226
+ if (newPageNumber.to_i==lastPageNumber.to_i)
227
+ @isLast=true
228
+ end
229
+ puts "\nIsLastPage : "+ bool_no_null(@isLast.to_s)
230
+ end
231
+
232
+ def goToPage pageNbr
233
+ @current_element.div(:class, "std-fieldset-bbar").td(:class => "x-toolbar-cell", :index => 4).text_field.set pageNbr
234
+ @browser.send_keys :return
235
+ #sleep($wait_time)
236
+ newPageNumber=@current_element.div(:class, "std-fieldset-bbar").td(:class => "x-toolbar-cell", :index => 4).text_field.when_present($wait_time).value
237
+ if (newPageNumber.to_i==pageNbr)
238
+ @goToPageSuccess=true
239
+ end
240
+ puts "\nGoToPageSuccess : "+ bool_no_null(@goToPageSuccess.to_s)
241
+ end
242
+
243
+ def clickRefresh
244
+ @current_element.div(:class, "std-fieldset-bbar").img(:index => 4).click
245
+ end
246
+
247
+ #Add action in a grid
248
+ def addLine (*args)
249
+ @current_element.div(:class, "std-fieldset-tbar").table(:xpath => "//table[contains(@id"",'"+"add"+"')]").when_present.click
250
+ args.each do |arg_item|
251
+ @current_element.div(:class,"x-form-field-wrap x-spinner-field fwk-number x-component").text_field.set arg_item
252
+ @browser.send_keys :tab
253
+ # def sub_method(idScreen,*args)
254
+ # args.each do |arg_item|
255
+ # puts arg_item.inspect
256
+ # puts arg_item.class.inspect
257
+ # end
258
+ end
259
+ end
260
+
261
+ #Delete action in a grid
262
+ def deleteLine (lineIndex)
263
+ extractLine lineIndex
264
+ selectLine lineIndex
265
+ @current_element.div(:class, "std-fieldset-tbar").table(:xpath => "//table[contains(@id,'"+"remove"+"')]").when_present.click
266
+ end
267
+
268
+ #Modify a cell in a grid
269
+ def modifyCell(lineIndex, columnId, newValue)
270
+ @cellToModify=extractCellByLineAndColumnIndex lineIndex, columnId
271
+ custom_double_click @browser , @cellToModify
272
+ @cellToModify.div(:class,"fwk-weekDaysListGrid-dayName").send_keys newValue
273
+ @browser.send_keys :return
274
+ end
275
+
276
+ #print object
277
+ def to_s
278
+ super.to_s +
279
+ "\n***** Grid *****"+
280
+ "\nIsPaginated : "+ bool_no_null(@paginated_grid.to_s)+
281
+ "\nIsEditable : "+ bool_no_null(@editable_grid.to_s)+
282
+ "\n**********"
283
+ end
284
+
285
+
286
+ def columnValues_to_s
287
+ if (@columnValues!=nil)
288
+ puts "\n*****Values of column : "+ no_null(@labelColumn) + "*****"
289
+ @columnValues.each { |value| puts value }
290
+ end
291
+ end
292
+
293
+
294
+ def allColumns_to_s
295
+ if (@allColumns!=nil)
296
+ @allColumns.each { |value| puts value }
297
+ end
298
+ end
299
+
300
+ def column_to_s
301
+ if (@columns != nil)
302
+ @columns.each do |column|
303
+ column.to_s
304
+ end
305
+ end
306
+ end
307
+
308
+
309
+ def getPaginated?
310
+ @paginated_grid
311
+ end
312
+
313
+ def getEditable?
314
+ @editable_grid
315
+ end
316
+
317
+ def isSelectedLine?
318
+ @check_selected_line
319
+ end
320
+
321
+ def getCellValue
322
+ @cellValue
323
+ end
324
+
325
+ def getCellEditable?
326
+ @isCellEditable
327
+ end
328
+
329
+ #private method list
330
+ private :update
331
+ end
332
+