logsui/tsrc/MATTItests/CommonFunctions.rb
changeset 0 4a5361db8937
equal deleted inserted replaced
-1:000000000000 0:4a5361db8937
       
     1 require 'matti'
       
     2 
       
     3 ### Constants
       
     4 
       
     5 VoiceIcon_Const = ':/callVoice.svg'
       
     6 VideoIcon_Const = ':/callVideo.svg'
       
     7 DirInIcon_Const = ':/dirIn.svg'
       
     8 DirOutIcon_Const = ':/dirOut.svg'
       
     9 DirMissedIcon_Const = ':/dirMissed.svg'
       
    10 DataAndTimeIcon_Const = ':/callDateAndTime.svg'
       
    11 RemoteInfoIcon_Const = ':/remoteInfo.svg'
       
    12 CallDurationIcon_Const = ':/callDuration.svg'
       
    13 
       
    14 
       
    15 ## Parent class for all TC_ classes. Contains common functionality related to intializing and running the cases,
       
    16 ## and other functionality that can be re-used by different tests  
       
    17 class CommonFunctions
       
    18  # Run when the class is intialized. Takes logging file and MATTI sut in.
       
    19  def initialize(log, my_sut)
       
    20   	@log = log
       
    21   	@my_sut = my_sut
       
    22   end
       
    23 	
       
    24 	# Running test case logic. The case name is taken in from the test list file and then a function that has the
       
    25 	# same name is called. 
       
    26 	def run(testName)
       
    27 		begin
       
    28 			result = send(testName)
       
    29 		rescue Exception => e
       
    30 	 		@log.fatal("Error, case execution terminated.")
       
    31 	 		@log.fatal("Error code: #{e.message}")
       
    32 	 		@log.fatal("Error line: #{e.backtrace.inspect}")
       
    33 	 		if(@my_sut.application.attribute("FullName") == 'Z:\sys\bin\logs.exe')
       
    34 	 			@appControl.closeApplication()
       
    35 	 		end
       
    36 	 		result = -2
       
    37 		end
       
    38 		return result
       
    39 	end
       
    40 	
       
    41 	# Initializes the test by generating the log events
       
    42 	def initializeTest(caseName)
       
    43 		@appControl = ApplicationControl.new(@log, @my_sut)
       
    44 		@appControl.clearList()
       
    45 		@appControl.addEvents(caseName)
       
    46 		@my_app = @appControl.startApplication()
       
    47 		sleep 3
       
    48 		# Note! Use only these in the test cases so that maintenance is easier. 
       
    49 		@mainWindow = @my_app.LogsMainWindow
       
    50 		@recentCallsView = @mainWindow.HbContentWidget.LogsRecentCallsView.HbWidget
       
    51 		@eventContainer = @recentCallsView.HbListView.HbAbstractItemContainer		
       
    52 	end
       
    53 	
       
    54 	# Initializes the test by generating the log events and starting application by pressing send Key
       
    55 	def initializeTestSendKey(caseName)
       
    56 		@appControl = ApplicationControl.new(@log, @my_sut)
       
    57 		@appControl.clearList()
       
    58 		@appControl.addEvents(caseName)
       
    59 		@appControl.pressSendKey
       
    60 	
       
    61 		sleep 4
       
    62 		puts @my_sut.application.attribute("FullName") 
       
    63 		@mainWindow = @my_app.LogsMainWindow
       
    64 		@recentCallsView = @mainWindow.HbContentWidget.LogsRecentCallsView.HbWidget
       
    65 		@eventContainer = @recentCallsView.HbListView.HbAbstractItemContainer
       
    66 		
       
    67 	end
       
    68 	
       
    69 	
       
    70 	# Selects a wanted view. First it verifies the current view and then the next view is selected.
       
    71 	def selectView(currentView, nextView)
       
    72 		@log.debug("Tapping on Show button")
       
    73 		showButton = @mainWindow.HbToolBar(:name=>'logs_toolbar').HbToolButton(:toolTipText=>'Show')
       
    74 		showButton.tap
       
    75 		sleep 1
       
    76 		sort_menu = @mainWindow.HbMenu.HbMenuListView.HbAbstractItemContainer
       
    77 		@log.debug("Verifying the current view in sort menu. Menu should be: #{currentView}")
       
    78 		
       
    79 		if(currentView == "Recent")	
       
    80 			sort_menu.HbMenuItem(:row=>'0').HbTextItem(:text=>'Recent calls')
       
    81 			sort_menu.HbMenuItem(:row=>'0').HbIconItem(:iconName => 'qtg_indi_list_selected')
       
    82 		elsif(currentView == "Dialled")
       
    83 			sort_menu.HbMenuItem(:row=>'2').HbTextItem(:text=>'Dialled calls')
       
    84 			sort_menu.HbMenuItem(:row=>'2').HbIconItem(:iconName => 'qtg_indi_list_selected')
       
    85 		elsif(currentView == "Received")
       
    86 			sort_menu.HbMenuItem(:row=>'1').HbTextItem(:text=>'Received calls')
       
    87 			sort_menu.HbMenuItem(:row=>'1').HbIconItem(:iconName => 'qtg_indi_list_selected')
       
    88 		elsif(currentView == "Missed")
       
    89 			sort_menu.HbMenuItem(:row=>'3').HbTextItem(:text=>'Missed calls')
       
    90 			sort_menu.HbMenuItem(:row=>'3').HbIconItem(:iconName => 'qtg_indi_list_selected')
       
    91 		end
       
    92 		@log.debug("Selecting the next view in sort menu. Selection: #{nextView}")
       
    93 		
       
    94 		if(nextView == "Recent")	
       
    95 			sort_menu.HbMenuItem(:row=>'0').tap
       
    96 			@currentView = "Recent"
       
    97 		elsif(nextView == "Dialled")
       
    98 			sort_menu.HbMenuItem(:row=>'2').tap
       
    99 			@currentView = "Dialled"
       
   100 		elsif(nextView == "Received")
       
   101 			sort_menu.HbMenuItem(:row=>'1').tap
       
   102 			@currentView = "Received"
       
   103 		elsif(nextView == "Missed")
       
   104 			sort_menu.HbMenuItem(:row=>'3').tap
       
   105 			@currentView = "Missed"
       
   106 		end
       
   107 	end
       
   108 	
       
   109 	# Intiates a call to the event that is in specified row passed in as a parameter. 
       
   110 	# Verifies the call is made to correct number
       
   111 	def initiate_call(row, phoneNumber)
       
   112 		@log.debug("Initiating call. Row: #{row} Phone number: #{phoneNumber}")
       
   113 		firstDialledEvent = @eventContainer.HbListViewItem(:row=>"#{row}").HbTextItem(:text=>"#{phoneNumber}")
       
   114 		firstDialledEvent.tap
       
   115 		sleep 2
       
   116 		# Verify that the Telephone is calling to the correct number!! Currently no environment for that!!!!
       
   117 		puts @serviceApp.attribute("FullName")
       
   118 		return 0
       
   119   	
       
   120   end
       
   121   
       
   122   # Intiates a call to the first event in the current view by pressing Send key
       
   123 	# Verifies the call is made to correct number
       
   124   def initiate_call_with_send_key
       
   125 		@log.debug("Initiating call by pressing Send key")
       
   126 		#recentCallsView = @my_app.HbMainWindow.HbContentWidget.LogsRecentCallsView.HbWidget
       
   127 		firstEvent = @eventContainer.HbAbstractViewItem(:row=>"0")#.HbTextItem(:text=>"#{phoneNumber}")
       
   128 		@appControl.pressSendKey()
       
   129 		# Verify that the Telephone is calling to the correct number!! Currently no environment for that!!!!
       
   130 		return 0
       
   131   end	
       
   132   
       
   133   ## Common functionality for testing the that the last call is dislplayed correctly in
       
   134   ## selected view.
       
   135   ## Check the Call type (voice / video) and call direction
       
   136   def last_call(caseName, phoneNumber, direction, type)
       
   137   	initializeTest(caseName)
       
   138   	@log.debug('Verifying the first recent calls item.')
       
   139 		verify_event(0, phoneNumber, direction, type)
       
   140 		@log.debug('Changing the view from Recent to Dialled and verifying the event')
       
   141 		if(direction == DirMissedIcon_Const)
       
   142 			selectView("Recent", "Missed")
       
   143 		elsif(direction == DirOutIcon_Const)
       
   144 			selectView("Recent", "Dialled")
       
   145 		else
       
   146 			selectView("Recent", "Received")
       
   147 		end
       
   148 		verify_event(0, phoneNumber, direction, type)
       
   149 		@log.debug('Add one event')
       
   150 		@appControl.addEvents(caseName + "b")
       
   151 		verify_event(0, phoneNumber + '1', direction, type)
       
   152 		verify_event(1, phoneNumber, direction, type)
       
   153 		result = 0
       
   154   	@appControl.closeApplication()
       
   155     return result
       
   156    end
       
   157   
       
   158   ## Function for verifying that the event is correct in the selected row.
       
   159   ## Check the Call type (voice / video), call direction and phone number
       
   160   def verify_event(row, contact, direction, type)
       
   161   	puts "Verifying that row: #{row} has a contact/phone number: #{contact}"
       
   162 		@log.debug("Verifying that row: #{row} contact/phone number: #{contact}")
       
   163   	@eventContainer.HbListViewItem(:row=>"#{row}").HbTextItem(:text=>"#{contact}")
       
   164   	@log.debug("Verifying the call type: #{type} by checking the icon")
       
   165   	@eventContainer.HbListViewItem(:row=>"#{row}").HbIconItem(:iconName=>"#{type}")
       
   166   	@log.debug("Verifying the call direction: #{direction} by checking the icon")
       
   167   	## CHANGE THIS BACK, CURRENTLY 2 ICONS
       
   168   	#@recentCallsView.HbAbstractItemContainer.HbAbstractViewItem(:row=>"#{row}").HbIconItem(:iconName=>"#{direction}")
       
   169   end 
       
   170   
       
   171 	
       
   172 end