2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Automates IE to visit a list of web sites while running CF in full tab mode.
8 The page cycler automates IE and navigates it to a series of URLs. It is
9 designed to be run with Chrome Frame configured to load every URL inside
12 TODO(robertshield): Make use of the python unittest module as per
19 import win32com.client
22 def LoadSiteList(path):
23 """Loads a list of URLs from |path|.
25 Expects the URLs to be separated by newlines, with no leading or trailing
29 path: The path to a file containing a list of new-line separated URLs.
32 A list of strings, each one a URL.
40 """Starts up IE, makes it visible and returns the automation object.
43 The IE automation object.
45 ie = win32com.client.Dispatch("InternetExplorer.Application")
47 win32gui.SetForegroundWindow(ie.HWND)
51 """Loads |url| into the InternetExplorer.Application instance in |ie|.
53 Waits for the Document object to be created and then waits for
54 the document ready state to reach READYSTATE_COMPLETE.
56 url: A string containing the url to navigate to.
57 ie: The IE automation object to navigate.
60 print "Navigating to " + url
64 READYSTATE_COMPLETE = 4
67 for retry in xrange(60):
69 # TODO(robertshield): Become an event sink instead of polling for
70 # changes to the ready state.
71 last_ready_state = ie.Document.ReadyState
72 if last_ready_state == READYSTATE_COMPLETE:
75 # TODO(robertshield): Find the precise exception related to ie.Document
76 # being not accessible and handle it here.
77 print "Unexpected error:", sys.exc_info()[0]
81 if last_ready_state != READYSTATE_COMPLETE:
82 print "Timeout waiting for " + url
85 parser = optparse.OptionParser()
86 parser.add_option('-u', '--url_list', default='urllist',
87 help='The path to the list of URLs')
88 (opts, args) = parser.parse_args()
90 urls = LoadSiteList(opts.url_list)
99 if __name__ == '__main__':