0001 # testExplorer - 0002 0003 import string 0004 import sys 0005 import os 0006 import win32com.client.dynamic 0007 import win32api 0008 import glob 0009 import pythoncom 0010 import time 0011 from util import CheckClean 0012 0013 bVisibleEventFired = 0 0014 0015 class ExplorerEvents: 0016 def OnVisible(self, visible): 0017 global bVisibleEventFired 0018 bVisibleEventFired = 1 0019 0020 def TestExplorerEvents(): 0021 global bVisibleEventFired 0022 iexplore = win32com.client.DispatchWithEvents("InternetExplorer.Application", ExplorerEvents) 0023 iexplore.Visible = 1 0024 if not bVisibleEventFired: 0025 raise RuntimeError, "The IE event did not appear to fire!" 0026 iexplore.Quit() 0027 iexplore = None 0028 0029 bVisibleEventFired = 0 0030 ie = win32com.client.Dispatch("InternetExplorer.Application") 0031 ie_events = win32com.client.DispatchWithEvents(ie, ExplorerEvents) 0032 ie.Visible = 1 0033 if not bVisibleEventFired: 0034 raise RuntimeError, "The IE event did not appear to fire!" 0035 ie.Quit() 0036 ie = None 0037 print "IE Event tests worked." 0038 0039 0040 def TestExplorer(iexplore): 0041 if not iexplore.Visible: iexplore.Visible = -1 0042 try: 0043 iexplore.Navigate(win32api.GetFullPathName('..\\readme.htm')) 0044 except pythoncom.com_error, details: 0045 print "Warning - could not open the test HTML file", details 0046 # for fname in glob.glob("..\\html\\*.html"): 0047 # print "Navigating to", fname 0048 # while iexplore.Busy: 0049 # win32api.Sleep(100) 0050 # iexplore.Navigate(win32api.GetFullPathName(fname)) 0051 win32api.Sleep(4000) 0052 iexplore.Quit() 0053 0054 def TestAll(): 0055 try: 0056 iexplore = win32com.client.dynamic.Dispatch("InternetExplorer.Application") 0057 TestExplorer(iexplore) 0058 0059 win32api.Sleep(1000) 0060 iexplore = None 0061 0062 # Test IE events. 0063 TestExplorerEvents() 0064 # Give IE a chance to shutdown, else it can get upset on fast machines. 0065 time.sleep(2) 0066 0067 # Note that the TextExplorerEvents will force makepy - hence 0068 # this gencache is really no longer needed. 0069 0070 from win32com.client import gencache 0071 gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1) 0072 iexplore = win32com.client.Dispatch("InternetExplorer.Application") 0073 TestExplorer(iexplore) 0074 0075 finally: 0076 iexplore = None 0077 0078 if __name__=='__main__': 0079 TestAll() 0080 CheckClean() 0081
Generated by PyXR 0.9.4