def get_multitab(self):
"""Open two tab, use one to load a background site and the other to
load the real site."""
PAUSE_BETWEEN_TAB_OPENINGS = 0.5
ut.timeout(cm.HARD_VISIT_TIMEOUT) # set timeout to kill running procs
# load a blank page - a page is needed to send keys to the browser
self.tb_driver.get(BAREBONE_HOME_PAGE)
self.sniffer.start_capture(self.pcap_path,
'tcp and not host %s and not host %s'
% (VBOX_GATEWAY_IP, LOCALHOST_IP))
time.sleep(cm.PAUSE_BETWEEN_INSTANCES)
try:
self.tb_driver.set_page_load_timeout(cm.SOFT_VISIT_TIMEOUT)
except:
wl_log.info("Exception setting a timeout {}".format(self.page_url))
wl_log.info("Crawling URL: {} with {} in the background".
format(self.page_url, self.bg_site))
body = self.tb_driver.find_element_by_tag_name("body")
body.send_keys(Keys.CONTROL + 't') # open a new tab
# now that the focus is on the address bar, load the background
# site by "typing" it to the address bar and "pressing" ENTER (\n)
# simulated by send_keys function
body.send_keys('%s\n' % self.bg_site)
# the delay between the loading of background and real sites
time.sleep(PAUSE_BETWEEN_TAB_OPENINGS)
body = self.tb_driver.find_element_by_tag_name("body")
body.send_keys(Keys.CONTROL + 't') # open a new tab
t1 = time.time()
self.tb_driver.get(self.page_url) # load the real site in the 2nd tab
page_load_time = time.time() - t1
wl_log.info("{} loaded in {} sec"
.format(self.page_url, page_load_time))
time.sleep(cm.WAIT_IN_SITE)
if self.capture_screen:
self.take_screenshot()
self.cleanup_visit()
评论列表
文章目录