Пример #1
0
	def __init__(self, config=None):
		'''
		Initiator. 
		'''
		self.ldtphandler = LDTPHandler()
		self._handleTeamViewerDialog()
		self.config = config
Пример #2
0
class WinFileUploader(threading.Thread):
	def __init__(self, file_path):
		threading.Thread.__init__(self)
		self.file_path =  file_path
		self.ldtphandler = LDTPHandler()
		# logger.debug(self.file_path)
		
	def run(self):
		# logger.debug("winFileUploader: Begins1")
		if platform.system() == "Windows":
			import pywinauto
			logger.debug("Native Windows : Import PyWinAuto")
			# logger.debug("winFileUploader: Begins2")
			pwa_app = pywinauto.application.Application()
			for i in range(1,50):
				logger.debug("Finding. iteration: %d" % (i + 1))
				w_handle = None
				try:
					logger.debug("Native Windows : Title = 'Open'")
					w_handle = pywinauto.findwindows.find_windows(title=u'Open', class_name='#32770')[0]
					break
				except:
					try:
						logger.debug("Native Windows : Title = 'File Upload'")
						w_handle = pywinauto.findwindows.find_windows(title=u'File Upload', class_name='#32770')[0]
						break
					except:
						try:
							logger.debug("Native Windows : Title = 'ChooseFile to Uploads'")
							w_handle = pywinauto.findwindows.find_windows(title=u'Choose File to Upload', class_name='#32770')[0]
							break
						except:
							try:
								logger.debug("Native Windows : Title = 'Select Files to upload'")
								w_handle = pywinauto.findwindows.find_windows(title_re=u'Select\s+file\(s\)\s+to\s+upload by', class_name='#32770')[0]
								break
							except:
								logger.debug("Not found in this cycle")
								time.sleep(1)

			logger.debug("w_handle is %s" % w_handle)
			if w_handle is None:
				logger.debug("WinFileUploader: Windows handle is None")
				from nsUI.actions import get_browser
				browser = get_browser()
				logger.debug("WinFileUploader: Killing the browser")
				browser.quit()
				raise Exception("Upload Window was not found, so WinFileUploader closed the browser.")
			else:
				logger.debug("WinFileUploader: Clicking Edit")
				window = pwa_app.window_(handle=w_handle)
				window.SetFocus()
				ctrl = window['Edit']
				ctrl.Click()
				ctrl = window['Edit']
				logger.debug("WinFileUploader: Sending keys for file path")
				ctrl.TypeKeys(self.file_path)
				time.sleep(3)
				logger.debug("WinFileUploader: Clicking open button")
				ctrl = window['&Open']
				ctrl.SetFocus()
				ctrl.Click()
				logger.debug("WinFileUploader: all done.")
		else :
			import os
			import os.path
			path = os.path.abspath(os.path.join(os.path.dirname(__file__),"..","..","nsUI","util"))
			from nsUI.actions import get_browser
			browser = get_browser()
			windowTitle =  browser.title
			windowTitle = windowTitle.replace(" ","")
			print windowTitle
			browserName = browser.capabilities['browserName'].replace("u","").replace("'","")
			if browserName in "chrome":
				time.sleep(10)
				browserAppName = "Google Chrome"
				time.sleep(5)		
				appleScriptFileFullPath = path + "/macUploadChrome.scpt"
				print appleScriptFileFullPath
				cmd = "osascript %s" %appleScriptFileFullPath
				print os.system(cmd)
				time.sleep(5)
				self.ldtphandler.raw_ldtp.settextvalue("frm%s"%windowTitle, "txttextfield1",self.file_path )
				self.ldtphandler.click_element("Clicking on Go Button", "frm%s"%windowTitle, "btnGo")
				try:
					time.sleep(5)
					self.ldtphandler.click_element("Clicking on Open Button", "frm%s"%windowTitle, "btnOpen")
				except:
					import os.path
					try:
						self.ldtphandler.click_element("Clicking the File ","frm%s"%windowTitle , os.path.basename("img"+self.file_path.replace(".","")))
					except:
						self.ldtphandler.click_element("Clicking the File ","frm%s"%windowTitle , os.path.basename("lst"+self.file_path.replace(".","")))
					self.ldtphandler.click_element("Clicking on Open Button", "frm%s"%windowTitle, "btnOpen")
			elif browserName in 'firefox':
				browserAppName = "Firefox"
				for i in range(15):
					try :
						logger.debug("Finiding Upload Winodw %s" %i)
						self.ldtphandler.raw_ldtp.guiexist("frmFileUpload", "btnCancel")
						time.sleep(5)
						break
					except Exception,e :
						pass
				time.sleep(5)		
				appleScriptFileFullPath = path + "/macUpload.scpt"
				print appleScriptFileFullPath
				cmd = "osascript %s" %appleScriptFileFullPath
				print os.system(cmd)
				time.sleep(5)
				self.ldtphandler.raw_ldtp.settextvalue("frmFileUpload", "txttextfield",self.file_path )
				self.ldtphandler.click_element("Clicking on Go Button", "frmFileUpload", "btnGo")
				self.ldtphandler.click_element("Clicking on Open Button", "frmFileUpload", "btnOpen")
			elif browserName in 'safari':
				browserAppName = "safari"
				time.sleep(5)		
				appleScriptFileFullPath = path + "/macUploadSafari.scpt"
				cmd = "osascript %s" %appleScriptFileFullPath
				os.system(cmd)
				time.sleep(5)
				self.ldtphandler.raw_ldtp.settextvalue("frm%s"%windowTitle, "txttextfield1",self.file_path )
				self.ldtphandler.click_element("Clicking on Go Button", "frm%s"%windowTitle, "btnGo")
				self.ldtphandler.click_element("Clicking on btnChoose Button", "frm%s"%windowTitle, "btnChoose")
