calendarwidgetplugin/tsrc/matti_testcases/Calendar_widget_tests.rb
changeset 2 a4a7966c042b
parent 0 db1bf15cefff
child 3 b2d662d68a49
equal deleted inserted replaced
1:f8e7eccf5f96 2:a4a7966c042b
    24 include MobyBase 
    24 include MobyBase 
    25 include MobyUtil
    25 include MobyUtil
    26 include MattiVerify 
    26 include MattiVerify 
    27 @@z_index = ""
    27 @@z_index = ""
    28 
    28 
       
    29 
    29 Parameter.instance.load_parameters_xml(File.expand_path(File.dirname(__FILE__)) + '/testdata/calendar_widget_test_script_parameters.xml') 
    30 Parameter.instance.load_parameters_xml(File.expand_path(File.dirname(__FILE__)) + '/testdata/calendar_widget_test_script_parameters.xml') 
    30     
    31     
    31 class TestClassCalendarWidget < Test::Unit::TestCase
    32 class TestClassCalendarWidget < Test::Unit::TestCase
    32     
    33   
    33 
    34   @HS_count = 0
    34 ##  def initialize (args)
    35   @day = 0
    35 ##	super(args)
    36   @month = 0
    36 ##	@sut = MATTI.sut(:Id => 'sut_s60_qt')
    37   @year = 0
    37 ##	#@sut = MATTI.sut(:Id => 's60')
    38   @hourformat_12 = true
    38 ##	begin		
    39   
    39 ##		#check_phone_date
       
    40 ##		#check_phone_time
       
    41 ##		#if @sut.application.test_object_exists?("HbTextItem", {:text => 'Continue', :__timeout => 2})
       
    42 ##		#	@sut.application( :name => 'ftulanguage' ).HbTextItem(:text => 'Continue').tap
       
    43 ##		#end
       
    44 ##		#@sut.press_key(:kEnd)
       
    45 ##		@sut.application( :name => 'qttasserver' ).press_key(:kApp)
       
    46 ##	rescue Exception => ex
       
    47 ##		puts "INITIALIZE FAILED. ERROR:"
       
    48 ##		puts ex.message
       
    49 ##		puts "*************************"
       
    50 ##	end
       
    51 ##  end
       
    52   def initialize (args)
    40   def initialize (args)
    53 	super(args)
    41 	super(args)
    54 	# MANDATORY DEFINITION: Define device "suts" which are used in testing, remember defined [ut] name in matti_parameters.xml
    42 	# MANDATORY DEFINITION: Define device "suts" which are used in testing, remember defined [ut] name in matti_parameters.xml
    55 	@sut = MATTI.sut(:Id => 'sut_s60_qt')
    43 	@sut = MATTI.sut(:Id => 'sut_s60_qt')
    56 	#to see if there is some widgets on the screen
    44 	#to see if there is some widgets on the screen
    84 			puts "INITIALIZE FAILED. ERROR:"
    72 			puts "INITIALIZE FAILED. ERROR:"
    85 			puts ex.message
    73 			puts ex.message
    86 			puts "*************************"
    74 			puts "*************************"
    87 		end
    75 		end
    88 	end
    76 	end
    89   #@real_phone_number = "02722990"
    77 	#app = @sut.application(:name => 'hsapplication')
       
    78     #identificator = TestObjectIdentificator.new(:type => :HsPageVisual)
       
    79 	#xml =  app.HsIdleWidget.HbWidget( :__index =>2 ).xml_data 
       
    80 	#element_set = xml.xpath( xpath = identificator.get_xpath_to_identify( xml ) ) 
       
    81 	#@HS_count = element_set.size
       
    82 	@HS_count = 4
       
    83 	@hourformat_12 = true
       
    84 	#puts "initialize @hourformat_12 = " + @hourformat_12.to_s
       
    85 	#puts "initialize @HS_count = " + @HS_count.to_s
       
    86   #@HS_count = 0
    90   #@widget_name = "Contact widget."
    87   #@widget_name = "Contact widget."
    91   #@@contact_array = Array.new() 
    88   #@@contact_array = Array.new() 
    92   end 
    89   end 
    93   
    90     
    94   def teardown
    91   def teardown
    95 	puts "teardown actions"
    92 	puts "teardown actions"
    96 	begin
    93 	begin
    97 		app = @sut.application.executable_name
    94 		app = @sut.application.executable_name
    98 		app_name = app.split(".exe")[0].to_s
    95 		app_name = app.split(".exe")[0].to_s
    99 		app_name = (app_name == 'tsapplication') ? 'hsapplication' : app_name
    96 		app_name = (app_name == 'tsapplication') ? 'hsapplication' : app_name
   100 		if @sut.application(:name => app_name).test_object_exists?("HbIconItem", {:iconName => 'qtg_mono_applications_all', :__timeout => 2})
    97 		if @sut.application(:name => app_name).test_object_exists?("HbIconItem", {:iconName => 'qtg_mono_applications_all', :__timeout => 2})
   101 			navigate_to_first_homescreen
    98 			navigate_to_first_homescreen
   102 			if @sut.application(:name => app_name).test_object_exists?("HbWidget",{:name => 'CalendarWidget'}) then
    99 			delete_calendar_events_via_UI
   103 				remove_calendar_widget_from_homescreen(0)
       
   104 			end
       
   105 			delete_calendar_events(@sut.application(:name => app_name))
       
   106 		else
   100 		else
   107 			app = @sut.application.executable_name
   101 			app = @sut.application.executable_name
   108 			app_name = app.split(".exe")[0].to_s
   102 			app_name = app.split(".exe")[0].to_s
   109 			app_name = (app_name == 'tsapplication') ? 'hsapplication' : app_name
   103 			app_name = (app_name == 'tsapplication') ? 'hsapplication' : app_name
   110 			if @sut.application(:name => app_name).test_object_exists?("HbIconItem", {:iconName => 'qtg_mono_back', :__timeout => 2})
   104 			if @sut.application(:name => app_name).test_object_exists?("HbIconItem", {:iconName => 'qtg_mono_back', :__timeout => 2})
   127 			end
   121 			end
   128 			app = @sut.application.executable_name
   122 			app = @sut.application.executable_name
   129 			app_name = app.split(".exe")[0].to_s
   123 			app_name = app.split(".exe")[0].to_s
   130 			app_name = (app_name == 'tsapplication') ? 'hsapplication' : app_name
   124 			app_name = (app_name == 'tsapplication') ? 'hsapplication' : app_name
   131 			navigate_to_first_homescreen
   125 			navigate_to_first_homescreen
   132 			if @sut.application(:name => app_name).test_object_exists?("HbWidget",{:name => 'CalendarWidget'}) then
   126 			delete_calendar_events_via_UI
   133 				remove_calendar_widget_from_homescreen(0)
       
   134 			end
       
   135 			delete_calendar_events(@sut.application(:name => app_name))
       
   136 		end
   127 		end
   137 	rescue Exception => ex
   128 	rescue Exception => ex
   138 		puts "TEARDOWN FAILED. ERROR:"
   129 		puts "TEARDOWN FAILED. ERROR:"
   139 		puts ex.message
   130 		puts ex.message
   140 		puts "*************************"
   131 		puts "*************************"
   146 				puts "MATTI get wrong application in UI (" + app_name +"). Start rebooting...!!!!"
   137 				puts "MATTI get wrong application in UI (" + app_name +"). Start rebooting...!!!!"
   147 				@sut.reset
   138 				@sut.reset
   148 				puts "Reboot is done!!"
   139 				puts "Reboot is done!!"
   149 				app_name = @sut.application.executable_name.split(".exe")[0].to_s
   140 				app_name = @sut.application.executable_name.split(".exe")[0].to_s
   150 				puts "Application on the screen is " + app_name
   141 				puts "Application on the screen is " + app_name
   151 				#lets see that there is not any calendar widget on the homescreen
       
   152 				navigate_to_first_homescreen
   142 				navigate_to_first_homescreen
   153 				if @sut.application(:name => app_name).test_object_exists?("HbWidget",{:name => 'CalendarWidget'}) then
   143 				delete_calendar_events_via_UI
   154 					remove_calendar_widget_from_homescreen(0)
       
   155 				end
       
   156 				delete_calendar_events(@sut.application(:name => app_name))
       
   157 			end
   144 			end
   158 		rescue Exception => e
   145 		rescue Exception => e
   159 			puts "TEARDOWN BEGIN-RESCUE FAILED. ERROR:"
   146 			puts "TEARDOWN BEGIN-RESCUE FAILED. ERROR:"
   160 			puts e.message
   147 			puts e.message
   161 			puts "*************************"
   148 			puts "*************************"
   162 		end
   149 		end
   163 	end		
   150 	end		
   164 	#begin
       
   165 	#	navigate_to_first_homescreen
       
   166 	#	if @sut.application(:name => 'hsapplication').test_object_exists?("HbWidget",{:name => 'CalendarWidget'}) then
       
   167 	#		remove_calendar_widget_from_homescreen
       
   168 	#	end
       
   169 	#rescue
       
   170 	#end 
       
   171 	#delete_calendar_events(@sut.application(:name => 'hsapplication'))
       
   172   end # teardown
   151   end # teardown
   173   
   152   
       
   153     ########################################################################################################################################
       
   154 	#
       
   155 	#	add_calendar_widget_to_homescreen
       
   156 	#
       
   157 	#	description:
       
   158 	#		This function adds calendar widget to Home screen via application list
       
   159 	#
       
   160 	#	preconditions: 
       
   161 	#
       
   162 	#	parameters:
       
   163 	#		
       
   164 	#
       
   165 	#	created: Jarno Mäkelä
       
   166 	#	creation date: 18-May-2010
       
   167 	#
       
   168 	########################################################################################################################################
       
   169 	
   174   def add_calendar_widget_to_homescreen(app, browse_to_list)
   170   def add_calendar_widget_to_homescreen(app, browse_to_list)
   175 	#selects calendar widget from applications-menu and adds it to home screen
   171 	#selects calendar widget from applications-menu and adds it to home screen
   176 	#Lets calculate, how many application list items there is seen
   172 	#Lets calculate, how many application list items there is seen
   177 
       
   178 	identificator = TestObjectIdentificator.new(:type => :HsListViewItem)
   173 	identificator = TestObjectIdentificator.new(:type => :HsListViewItem)
   179 	xml =  app.HbListView( :name => 'allAppsListView' ).xml_data 
   174 	xml =  app.HbListView( :name => 'listView' ).xml_data 
   180 	element_set = xml.xpath( xpath = identificator.get_xpath_to_identify( xml ) ) 
   175 	element_set = xml.xpath( xpath = identificator.get_xpath_to_identify( xml ) ) 
   181 	item_count = element_set.size
   176 	item_count = element_set.size
   182 	#puts "item_count = ",item_count
   177 	#puts "item_count = ",item_count
   183 	item_index = 4
   178 	item_index = 4
   184 	#lets check if calendar widget is visible on display. If not, we flick until we get it visible
   179 	#lets check if calendar widget is visible on display. If not, we flick until we get it visible
   185 	while item_index < item_count
   180 	while item_index < item_count
   186 		if app.test_object_exists?("HbTextItem",{:text => 'CalendarWidget',:visibleOnScreen => 'true'}) then
   181 		if app.test_object_exists?("HbTextItem",{:text => 'CalendarWidget',:visibleOnScreen => 'true'}) then
   187 			#app.HbTextItem(:__index => item_index-1).tap_down
       
   188 			#app.HbTextItem(:__index => item_index-1).flick(:Up)
       
   189 			#app.HbListViewItem(:text => 'Bedrock').gesture(:Up,1,450,:Left,true)
       
   190 			if browse_to_list == 'longpressHS' then
   182 			if browse_to_list == 'longpressHS' then
   191 				app.HbTextItem(:text => 'CalendarWidget').tap
   183 				app.HbTextItem(:text => 'CalendarWidget').tap
   192 			else
   184 			else
   193 				app.HbTextItem(:text => 'CalendarWidget').tap
   185 				app.HbTextItem(:text => 'CalendarWidget').tap
   194 				app.HbTextItem( :text => 'Add to Home screen' ).tap
   186 				app.HbTextItem( :text => 'Add to Home screen' ).tap
   195 				app.HbIconItem(:iconName => 'qtg_mono_back').tap
   187 				app.HbIconItem(:iconName => 'qtg_mono_back').tap
   196 			end
   188 			end
   197 			break
   189 			break
   198 		else
   190 		else
   199 			#app.HbTextItem(:__index => item_index-1).tap_down
       
   200 			#app.HbListViewItem(:__index => item_index-1).flick(:Up)
       
   201 			app.HsListViewItem(:__index => item_index-1).gesture(:Up,1,550,{:Left,true})
   191 			app.HsListViewItem(:__index => item_index-1).gesture(:Up,1,550,{:Left,true})
   202 		end
   192 		end
   203 		item_index +=2
   193 		item_index +=2
   204 		if item_index >= item_count then
   194 		if item_index >= item_count then
   205 			identificator = TestObjectIdentificator.new(:type => :HsListViewItem) 
   195 			identificator = TestObjectIdentificator.new(:type => :HsListViewItem) 
   209 			#puts "item_count = ",item_count
   199 			#puts "item_count = ",item_count
   210 			item_index = 4
   200 			item_index = 4
   211 		end
   201 		end
   212 	end
   202 	end
   213 
   203 
   214 	if browse_to_list != 'longpressHS' then
   204 	#if browse_to_list != 'longpressHS' then
   215 		app.HbIconItem(:iconName => 'qtg_mono_back').tap
   205 	#	app.HbIconItem(:iconName => 'qtg_mono_back').tap
   216 	end
   206 	#end
   217 	#verify, that there exists calendar widget in homescreen
   207   end
   218 	#verify(){app.HbWidget( :name => 'CalendarWidget' )}
   208   
       
   209     ########################################################################################################################################
       
   210 	#
       
   211 	#	check_phone_date
       
   212 	#
       
   213 	#	description:
       
   214 	#		This function checks the date of phone 
       
   215 	#
       
   216 	#	preconditions: 
       
   217 	#
       
   218 	#	parameters:
       
   219 	#		
       
   220 	#
       
   221 	#	created: Jarno Mäkelä
       
   222 	#	creation date: 18-May-2010
       
   223 	#
       
   224 	########################################################################################################################################
       
   225 	
       
   226   def check_phone_date
       
   227 	#Temporarily lets assume, that phone date is same as current real time, since clock application crashes in phone
       
   228 	clock_app = @sut.run(:name => "clock.exe")
       
   229 	date = clock_app.HbLabel( :name => 'dateLabel' ).HbTextItem.attribute("text")
       
   230 	#date = Time.now
       
   231 	puts "date is: ",date
       
   232 	#parse day,month and year
       
   233 	@day = date[4..5]
       
   234 	puts "day:", @day
       
   235 	@month = date[7..8]
       
   236 	puts "month:", @month
       
   237 	@year = date[10..13]
       
   238 	puts "year:",@year
       
   239 	clock_app.close
       
   240   end
       
   241   
       
   242     ########################################################################################################################################
       
   243 	#
       
   244 	#	check_phone_time
       
   245 	#
       
   246 	#	description:
       
   247 	#		This function checks the time of phone 
       
   248 	#
       
   249 	#	preconditions: 
       
   250 	#
       
   251 	#	parameters:
       
   252 	#		
       
   253 	#
       
   254 	#	created: Jarno Mäkelä
       
   255 	#	creation date: 18-May-2010
       
   256 	#
       
   257 	########################################################################################################################################
       
   258 	
       
   259   def check_phone_time
       
   260 	app = @sut.application(:name => 'hsapplication')
       
   261 	time = app.HbStatusBar.HbTextItem.attribute("text")
       
   262 	puts "time is: ",time
       
   263 	#parse hour and minute
       
   264 	@hour = time[0..1]
       
   265 	temp_hour = @hour.to_i
       
   266 	if time.index('pm') != nil
       
   267 		if temp_hour != 12 then
       
   268 			temp_hour = temp_hour +12
       
   269 		end
       
   270 	end
       
   271 	if time.index('am') != nil || time.index('pm') != nil then
       
   272 		@hourformat_12 = true
       
   273 	else
       
   274 		@hourformat_12 = false
       
   275 	end
       
   276 	@hour = temp_hour.to_s
       
   277 	puts "hour:", @hour
       
   278 	@minute = time[3..4]
       
   279 	puts "minute:", @minute
       
   280   end
       
   281   
       
   282     ########################################################################################################################################
       
   283 	#
       
   284 	#	calculate_date
       
   285 	#
       
   286 	#	description:
       
   287 	#		This function calculates the correct date from unchecked date values
       
   288 	#
       
   289 	#	preconditions: 
       
   290 	#
       
   291 	#	parameters:
       
   292 	#		-day: 		unhandled day value
       
   293 	#		-month:		unhandled month value
       
   294 	#		-year: 		unhandled year value
       
   295 	#		-hour: 		unhandled hour value
       
   296 	#		-minute: 	unhandled minute value
       
   297 	#
       
   298 	#	return value:
       
   299 	#		handled date string in fixture needed format (dd-mm-yyyy hh:mm:00)
       
   300 	#
       
   301 	#	created: Jarno Mäkelä
       
   302 	#	creation date: 18-May-2010
       
   303 	#
       
   304 	########################################################################################################################################
       
   305 	
       
   306   def calculate_date(day, month, year, hour, minute)
       
   307 	#let's check the minute
       
   308 	if(minute >=60) then
       
   309 		minute = minute - 60
       
   310 		hour= hour +1
       
   311 	end
       
   312 	if(hour >=24) then
       
   313 		hour = hour - 24
       
   314 		day = day +1
       
   315 	end
       
   316 	if(day > 31) then
       
   317 		if(month == 1)||(month == 3)||(month == 5)||(month == 7)||(month == 8)||(month == 10)||(month == 12) then
       
   318 			month = month +1
       
   319 			day = day - 31
       
   320 		elsif(month == 4)||(month == 6)||(month == 9)||(month == 11) then
       
   321 			month = month +1
       
   322 			day = day - 30
       
   323 		elsif(month == 2) then
       
   324 			if ( year % 100 != 0 && year % 4 == 0 || year % 400 == 0 ) then
       
   325 				month = month +1
       
   326 				day = day -29
       
   327 			else
       
   328 				month = month +1
       
   329 				day = day - 28
       
   330 			end
       
   331 		end
       
   332 	end
       
   333 	if(month > 12) then
       
   334 		month = month - 12
       
   335 		year = year +1
       
   336 	end
       
   337 	if(day <10) then
       
   338 		returnday = '0'+day.to_s
       
   339 	else
       
   340 		returnday = day.to_s
       
   341 	end
       
   342 	if(month < 10) then
       
   343 		returnmonth = '0' + month.to_s
       
   344 	else
       
   345 		returnmonth = month.to_s
       
   346 	end
       
   347 	if(minute < 10) then
       
   348 		returnminute = '0'+minute.to_s
       
   349 	else
       
   350 		returnminute = minute.to_s
       
   351 	end
       
   352 	if(hour < 10) then
       
   353 		returnhour = '0'+hour.to_s
       
   354 	else
       
   355 		returnhour = hour.to_s
       
   356 	end
       
   357 	return returnday,'-',returnmonth,'-',year.to_s,' ',returnhour,':',returnminute,':00'
       
   358   end
       
   359   
       
   360     ########################################################################################################################################
       
   361 	#
       
   362 	#	convert_time_to_12hour_format
       
   363 	#
       
   364 	#	description:
       
   365 	#		This function converts 24 hour time to 12 hour time format
       
   366 	#
       
   367 	#	preconditions: 
       
   368 	#
       
   369 	#	parameters:
       
   370 	#		-conv_timestr:				time string that is needed to convert
       
   371 	#
       
   372 	#	return value:
       
   373 	#		correctly converted time string
       
   374 	#
       
   375 	#	created: Jarno Mäkelä
       
   376 	#	creation date: 25-May-2010
       
   377 	#
       
   378 	########################################################################################################################################
       
   379 	
       
   380   def convert_time_to_12hour_format(conv_timestr)
       
   381 	hour = conv_timestr[0..1].to_i
       
   382 	#puts "hour:", hour
       
   383 	if hour >= 12 then
       
   384 		if hour == 12 then
       
   385 			return hour.to_s+':'+conv_timestr[3..4]+' pm'
       
   386 		else
       
   387 			hour = hour -12
       
   388 			if hour < 10 then
       
   389 				return '0'+hour.to_s+':'+conv_timestr[3..4]+' pm'
       
   390 			else
       
   391 				return hour.to_s+':'+conv_timestr[3..4]+' pm'
       
   392 			end
       
   393 		end
       
   394 	else
       
   395 		if hour == 0 then
       
   396 			hour = 12
       
   397 			return hour.to_s+':'+conv_timestr[3..4]+' am'
       
   398 		elsif hour < 10 then
       
   399 			return '0'+hour.to_s+':'+conv_timestr[3..4]+' am'
       
   400 		else
       
   401 			return hour.to_s+':'+conv_timestr[3..4]+' am'
       
   402 		end
       
   403 	end
       
   404   end
       
   405 
       
   406     ########################################################################################################################################
       
   407 	#
       
   408 	#	navigate_to_first_homescreen
       
   409 	#
       
   410 	#	description:
       
   411 	#		This function goes to first homescreen page from anywhere of homescreen pages
       
   412 	#
       
   413 	#	preconditions: 
       
   414 	#		-Phone is in homescreen
       
   415 	#	parameters:
       
   416 	#		None
       
   417 	#
       
   418 	#	created: Jarno Mäkelä
       
   419 	#	creation date: 02-Jun-2010
       
   420 	#
       
   421 	########################################################################################################################################
       
   422 	
       
   423   def navigate_to_first_homescreen
       
   424 	app = @sut.application(:name => 'hsapplication')
       
   425 	#Check, which HS we are
       
   426 	for i in 0..(@HS_count-1)
       
   427 		if(app.HsIdleWidget.HbWidget( :name => 'controlLayer' ).HsPageIndicator( :name => 'pageIndicator' ).HsPageIndicatorItem(:__index =>i).test_object_exists?("HbIconItem",{:iconName => 'qtg_graf_hspage_highlight'})) then
       
   428 			puts "we are in HS " + (i+1).to_s
       
   429 			current_HS_location = i
       
   430 			break
       
   431 		end
       
   432 	end
       
   433 	#Go to first HS if we are not there
       
   434 	if current_HS_location != 0 then
       
   435 		for j in 1..current_HS_location
       
   436 			app.HsIdleWidget.HbWidget( :name => 'controlLayer' ).HsPageIndicator( :name => 'pageIndicator' ).HsPageIndicatorItem(:__index =>current_HS_location).gesture(:Right,1,200)
       
   437 		end
       
   438 	end
   219   end
   439   end
   220   
   440   
   221     ########################################################################################################################################
   441     ########################################################################################################################################
   222 	#
   442 	#
   223 	#	remove_calendar_widget_from_homescreen
   443 	#	remove_calendar_widget_from_homescreen
   235 	#
   455 	#
   236 	########################################################################################################################################
   456 	########################################################################################################################################
   237 	
   457 	
   238   def remove_calendar_widget_from_homescreen(hs_pagenumber)
   458   def remove_calendar_widget_from_homescreen(hs_pagenumber)
   239 	app = @sut.application(:name => 'hsapplication')
   459 	app = @sut.application(:name => 'hsapplication')
   240 	#verify(){@sut.application.HbIconItem(:iconName => 'hs_applib_button.png')}
       
   241 	#verify(){app.HbWidget( :name => 'CalendarWidget' )}
       
   242 	#find correct widget host object
   460 	#find correct widget host object
   243 	calendar_widget_object = app.HsPage(:__index => hs_pagenumber).find(:name => 'CalendarWidget')
   461 	calendar_widget_object = app.HsIdleWidget.HbWidget(:__index =>2).HsPageVisual(:__index => hs_pagenumber).find(:name => 'CalendarWidget')
   244 	#app.HsPage(:__index => hs_pagenumber).HsWidgetHost.HsCalendarWidget.HbWidget( :name => 'CalendarWidget' ).tap_down
       
   245 	calendar_widget_object.tap_down
   462 	calendar_widget_object.tap_down
   246 	#app.HbWidget( :name => 'controlLayer' ).HsWidgetHost.HbWidget( :name => 'CalendarWidget' ).tap_down
       
   247 	#app.HbWidget( :name => 'controlLayer' ).HsWidgetHost.HbWidget( :name => 'CalendarWidget' ).drag_to_object(app.HsTrashBinWidget( :name => 'trashBin' ))
       
   248 	calendar_widget_object = app.HbWidget( :name => 'controlLayer' ).find(:name => 'CalendarWidget')
   463 	calendar_widget_object = app.HbWidget( :name => 'controlLayer' ).find(:name => 'CalendarWidget')
   249 	calendar_widget_object.drag_to_object(app.HsTrashBinWidget( :name => 'trashBin' ))
   464 	calendar_widget_object.drag_to_object(app.HsTrashBinWidget( :name => 'trashBin' ))
   250   end
   465   end
   251   
   466   
   252     ########################################################################################################################################
   467     ########################################################################################################################################
   253 	#
   468 	#
   254 	#	create_calendar_event
   469 	#	delete_calendar_events !!!FIXTURE NOT WORKING !!!
       
   470 	#
       
   471 	#	description:
       
   472 	#		This function deletes all calendar events via fixture  
       
   473 	#
       
   474 	#	preconditions: 
       
   475 	#
       
   476 	#	parameters:
       
   477 	#		-app:				application needed
       
   478 	#
       
   479 	#	created: Jarno Mäkelä
       
   480 	#	creation date: 19-May-2010
       
   481 	#
       
   482 	########################################################################################################################################
       
   483 	
       
   484   def delete_calendar_events(app)
       
   485 	tmp_id = app.id
       
   486 	tmp = @sut.execution_order
       
   487 	@sut.execution_order = ['S60']
       
   488 	app.apply_behaviour!( :name => 'S60Fixture' )
       
   489 	app.set_application_id(app.attribute('applicationUid'));
       
   490 	response = app.fixture('tapi_calendar_fixture', 'delete_all', {})
       
   491 	@sut.execution_order = tmp
       
   492 	app.apply_behaviour!( :name => 'QtFixture' ) 
       
   493 	app.set_application_id(tmp_id)
       
   494 	response
       
   495   end
       
   496 
       
   497     ########################################################################################################################################
       
   498 	#
       
   499 	#	delete_calendar_events_via_UI
       
   500 	#
       
   501 	#	description:
       
   502 	#		This function deletes all calendar events via calendar UI  
       
   503 	#
       
   504 	#	preconditions: 
       
   505 	#
       
   506 	#	parameters:
       
   507 	#		-app:				application needed
       
   508 	#
       
   509 	#	created: Jarno Mäkelä
       
   510 	#	creation date: 13-Aug-2010
       
   511 	#
       
   512 	########################################################################################################################################
       
   513 	  
       
   514   def delete_calendar_events_via_UI
       
   515 	cal_app = @sut.run(:name => "calendar.exe")
       
   516 	cal_app.HbMarqueeItem(:text => 'Calendar').tap
       
   517 	if cal_app.test_object_exists?("HbTextItem",{:text => 'Delete entries'}) then
       
   518 		cal_app.HbTextItem(:text => 'Delete entries').tap
       
   519 		cal_app.HbTextItem(:text => 'All entries').tap
       
   520 		cal_app.HbTextItem(:text => 'Delete').tap
       
   521 	end
       
   522 	cal_app.close
       
   523   end
       
   524   
       
   525     ########################################################################################################################################
       
   526 	#
       
   527 	#	set_event_time_via_UI
       
   528 	#
       
   529 	#	description:
       
   530 	#		This function sets wanted event time via calendar UI  
       
   531 	#
       
   532 	#	preconditions: 
       
   533 	#
       
   534 	#	parameters:
       
   535 	#		-app:				application needed
       
   536 	#		-time:				time, what is wanted to set
       
   537 	#
       
   538 	#	created: Jarno Mäkelä
       
   539 	#	creation date: 13-Aug-2010
       
   540 	#
       
   541 	########################################################################################################################################
       
   542 	  
       
   543   def set_event_time_via_UI(app,time)
       
   544 	#Check,what value there is currently in hour time
       
   545 	current_hour_value = app.HbDatePickerView(:__index => 0).HbAbstractItemContainer.HbDatePickerViewItem(:__index => 2).HbTextItem.attribute("text")
       
   546 	puts "current_hour_value = " + current_hour_value
       
   547 	current_hour_value_i = current_hour_value.to_i
       
   548 	if @hourformat_12 == true then
       
   549 		#12 hour time used
       
   550 		set_time_value = convert_time_to_12hour_format(time)
       
   551 	else
       
   552 		#24 hour time used
       
   553 		set_time_value = time
       
   554 	end 
       
   555 	set_time_hour_value = set_time_value[0..1]
       
   556 	puts "set_time_hour_value = " + set_time_hour_value
       
   557 	set_time_hour_value_i = set_time_hour_value.to_i
       
   558 	if set_time_hour_value_i < current_hour_value_i then
       
   559 		if @hourformat_12 == true then
       
   560 			#12 hour time used
       
   561 			set_time_hour_value_i = set_time_hour_value_i +12
       
   562 		else
       
   563 			#24 hour time used
       
   564 			set_time_hour_value_i = set_time_hour_value_i +24
       
   565 		end 
       
   566 	end
       
   567 	for i in 0..(set_time_hour_value_i - 1 - current_hour_value_i)
       
   568 		index = 2 + i
       
   569 		app.HbDatePickerView(:__index => 0).HbAbstractItemContainer.HbDatePickerViewItem(:__index => index).HbTextItem.gesture(:Up,0.5,53)
       
   570 	end
       
   571   end
       
   572   
       
   573     ########################################################################################################################################
       
   574 	#
       
   575 	#	create_calendar_event !!!FIXTURE NOT WORKING !!!
   255 	#
   576 	#
   256 	#	description:
   577 	#	description:
   257 	#		This function creates calendar event via fixture  
   578 	#		This function creates calendar event via fixture  
   258 	#
   579 	#
   259 	#	preconditions: 
   580 	#	preconditions: 
   331 		return start_date[0..1]+' '+month_text+' '+time_to_verify
   652 		return start_date[0..1]+' '+month_text+' '+time_to_verify
   332 	else
   653 	else
   333 		puts "time_to_verify:", time_to_verify
   654 		puts "time_to_verify:", time_to_verify
   334 		return time_to_verify
   655 		return time_to_verify
   335 	end
   656 	end
   336 	#sut = MATTI.sut(:Id => 's60')
       
   337 	#app = sut.run(:name => "HtiAdmin.exe")
       
   338 	#app.fixture('tapi_calendar_fixture', 'add_meeting', {:description =>  subject, :start_date => '17-05-2010 15:00:00', :end_date => '17-05-2010 16:00:00'})
       
   339 	#app.fixture('tapi_calendar_fixture', 'add_meeting', {:description =>  subject, :start_date => start_date, :end_date => end_date})
       
   340 	#app.close()
       
   341   end
   657   end
   342   
   658   
   343     ########################################################################################################################################
   659     ########################################################################################################################################
   344 	#
   660 	#
   345 	#	convert_time_to_12hour_format
   661 	#	create_calendar_event_via_calendar
   346 	#
   662 	#
   347 	#	description:
   663 	#	description:
   348 	#		This function converts 24 hour time to 12 hour time format
   664 	#		This function creates calendar event via calendar application UI  
   349 	#
   665 	#
   350 	#	preconditions: 
   666 	#	preconditions: 
   351 	#
   667 	#
   352 	#	parameters:
   668 	#	parameters:
   353 	#		-conv_timestr:				time string that is needed to convert
   669 	#		-subject:			subject of the meeting (not working yet)
       
   670 	#		-start_day:	    	start day of the meeting(not working yet)
       
   671 	#		-start_month:		start month of the meeting(not working yet)
       
   672 	#		-start_year:		start year of the meeting(not working yet)
       
   673 	#		-start_hour:		start hour of the meeting(minimun value two hours more than current time)
       
   674 	#		-start_minute:		start minute of the meeting(not working yet)
       
   675 	#		-duration_days: 	duration of the days, that meeting is lasting(not working yet)
       
   676 	#		-duration_hours:	duration of the hours, that meeting is lasting(not working yet)
       
   677 	#		-duration_minutes:	duration of the minutes, that meeting is lasting(not working yet)
   354 	#
   678 	#
   355 	#	return value:
   679 	#	return value:
   356 	#		correctly converted time string
   680 	#		-time_to_verify:	time, that is supposed to be in the calendar widget (Format: hh:mm-hh:mm or hh:mm (am/pm)-hh:mm (am/pm))
   357 	#
   681 	#
   358 	#	created: Jarno Mäkelä
   682 	#	created: Jarno Mäkelä
   359 	#	creation date: 25-May-2010
   683 	#	creation date: 13-Aug-2010
   360 	#
   684 	#
   361 	########################################################################################################################################
   685 	########################################################################################################################################
   362 	
   686 	
   363   def convert_time_to_12hour_format(conv_timestr)
   687   def create_calendar_event_via_calendar(subject,start_day, start_month, start_year, start_hour, start_minute, duration_days, duration_hours, duration_minutes)
   364 	#let's first check the hour
   688 	#Creates calendar event via calendar application
   365 	hour = conv_timestr[0..1].to_i
   689 	#let's calculate the real values of start date. In parameters, eg. the day value can exceed 31, so we need to change month and set day
   366 	#puts "hour:", hour
   690 	#to 1. Same calculation needed for other parameter values
   367 	if hour >= 12 then
   691 	if start_minute > 15 then
   368 		if hour == 12 then
   692 		if start_minute > 45 then
   369 			return hour.to_s+':'+conv_timestr[3..4]+' pm'
   693 			start_hour = start_hour + 1
       
   694 			start_minute = 0
   370 		else
   695 		else
   371 			hour = hour -12
   696 			start_minute = 30
   372 			if hour < 10 then
   697 		end
   373 				return '0'+hour.to_s+':'+conv_timestr[3..4]+' pm'
   698 	else
       
   699 		start_minute = 0
       
   700 	end
       
   701 	start_date = calculate_date(start_day, start_month, start_year, start_hour, start_minute)
       
   702 	puts "start_date:",start_date.to_s
       
   703 	start_time_split = (start_date.to_s).split
       
   704 	start_time = start_time_split[1]
       
   705 	start_time_to_verify = start_time[0..4] 
       
   706 	puts "start_time_to_verify:",start_time_to_verify
       
   707 	end_date = calculate_date(start_day+duration_days, start_month, start_year, start_hour+duration_hours, start_minute + duration_minutes)
       
   708 	puts "end_date:",end_date.to_s
       
   709 	end_time_split = (end_date.to_s).split
       
   710 	end_time = end_time_split[1]
       
   711 	end_time_to_verify = end_time[0..4]
       
   712 	puts "end_time_to_verify:",end_time_to_verify
       
   713 	#puts "create_calendar_event_via_calendar @hourformat_12 = " + @hourformat_12.to_s
       
   714 	if @hourformat_12 == true then
       
   715 		#12 hour time used
       
   716 		time_to_verify = convert_time_to_12hour_format(start_time_to_verify)+'-'+convert_time_to_12hour_format(end_time_to_verify)
       
   717 	else
       
   718 		#24 hour time used
       
   719 		time_to_verify = start_time_to_verify+'-'+end_time_to_verify
       
   720 	end
       
   721 	cal_app = @sut.run(:name => "calendar.exe")
       
   722 	#cal_app.HbIconItem(:iconName => 'qtg_mono_options_menu').tap
       
   723 	cal_app.HbMarqueeItem(:text => 'Calendar').tap
       
   724 	cal_app.HbTextItem(:text => 'New entry').tap
       
   725 	#Add the subject. Cannot do this currently,since phone won't go away from text input
       
   726 	#cal_app.HbLineEdit( :name => 'subjectItem' ).tap
       
   727 	#cal_app.HbLineEdit( :name => 'subjectItem' ).HbScrollArea.HbWidget.type_text(subject)
       
   728 	#cal_app.QGraphicsWidget( :name => 'vkbHandle' ).tap
       
   729 	#Add start time
       
   730 	cal_app.HbPushButton( :name => 'startTime' ).tap
       
   731 	set_event_time_via_UI(cal_app,start_time_to_verify)
       
   732 	cal_app.HbTextItem( :text => 'OK' ).tap
       
   733 	cal_app.HbIconItem(:iconName => 'qtg_mono_back').tap
       
   734 	#cal_app.HbIconItem(:iconName => 'qtg_mono_back').tap
       
   735 	cal_app.close
       
   736 	#let's put date if event is in other future day than today
       
   737 	if start_day > @day.to_i then
       
   738 	   start_date = start_time_split[0]
       
   739 	   month_text = case start_date[3..4]
       
   740 			when "01" then "Jan"
       
   741 			when "02" then "Feb"
       
   742 			when "03" then "Mar"
       
   743 			when "04" then "Apr"
       
   744 			when "05" then "May"
       
   745 			when "06" then "Jun"
       
   746 			when "07" then "Jul"
       
   747 			when "08" then "Aug"
       
   748 			when "09" then "Sep"
       
   749 			when "10" then "Oct"
       
   750 			when "11" then "Nov"
       
   751 			when "12" then "Dec"
       
   752 		end
       
   753 		puts "time_to_verify:", start_date[0..1]+' '+month_text+' '+time_to_verify
       
   754 		return start_date[0..1]+' '+month_text+' '+time_to_verify
       
   755 	else
       
   756 		puts "time_to_verify:", time_to_verify
       
   757 		return time_to_verify
       
   758 	end
       
   759   end
       
   760   
       
   761   ##############################################################################################################################################
       
   762   # Calendar widget - initialize
       
   763   ##############################################################################################################################################
       
   764   #
       
   765   # Purpose of the test is to make initializing of calendar widget environment 
       
   766   #
       
   767   #	Created at: 10.08.2010
       
   768   #	Created by: Jarno Mäkelä
       
   769   #	Reviewed by: 
       
   770   #
       
   771   #	===	Initializing consists
       
   772   #	- Counting of existing Home screens
       
   773   # - Checking phone date
       
   774   # - Checking calendar widget existing and removing it if it is found in HS
       
   775   # - Navigating to first HS
       
   776   #
       
   777   #	===	params
       
   778   #	none
       
   779   #
       
   780   ############################################################################################################################################
       
   781 
       
   782   def test_initialize_calendar_widget_test_env
       
   783 	puts "test_initialize_calendar_widget_test_env start"
       
   784 	app = @sut.application(:name => 'hsapplication')
       
   785 	#Let's check existing Home screens
       
   786 	#identificator = TestObjectIdentificator.new(:type => :HsPageVisual)
       
   787 	#xml =  app.HsIdleWidget.HbWidget( :__index =>2 ).xml_data 
       
   788 	#element_set = xml.xpath( xpath = identificator.get_xpath_to_identify( xml ) ) 
       
   789 	#@HS_count = element_set.size
       
   790 	#check_phone_date
       
   791 	#Check, if calendar widget exists in some of the Home screens
       
   792 	if (app.test_object_exists?("HbWidget",{:name => 'CalendarWidget'})) then
       
   793 		#Check, which HS window calendar widget exists
       
   794 		for i in 0..(@HS_count-1)
       
   795 			if(app.HsIdleWidget.HbWidget(:__index =>2).HsPageVisual(:__index =>i).test_object_exists?("HbWidget",{:name => 'CalendarWidget'})) then
       
   796 				puts "calendar widget found in HS " + (i+1).to_s
       
   797 				widget_HS_location = i
       
   798 				break
       
   799 			end
       
   800 		end
       
   801 		#Go to homescreen, where calendar widget is and remove it
       
   802 		#first check, that we are in first HS
       
   803 		for i in 0..(@HS_count-1)
       
   804 			if(app.HsIdleWidget.HbWidget( :name => 'controlLayer' ).HsPageIndicator( :name => 'pageIndicator' ).HsPageIndicatorItem(:__index =>i).test_object_exists?("HbIconItem",{:iconName => 'qtg_graf_hspage_highlight'})) then
       
   805 				puts "we are in HS " + (i+1).to_s
       
   806 				our_HS_location = i
       
   807 				break
       
   808 			end
       
   809 		end
       
   810 		#Go to same HS where calendar widget is
       
   811 		if our_HS_location == widget_HS_location then
       
   812 			remove_calendar_widget_from_homescreen(our_HS_location)
       
   813 		else
       
   814 			if our_HS_location < widget_HS_location then
       
   815 				for i in our_HS_location..widget_HS_location-1
       
   816 					app.HsIdleWidget.HbWidget( :name => 'controlLayer' ).HsPageIndicator( :name => 'pageIndicator' ).HsPageIndicatorItem(:__index =>our_HS_location).gesture(:Left,1,200)
       
   817 				end
       
   818 				sleep 1
       
   819 				remove_calendar_widget_from_homescreen(widget_HS_location)
   374 			else
   820 			else
   375 				return hour.to_s+':'+conv_timestr[3..4]+' pm'
   821 				for i in widget_HS_location..our_HS_location-1
       
   822 					app.HsIdleWidget.HbWidget( :name => 'controlLayer' ).HsPageIndicator( :name => 'pageIndicator' ).HsPageIndicatorItem(:__index =>our_HS_location).gesture(:Right,1,200)
       
   823 				end
       
   824 				sleep 1
       
   825 				remove_calendar_widget_from_homescreen(widget_HS_location)
   376 			end
   826 			end
   377 		end
   827 		end
   378 	else
   828 	end
   379 		if hour == 0 then
   829 	#navigate to the first home screen
   380 			hour = 12
   830 	navigate_to_first_homescreen
   381 			return hour.to_s+':'+conv_timestr[3..4]+' am'
   831   end
   382 		elsif hour < 10 then
   832   
   383 			return '0'+hour.to_s+':'+conv_timestr[3..4]+' am'
       
   384 		else
       
   385 			return hour.to_s+':'+conv_timestr[3..4]+' am'
       
   386 		end
       
   387 	end
       
   388   end
       
   389   
       
   390     ########################################################################################################################################
       
   391 	#
       
   392 	#	delete_calendar_events
       
   393 	#
       
   394 	#	description:
       
   395 	#		This function deletes all calendar events via fixture  
       
   396 	#
       
   397 	#	preconditions: 
       
   398 	#
       
   399 	#	parameters:
       
   400 	#		-app:				application needed
       
   401 	#
       
   402 	#	created: Jarno Mäkelä
       
   403 	#	creation date: 19-May-2010
       
   404 	#
       
   405 	########################################################################################################################################
       
   406 	
       
   407   def delete_calendar_events(app)
       
   408 	tmp_id = app.id
       
   409 	tmp = @sut.execution_order
       
   410 	@sut.execution_order = ['S60']
       
   411 	app.apply_behaviour!( :name => 'S60Fixture' )
       
   412 	app.set_application_id(app.attribute('applicationUid'));
       
   413 	response = app.fixture('tapi_calendar_fixture', 'delete_all', {})
       
   414 	@sut.execution_order = tmp
       
   415 	app.apply_behaviour!( :name => 'QtFixture' ) 
       
   416 	app.set_application_id(tmp_id)
       
   417 	response
       
   418   end
       
   419   
       
   420   def create_calendar_event_via_calendar(subject)
       
   421 	#Creates calendar event
       
   422 	cal_app = @sut.run(:name => "calendar.exe")
       
   423 	cal_app.HbIconItem(:iconName => 'qtg_mono_options_menu').tap
       
   424 	cal_app.HbTextItem(:text => 'New event')
       
   425 	#Add the subject
       
   426 	cal_app.HbDataFormViewItem(:__index =>0).HbWidget.tap
       
   427 	cal_app.HbDataFormViewItem(:__index =>0).HbWidget.type_text(subject)
       
   428 	cal_app.HbTextItem(:text => 'Subject').tap
       
   429 	#Add start time
       
   430 	cal_app.CalenEditorCustomItem(:__index=>0).HbWidget.HbPushButton(:__index=>0).tap
       
   431 	
       
   432   end
       
   433   
       
   434     ########################################################################################################################################
       
   435 	#
       
   436 	#	check_phone_date
       
   437 	#
       
   438 	#	description:
       
   439 	#		This function checks the date of phone 
       
   440 	#
       
   441 	#	preconditions: 
       
   442 	#
       
   443 	#	parameters:
       
   444 	#		
       
   445 	#
       
   446 	#	created: Jarno Mäkelä
       
   447 	#	creation date: 18-May-2010
       
   448 	#
       
   449 	########################################################################################################################################
       
   450 	
       
   451   def check_phone_date
       
   452 	#Temporarily lets assume, that phone date is same as current real time, since clock application crashes in phone
       
   453 	clock_app = @sut.run(:name => "clock.exe")
       
   454 	date = clock_app.HbLabel( :name => 'dateLabel' ).HbTextItem.attribute("text")
       
   455 	#date = Time.now
       
   456 	puts "date is: ",date
       
   457 	#parse day,month and year
       
   458 	@day = date[4..5]
       
   459 	#@day = (date.day).to_s
       
   460 	#if @day.to_i < 10 then
       
   461 		#@day = '0'+ (date.day).to_s
       
   462 	#end
       
   463 	puts "day:", @day
       
   464 	@month = date[7..8]
       
   465 	#@month = (date.month).to_s
       
   466 	#if @month.to_i < 10 then
       
   467 	#	@month = '0'+ (date.month).to_s
       
   468 	#end
       
   469 	puts "month:", @month
       
   470 	@year = date[10..13]
       
   471 	#@year = (date.year).to_s
       
   472 	puts "year:",@year
       
   473 	clock_app.close
       
   474   end
       
   475   
       
   476     ########################################################################################################################################
       
   477 	#
       
   478 	#	check_phone_time
       
   479 	#
       
   480 	#	description:
       
   481 	#		This function checks the time of phone 
       
   482 	#
       
   483 	#	preconditions: 
       
   484 	#
       
   485 	#	parameters:
       
   486 	#		
       
   487 	#
       
   488 	#	created: Jarno Mäkelä
       
   489 	#	creation date: 18-May-2010
       
   490 	#
       
   491 	########################################################################################################################################
       
   492 	
       
   493   def check_phone_time
       
   494 	app = @sut.application(:name => 'hsapplication')
       
   495 	time = app.HbStatusBar.HbTextItem.attribute("text")
       
   496 	puts "time is: ",time
       
   497 	#parse hour and minute
       
   498 	@hour = time[0..1]
       
   499 	temp_hour = @hour.to_i
       
   500 	if time.index('pm') != nil
       
   501 		if temp_hour != 12 then
       
   502 			temp_hour = temp_hour +12
       
   503 		end
       
   504 	end
       
   505 	if time.index('am') != nil || time.index('pm') != nil then
       
   506 		@hourformat_12 = true
       
   507 	else
       
   508 		@hourformat_12 = false
       
   509 	end
       
   510 	@hour = temp_hour.to_s
       
   511 	puts "hour:", @hour
       
   512 	@minute = time[3..4]
       
   513 	puts "minute:", @minute
       
   514   end
       
   515   
       
   516     ########################################################################################################################################
       
   517 	#
       
   518 	#	calculate_date
       
   519 	#
       
   520 	#	description:
       
   521 	#		This function calculates the correct date from unchecked date values
       
   522 	#
       
   523 	#	preconditions: 
       
   524 	#
       
   525 	#	parameters:
       
   526 	#		-day: 		unhandled day value
       
   527 	#		-month:		unhandled month value
       
   528 	#		-year: 		unhandled year value
       
   529 	#		-hour: 		unhandled hour value
       
   530 	#		-minute: 	unhandled minute value
       
   531 	#
       
   532 	#	return value:
       
   533 	#		handled date string in fixture needed format (dd-mm-yyyy hh:mm:00)
       
   534 	#
       
   535 	#	created: Jarno Mäkelä
       
   536 	#	creation date: 18-May-2010
       
   537 	#
       
   538 	########################################################################################################################################
       
   539 	
       
   540   def calculate_date(day, month, year, hour, minute)
       
   541 	#let's check the minute
       
   542 	if(minute >=60) then
       
   543 		minute = minute - 60
       
   544 		hour= hour +1
       
   545 	end
       
   546 	if(hour >=24) then
       
   547 		hour = hour - 24
       
   548 		day = day +1
       
   549 	end
       
   550 	if(day > 31) then
       
   551 		if(month == 1)||(month == 3)||(month == 5)||(month == 7)||(month == 8)||(month == 10)||(month == 12) then
       
   552 			month = month +1
       
   553 			day = day - 31
       
   554 		elsif(month == 4)||(month == 6)||(month == 9)||(month == 11) then
       
   555 			month = month +1
       
   556 			day = day - 30
       
   557 		elsif(month == 2) then
       
   558 			if ( year % 100 != 0 && year % 4 == 0 || year % 400 == 0 ) then
       
   559 				month = month +1
       
   560 				day = day -29
       
   561 			else
       
   562 				month = month +1
       
   563 				day = day - 28
       
   564 			end
       
   565 		end
       
   566 	end
       
   567 	if(month > 12) then
       
   568 		month = month - 12
       
   569 		year = year +1
       
   570 	end
       
   571 	if(day <10) then
       
   572 		returnday = '0'+day.to_s
       
   573 	else
       
   574 		returnday = day.to_s
       
   575 	end
       
   576 	if(month < 10) then
       
   577 		returnmonth = '0' + month.to_s
       
   578 	else
       
   579 		returnmonth = month.to_s
       
   580 	end
       
   581 	if(minute < 10) then
       
   582 		returnminute = '0'+minute.to_s
       
   583 	else
       
   584 		returnminute = minute.to_s
       
   585 	end
       
   586 	if(hour < 10) then
       
   587 		returnhour = '0'+hour.to_s
       
   588 	else
       
   589 		returnhour = hour.to_s
       
   590 	end
       
   591 	
       
   592 	return returnday,'-',returnmonth,'-',year.to_s,' ',returnhour,':',returnminute,':00'
       
   593 	
       
   594   end
       
   595   
       
   596     ########################################################################################################################################
       
   597 	#
       
   598 	#	navigate_to_first_homescreen
       
   599 	#
       
   600 	#	description:
       
   601 	#		This function goes to first homescreen page from anywhere of homescreen pages
       
   602 	#
       
   603 	#	preconditions: 
       
   604 	#		-Phone is in homescreen
       
   605 	#	parameters:
       
   606 	#		None
       
   607 	#
       
   608 	#	created: Jarno Mäkelä
       
   609 	#	creation date: 02-Jun-2010
       
   610 	#
       
   611 	########################################################################################################################################
       
   612 	
       
   613   def navigate_to_first_homescreen
       
   614 	app = @sut.application(:name => 'hsapplication')
       
   615 	if app.HsPageIndicatorItem(:__index =>0).test_object_exists?("HbIconItem",{:iconName => 'qtg_graf_hspage_highlight'}) then
       
   616 		page = 1
       
   617 	elsif app.HsPageIndicatorItem(:__index =>1).test_object_exists?("HbIconItem",{:iconName => 'qtg_graf_hspage_highlight'}) then
       
   618 		page = 2
       
   619 		app.HsPageIndicatorItem(:__index =>1).gesture(:Right,1,170)
       
   620 		if app.HsPageIndicatorItem(:__index =>0).test_object_exists?("HbIconItem",{:iconName => 'qtg_graf_hspage_highlight'}) then
       
   621 			page = 1
       
   622 		else
       
   623 			raise VerificationError ,"ERROR: Cannot go to first home screen", caller
       
   624 		end
       
   625 	else
       
   626 		page = 3
       
   627 		app.HsPageIndicatorItem(:__index =>1).gesture(:Right,1,170)
       
   628 		sleep 1
       
   629 		app.HsPageIndicatorItem(:__index =>1).gesture(:Right,1,170)
       
   630 		if app.HsPageIndicatorItem(:__index =>0).test_object_exists?("HbIconItem",{:iconName => 'qtg_graf_hspage_highlight'}) then
       
   631 			page = 1
       
   632 		else
       
   633 			raise VerificationError ,"ERROR: Cannot go to first home screen", caller
       
   634 		end
       
   635 	end
       
   636   end
       
   637 ################################################################################################################################################
   833 ################################################################################################################################################
   638 ###
   834 ###
   639 ###						BAT cases start
   835 ###						BAT cases start
   640 ###
   836 ###
   641 ################################################################################################################################################
   837 ################################################################################################################################################
   650   #	Created by: Jarno Mäkelä
   846   #	Created by: Jarno Mäkelä
   651   #	Reviewed by: 
   847   #	Reviewed by: 
   652   #
   848   #
   653   #	===	preconditions
   849   #	===	preconditions
   654   #	- Device is in Home Screen
   850   #	- Device is in Home Screen
   655   # - Some events in Calendar.
   851   # - There is no calendar widget on any home screens
   656   #
   852   #
   657   #	===	params
   853   #	===	params
   658   #	none
   854   #	none
   659   #
   855   #
   660   ############################################################################################################################################
   856   ############################################################################################################################################
   661   
   857   
   662   def _test_calendar_widget_load_unload_widget_in_HomeScreen
   858   def test_calendar_widget_load_unload_widget_in_HomeScreen
   663 	#running_round = 1
   859 	#running_round = 1
   664 	#max_running_rounds = 2
   860 	#max_running_rounds = 2
   665 	#begin
   861 	#begin
   666 		#Preconditions:
   862 		#Preconditions:
   667 		#Device is in Homescreen
   863 		#Device is in Homescreen
   668 		app = @sut.application(:name => 'hsapplication')
   864 		app = @sut.application(:name => 'hsapplication')
   669 		navigate_to_first_homescreen
       
   670 		verify(){app.HbIconItem(:iconName => 'qtg_mono_applications_all')}
   865 		verify(){app.HbIconItem(:iconName => 'qtg_mono_applications_all')}
   671 		#Some events in calendar
   866 		#There is no calendar widget on any home screens. This is done in initialize test function already
   672 		check_phone_date
   867 		check_phone_date
   673 		check_phone_time
   868 		check_phone_time
   674 		create_calendar_event(app, 'Meeting 1',@day.to_i+1,@month.to_i,@year.to_i,@hour.to_i+1,@minute.to_i,0,1,0)
       
   675 		create_calendar_event(app, 'Meeting 2',@day.to_i+2,@month.to_i,@year.to_i,@hour.to_i-2,@minute.to_i,0,1,0)
       
   676 		#Step 1:Tap application list button in the upper right corner of Home Screen
   869 		#Step 1:Tap application list button in the upper right corner of Home Screen
   677 		app.HbIconItem(:iconName => 'qtg_mono_applications_all').tap
   870 		app.HbIconItem(:iconName => 'qtg_mono_applications_all').tap
   678 		#step 2: Select 'add to homescreen' by longpressing 'Calendar Widget' in the catalog list
   871 		#step 2: Select 'Calendar Widget' by tapping it.
   679 		add_calendar_widget_to_homescreen(app,'AppListButton')
   872 		add_calendar_widget_to_homescreen(app,'AppListButton')
   680 		#step 2 expected: Calendar widget is added to Home Screen.
   873 		#step 2 expected: Calendar widget is added to Home Screen.
   681 		day_to_verify = @day.to_i
   874 		day_to_verify = @day.to_i
   682 		#puts "day_to_verify =", day_to_verify
   875 		#puts "day_to_verify =", day_to_verify
   683 		verify(){app.HbTextItem(:text => day_to_verify)}
   876 		verify(){app.HbLabel( :name => 'dayNumber' ).HbTextItem(:text => day_to_verify)}
   684 		#Calendar widget content contains "No event for next 7 days"
       
   685 		#verify(){app.HbTextItem(:text => 'No events for next 7 days')}
       
   686 		#Verify, that reminder icon in widget is not shown
       
   687 		#if not(app.test_object_exists?("HbIconItem",{:iconName => 'images/bell.PNG'})) then
       
   688 		#	raise VerificationError ,"ERROR: There is not reminder icon in calendar widget, when it should be there", caller
       
   689 		#end
       
   690 		#Step 3 and Step4:Remove calendar widget from display
   877 		#Step 3 and Step4:Remove calendar widget from display
   691 		remove_calendar_widget_from_homescreen(0)
   878 		#remove_calendar_widget_from_homescreen(0)
   692 		delete_calendar_events(app)
       
   693 	#rescue
   879 	#rescue
   694 	#	if (running_round < max_running_rounds) then
   880 	#	if (running_round < max_running_rounds) then
   695     #       running_round = running_round + 1
   881     #       running_round = running_round + 1
   696     #        puts "Some error came during run. Lets try again"
   882     #        puts "Some error came during run. Lets try again"
   697     #        teardown
   883     #        teardown
   746   #	===	params
   932   #	===	params
   747   #	none
   933   #	none
   748   #
   934   #
   749   ############################################################################################################################################
   935   ############################################################################################################################################
   750   
   936   
   751   def _test_calendar_widget_one_event_today_one_event_tomorrow
   937   def test_calendar_widget_one_event_today_one_event_tomorrow
   752 	#running_round = 1
   938 	#running_round = 1
   753 	#max_running_rounds = 2
   939 	#max_running_rounds = 2
   754 	#begin
   940 	#begin
   755 		#Preconditions:
   941 		#Preconditions:
   756 		#Device is in Homescreen
   942 		#Device is in Homescreen
   758 		verify(){app.HbIconItem(:iconName => 'qtg_mono_applications_all')}
   944 		verify(){app.HbIconItem(:iconName => 'qtg_mono_applications_all')}
   759 		navigate_to_first_homescreen
   945 		navigate_to_first_homescreen
   760 		#- One event happens few hours after current phone time at today and one event at tomorrow in Calendar.
   946 		#- One event happens few hours after current phone time at today and one event at tomorrow in Calendar.
   761 		check_phone_date
   947 		check_phone_date
   762 		check_phone_time
   948 		check_phone_time
   763 		today_time_for_verification = create_calendar_event(app, 'Today meeting',@day.to_i,@month.to_i,@year.to_i,@hour.to_i+3,@minute.to_i,0,1,0)
   949 		today_time_for_verification = create_calendar_event_via_calendar("not working",@day.to_i,@month.to_i,@year.to_i,@hour.to_i+2,@minute.to_i,0,1,0)
   764 		tomorrow_time_for_verification = create_calendar_event(app, 'Tomorrow meeting',@day.to_i+1,@month.to_i,@year.to_i,@hour.to_i,@minute.to_i,0,1,0)
   950 		tomorrow_time_for_verification = create_calendar_event(app, 'Tomorrow meeting',@day.to_i+1,@month.to_i,@year.to_i,@hour.to_i,@minute.to_i,0,1,0)
   765 		#-Calendar widget is added to Home Screen.
   951 		#-Calendar widget is added to Home Screen.
   766 		#Not adding calendar widget, if it already exists there
   952 		#Not adding calendar widget, if it already exists there
   767 		if not(app.test_object_exists?("HbWidget",{:name => 'CalendarWidget'})) then
   953 		if not(app.test_object_exists?("HbWidget",{:name => 'CalendarWidget'})) then
   768 			#add calendar widget to home screen
   954 			#add calendar widget to home screen
   817   #	===	params
  1003   #	===	params
   818   #	none
  1004   #	none
   819   #
  1005   #
   820   ############################################################################################################################################
  1006   ############################################################################################################################################
   821   
  1007   
   822   def _test_calendar_widget_overlapping_events
  1008   def test_calendar_widget_overlapping_events
   823 	running_round = 1
  1009 	#Preconditions:
   824 	max_running_rounds = 2
  1010 	#Device is in Homescreen
   825 	begin
  1011 	app = @sut.application(:name => 'hsapplication')
   826 		#Preconditions:
  1012 	verify(){app.HbIconItem(:iconName => 'qtg_mono_applications_all')}
   827 		#Device is in Homescreen
  1013 	#- One event happens few hours after current phone time at today in Calendar.
   828 		app = @sut.application(:name => 'hsapplication')
  1014 	check_phone_date
   829 		verify(){app.HbIconItem(:iconName => 'qtg_mono_applications_all')}
  1015 	check_phone_time
   830 		navigate_to_first_homescreen
  1016 	today_time_for_verification = create_calendar_event_via_calendar("not working",@day.to_i,@month.to_i,@year.to_i,@hour.to_i+2,@minute.to_i,0,0,0)
   831 		#- One event happens few hours after current phone time at today in Calendar.
  1017 	#-Calendar widget is added to Home Screen.
   832 		check_phone_date
  1018 	#Not adding calendar widget, if it already exists there
   833 		check_phone_time
  1019 	if not(app.test_object_exists?("HbWidget",{:name => 'CalendarWidget'})) then
   834 		today_time_for_verification = create_calendar_event(app, 'Today meeting',@day.to_i,@month.to_i,@year.to_i,@hour.to_i+3,@minute.to_i,0,1,0)
  1020 		#add calendar widget to home screen
   835 		#-Calendar widget is added to Home Screen.
  1021 		app.HbIconItem(:iconName => 'qtg_mono_applications_all').tap
   836 		#Not adding calendar widget, if it already exists there
  1022 		add_calendar_widget_to_homescreen(app,'AppListButton')
   837 		if not(app.test_object_exists?("HbWidget",{:name => 'CalendarWidget'})) then
  1023 	end
   838 			#add calendar widget to home screen
  1024 	#Step 1:Check Calendar widget.
   839 			app.HbIconItem(:iconName => 'qtg_mono_applications_all').tap
  1025 	#step 1 Expected: - All icons (widget icon and reminder icon) are shown correctly.
   840 			add_calendar_widget_to_homescreen(app,'AppListButton')
  1026 	#- Calendar widget shows the event as two rows: first row show the event time and second row shows the event title.
   841 		end
  1027 	day_to_verify = @day.to_i
   842 		#Step 1:Check Calendar widget.
  1028 	verify(){app.HbTextItem(:text => day_to_verify)}
   843 		#step 1 Expected: - All icons (widget icon and reminder icon) are shown correctly.
  1029 	verify(){app.HbLabel( :name => 'upperLabel' ).HbTextItem( :text => today_time_for_verification )}
   844 		#- Calendar widget shows the event as two rows: first row show the event time and second row shows the event title.
  1030 	verify(){app.HbLabel( :name => 'lowerLabel' ).HbTextItem( :text => 'Unnamed' )}
   845 		day_to_verify = @day.to_i
  1031 	#Verify, that reminder icon in widget is shown
   846 		verify(){app.HbTextItem(:text => day_to_verify)}
  1032 	if not(app.test_object_exists?("HbFrameItem",{:frameGraphicsName => 'qtg_small_reminder'})) then
   847 		verify(){app.HbLabel( :name => 'upperLabel' ).HbTextItem( :text => today_time_for_verification )}
  1033 		raise VerificationError ,"ERROR: There is not reminder icon in calendar widget, when it should be there", caller
   848 		verify(){app.HbLabel( :name => 'lowerLabel' ).HbTextItem( :text => 'Today meeting' )}
  1034 	end
   849 		#Verify, that reminder icon in widget is shown
  1035 	
   850 		#if not(app.test_object_exists?("HbIconItem",{:iconName => 'images/bell.PNG'})) then
  1036 	#Step 2:Create another event overlapping the first event in Calendar.
   851 		#	raise VerificationError ,"ERROR: There is not reminder icon in calendar widget, when it should be there", caller
  1037 	another_time_for_verification = create_calendar_event_via_calendar("Another not working",@day.to_i,@month.to_i,@year.to_i,@hour.to_i+2,@minute.to_i,0,0,0)
   852 		#end
  1038 	#Step 3:Return to Home Screen and check Calendar widget.
   853 		
  1039 	#Step 3 Expected: - All icons (widget icon and reminder icon) are shown correctly.
   854 		#Step 2:Create another event overlapping the first event in Calendar.
  1040 	#- Calendar widget shows the overlapping information as two rows: first row shows overlapping time and second row shows  text 
   855 		another_time_for_verification = create_calendar_event(app, 'Another today meeting',@day.to_i,@month.to_i,@year.to_i,@hour.to_i+3,@minute.to_i+15,0,1,0)
  1041 	#'2 events overlapping'.
   856 		#Step 3:Return to Home Screen and check Calendar widget.
  1042 	if @hourformat_12 == true then
   857 		#Step 3 Expected: - All icons (widget icon and reminder icon) are shown correctly.
  1043 		overlapping_time_for_verification = today_time_for_verification[0..7]+'-'+another_time_for_verification[9..16]
   858 		#- Calendar widget shows the overlapping information as two rows: first row shows overlapping time and second row shows  text 
  1044 	else
   859 		#'2 events overlapping'.
  1045 		overlapping_time_for_verification = today_time_for_verification[0..4]+'-'+another_time_for_verification[6..10]
   860 		if @hourformat_12 == true then
  1046 	end
   861 			overlapping_time_for_verification = today_time_for_verification[0..7]+'-'+another_time_for_verification[9..16]
  1047 	puts "overlapping_time_for_verification: ",overlapping_time_for_verification
   862 		else
  1048 	verify(){app.HbLabel( :name => 'upperLabel' ).HbTextItem( :text => overlapping_time_for_verification )}
   863 			overlapping_time_for_verification = today_time_for_verification[0..4]+'-'+another_time_for_verification[6..10]
  1049 	verify(){app.HbLabel( :name => 'lowerLabel' ).HbTextItem( :text => '2 overlapping entry' )}
   864 		end
  1050 	#Step 4: Tap the overlapping events part in calendar view
   865 		puts "overlapping_time_for_verification: ",overlapping_time_for_verification
  1051 	app.HbLabel( :name => 'lowerLabel' ).HbTextItem( :text => '2 overlapping entry' ).tap
   866 		verify(){app.HbLabel( :name => 'upperLabel' ).HbTextItem( :text => overlapping_time_for_verification )}
  1052 	#Step 4 Expected: - Phone goes to calendar agenda view with all events visible.
   867 		verify(){app.HbLabel( :name => 'lowerLabel' ).HbTextItem( :text => '2 events overlapping' )}
  1053 	#ToDo 
   868 		#Step 4: Tap the overlapping events part in calendar view
  1054 	# !! NOT WORKING IN week 30 SW !!
   869 		app.HbLabel( :name => 'lowerLabel' ).HbTextItem( :text => '2 events overlapping' ).tap
  1055 	# - The date is same as the event date.
   870 		#Step 4 Expected: - Phone goes to calendar agenda view with  all events visible.
  1056 	#ToDo
   871 		#ToDo
  1057 	delete_calendar_events_via_UI
   872 		# - The date is same as the event date.
  1058   end
   873 		#ToDo
  1059   
   874 		remove_calendar_widget_from_homescreen(0)
  1060   def test_calendar_widget_overlapping_events_fixed
   875 		delete_calendar_events(app)
  1061 	#Preconditions:
   876 	rescue
  1062 	#Device is in Homescreen
   877 		if (running_round < max_running_rounds) then
  1063 	app = @sut.application(:name => 'hsapplication')
   878            running_round = running_round + 1
  1064 	verify(){app.HbIconItem(:iconName => 'qtg_mono_applications_all')}
   879            puts "Some error came during run. Lets try again"
  1065 	#- One event happens few hours after current phone time at today in Calendar.
   880            teardown
  1066 	check_phone_date
   881 	       retry
  1067 	check_phone_time
   882         else
  1068 	today_time_for_verification = create_calendar_event_via_calendar("not working",@day.to_i,@month.to_i,@year.to_i,@hour.to_i+2,@minute.to_i,0,0,0)
   883            puts "Test failed"
  1069 	#-Calendar widget is added to Home Screen.
   884            raise
  1070 	#Not adding calendar widget, if it already exists there
   885         end
  1071 	if not(app.test_object_exists?("HbWidget",{:name => 'CalendarWidget'})) then
   886 	end #rescue	
  1072 		#add calendar widget to home screen
   887   end
  1073 		app.HbIconItem(:iconName => 'qtg_mono_applications_all').tap
       
  1074 		add_calendar_widget_to_homescreen(app,'AppListButton')
       
  1075 	end
       
  1076 	#Step 1:Check Calendar widget.
       
  1077 	#step 1 Expected: - All icons (widget icon and reminder icon) are shown correctly.
       
  1078 	#- Calendar widget shows the event as two rows: first row show the event time and second row shows the event title.
       
  1079 	day_to_verify = @day.to_i
       
  1080 	verify(){app.HbTextItem(:text => day_to_verify)}
       
  1081 	#Verify, that reminder icon in widget is shown
       
  1082 	if not(app.test_object_exists?("HbFrameItem",{:frameGraphicsName => 'qtg_small_reminder'})) then
       
  1083 		raise VerificationError ,"ERROR: There is not reminder icon in calendar widget, when it should be there", caller
       
  1084 	end
       
  1085 	
       
  1086 	#Step 2:Create another event overlapping the first event in Calendar.
       
  1087 	another_time_for_verification = create_calendar_event_via_calendar("Another not working",@day.to_i,@month.to_i,@year.to_i,@hour.to_i+2,@minute.to_i,0,0,0)
       
  1088 	#Step 3:Return to Home Screen and check Calendar widget.
       
  1089 	#Step 3 Expected: - All icons (widget icon and reminder icon) are shown correctly.
       
  1090 	#- Calendar widget shows the overlapping information as two rows: first row shows overlapping time and second row shows  text 
       
  1091 	#'2 events overlapping'.
       
  1092 	if @hourformat_12 == true then
       
  1093 		overlapping_time_for_verification = today_time_for_verification[0..7]+'-'+another_time_for_verification[9..16]
       
  1094 	else
       
  1095 		overlapping_time_for_verification = today_time_for_verification[0..4]+'-'+another_time_for_verification[6..10]
       
  1096 	end
       
  1097 	puts "overlapping_time_for_verification: ",overlapping_time_for_verification
       
  1098 	verify(){app.HbLabel( :name => 'lowerLabel' ).HbTextItem( :text => '2 overlapping entry' )}
       
  1099 	delete_calendar_events_via_UI
       
  1100   end #test_calendar_widget_overlapping_events_fixed
   888   
  1101   
   889   ##############################################################################################################################################
  1102   ##############################################################################################################################################
   890   # Calendar widget - Tapping upcoming event
  1103   # Calendar widget - Tapping upcoming event
   891   ##############################################################################################################################################
  1104   ##############################################################################################################################################
   892   #
  1105   #
   937 		#preconditions:
  1150 		#preconditions:
   938 		#-Device is in Home Screen
  1151 		#-Device is in Home Screen
   939 		app = @sut.application(:name => 'hsapplication')
  1152 		app = @sut.application(:name => 'hsapplication')
   940 		#verify(){@sut.application(:name => 'hsapplication').HbIconItem(:iconName => 'qtg_mono_applications_all')}
  1153 		#verify(){@sut.application(:name => 'hsapplication').HbIconItem(:iconName => 'qtg_mono_applications_all')}
   941 		verify(){app.HbIconItem(:iconName => 'qtg_mono_applications_all')}
  1154 		verify(){app.HbIconItem(:iconName => 'qtg_mono_applications_all')}
   942 		navigate_to_first_homescreen
  1155 		#navigate_to_first_homescreen
   943 		#-Calendar widget is added to Home Screen.
  1156 		#-Calendar widget is added to Home Screen.
   944 		#Not adding calendar widget, if it already exists there
  1157 		#Not adding calendar widget, if it already exists there
   945 		if not(app.test_object_exists?("HbWidget",{:name => 'CalendarWidget'})) then
  1158 		if not(app.test_object_exists?("HbWidget",{:name => 'CalendarWidget'})) then
   946 			#add calendar widget to home screen
  1159 			#add calendar widget to home screen
   947 			app.HbIconItem(:iconName => 'qtg_mono_applications_all').tap
  1160 			app.HbIconItem(:iconName => 'qtg_mono_applications_all').tap
   968 		end
  1181 		end
   969 		day_to_verify = @day.to_i
  1182 		day_to_verify = @day.to_i
   970 		verify(){app.HbTextItem(:text => day_to_verify)}
  1183 		verify(){app.HbTextItem(:text => day_to_verify)}
   971 		verify(){app.HbTextItem(:text => month_in_view)}
  1184 		verify(){app.HbTextItem(:text => month_in_view)}
   972 		#Calendar widget content contains "No event for next 7 days"
  1185 		#Calendar widget content contains "No event for next 7 days"
   973 		verify(){app.HbTextItem(:text => 'No calendar entries today or next 7 days')}
  1186 		verify(){app.HbTextItem(:text => 'No entries for 7 days')}
   974 	
  1187 	
   975 		#Verify, that reminder icon in widget is not shown
  1188 		#Verify, that reminder icon in widget is not shown
   976 		if (app.test_object_exists?("HbIconItem",{:iconName => 'images/bell.PNG'})) then
  1189 		if (app.test_object_exists?("HbIconItem",{:iconName => 'images/bell.PNG'})) then
   977 			raise VerificationError ,"ERROR: There is reminder icon in calendar widget, when it should not be there", caller
  1190 			raise VerificationError ,"ERROR: There is reminder icon in calendar widget, when it should not be there", caller
   978 		end
  1191 		end