Пример #3
0
	def __init__(self, file_path):
		threading.Thread.__init__(self)
		self.file_path =  file_path
		self.ldtphandler = LDTPHandler()
Пример #4
0
class NSClient:
	''' 
	Base class for all NetSkope client actions
	'''
	def __init__(self, config=None):
		'''
		Initiator. 
		'''
		self.ldtphandler = LDTPHandler()
		self._handleTeamViewerDialog()
		self.config = config
		
	def _checkNetskopeInstalledOrNot(self):
		'''
		Checks the File is Exists in target Directory or not
		'''
		
		path = client.installedPath
		foldername = client.installedDirName
		if self.ldtphandler.os_family == "mac":
			path = path.replace("C:","").replace("\\","/")
		if not platform.machine().endswith("64"):
			path = path .replace(" (x86)","")
		list = os.listdir(path)
		return foldername in list	
		
	def _closeIndataWindow(self, build_path):
		windowName = self.ldtphandler.get_window_name_for_path(build_path)
		self.ldtphandler.close_window("Closing the In_data window ", windowName)
		try :
			self.ldtphandler.click_element("Closing the In_data window ", windowName, "btnclosebutton")
		except:
			pass

	def _moveLogFile(self,src_dir, dest_dir):
		print src_dir
		print dest_dir
		print "Move"
		try:
			if not os.path.exists(dest_dir): os.makedirs(dest_dir)
			fileList = os.listdir(src_dir)
			for i in fileList:
				src = os.path.join(src_dir, i)
				dest = os.path.join(dest_dir, i)
				if os.path.exists(dest):
					if os.path.isdir(dest):
						move_over(src, dest)
						continue
					else:
						os.remove(dest)
				shutil.move(src, dest_dir)
		except:
			pass
		
	def	_handleTeamViewerDialog(self):
		try :
			time.sleep(5)
			self.ldtphandler.gui_exists("Sponsored session")
			self.ldtphandler.click_element("Handling team viewer Dialog", "Sponsored session", "btnOK")
		except :
			logger.debug("No Team Viewer Dialog appeared")
	
	def enableNSClientFromSysTray(self):
		try:
			ldtp = self.ldtphandler.raw_ldtp
			winlist = ldtp.getwindowlist()
			dynamicWindowname = ""
			for window in winlist:
				try :
					if window.startswith("pane"):
						objlist = ldtp.getobjectlist(window)
						for object in objlist:
							if object in ["btnNotificationChevron"]:
								dynamicWindowname = window
								break
				except :
					pass
			ldtp.mouseleftclick(dynamicWindowname, "btnNotificationChevron")
			try :
				ldtp.mouserightclick("paneNotification Overflow", 'btnNetskopeClientdisabled')
				print ldtp.getobjectlist("mnuContext")
				ldtp.selectmenuitem("mnuContext", 'mnuEnableNetskopeClient')
				print "Enabled... "
			except :	
				# ldtp.mouseleftclick(dynamicWindowname, "btnNotificationChevron")
				# try :
					# ldtp.mouserightclick("paneNotification Overflow", 'btnNetskopeClientdisabled')
				# except :
					# ldtp.mouseleftclick(dynamicWindowname, "btnNotificationChevron")
					# ldtp.mouserightclick("paneNotification Overflow", 'btnNetskopeClientdisabled1')
				# ldtp.selectmenuitem("mnuContext", 'mnuEnableNetskopeClient')
				print "Already Enable"
		except Exception,e:
			print e
			pass