def instantiateWebdriver(self, base_url): os.environ['DISPLAY'] = ":99" profile = webdriver.FirefoxProfile() profile.set_preference("browser.privatebrowsing.autostart", True) profile.set_preference("network.http.phishy-userpass-length", 255) profile.set_preference("network.automatic-ntlm-auth.trusted-uris", "x.x.x.x") profile.set_preference('browser.cache.disk.enable', False) profile.set_preference('browser.cache.memory.enable', False) profile.set_preference('browser.cache.offline.enable', False) profile.set_preference("network.http.use-cache", False) profile.accept_untrusted_certs = True driver = None if base_url is None: base_url = self.getBaseUrl() def restartXvfb(): selenium_process_list = Machine.getProcessList(filter='selenium-server') selenium_pids = [int(p.split()[1]) for p in selenium_process_list] for pid in selenium_pids: Machine.killProcessRemote(pid, host=None, user=Machine.getAdminUser(), passwd=None, logoutput=True) xvfb_pid = [int(p.split()[1]) for p in Machine.getProcessList(filter='Xvfb')] for pid in xvfb_pid: Machine.killProcessRemote(pid, host=None, user=Machine.getAdminUser(), passwd=None, logoutput=True) Machine.rm(Machine.getAdminUser(), None, "/tmp/.X99-lock", isdir=False, passwd=None) Machine.runinbackgroundAs(Machine.getAdminUser(), cmd="Xvfb :99 -ac -screen 0 1280x1024x24", host=None) time.sleep(10) num_attempts = 0 max_attempts = 5 while num_attempts < max_attempts: try: os.environ["http_proxy"] = '' #firefox_binary = '/base/tools/firefox-45.0/firefox' #driver = Selenium.getWebDriver( # browserType='firefox', platformType='LINUX', browser_profile=profile, firefox_binary=firefox_binary) driver = Selenium.getWebDriver(browserType='firefox', platformType='LINUX', browser_profile=profile) # Adding an implicit wait so that the tests wait for some # time (30- seconds) before finding elements on web page # JIRA: https://hortonworks.jira.com/browse/QE-15773 driver.implicitly_wait(30) Selenium.setWebDriverWinSize(driver, 1920, 1080) driver.get(base_url) break except Exception, e: logger.error("Exception is: %s" % e) if num_attempts < max_attempts - 1: restartXvfb() pass else: logger.error("attempt : %s , Failed to get webdriver for Dataplane : %s" % (num_attempts, e)) num_attempts = num_attempts + 1
def instantiateWebdriver(self): os.environ['DISPLAY'] = ":99" Machine.runas(Machine.getAdminUser(), "dbus-uuidgen --ensure") profile = webdriver.FirefoxProfile() profile.set_preference("browser.privatebrowsing.autostart", True) profile.set_preference("network.http.phishy-userpass-length", 255) profile.set_preference("network.automatic-ntlm-auth.trusted-uris", "x.x.x.x") profile.accept_untrusted_certs = True driver = None profile.set_preference("browser.download.manager.showWhenStarting", False) profile.set_preference("browser.download.dir", "/tmp") profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/zip,application/octet-stream") profile.set_preference("browser.helperApps.alwaysAsk.force", False) # QE-4343 profile.set_preference("dom.max_script_run_time", 0) from beaver.component.hadoop import Hadoop if Hadoop.isUIKerberozied() and Machine.isHumboldt(): profile.set_preference("network.negotiate-auth.delegation-uris", ".hdinsight.net") profile.set_preference("network.negotiate-auth.trusted-uris", ".hdinsight.net") def restartXvfb(): selenium_process_list = Machine.getProcessList(filter='selenium-server') selenium_pids = [int(p.split()[1]) for p in selenium_process_list] selenium_cmds = [' '.join(p.split()[3:]) for p in selenium_process_list] selenium_hub_cmd = None selenium_wd_cmd = None for cmd in selenium_cmds: if "role hub" in cmd: selenium_hub_cmd = cmd + " > /tmp/selenium-hub.log 2>&1 &" if "role webdriver" in cmd: selenium_wd_cmd = cmd + " > /tmp/selenium-node.log 2>&1 &" assert selenium_hub_cmd and selenium_wd_cmd, "Failed to find selenium-server processes and restart them" for pid in selenium_pids: Machine.killProcessRemote(pid, host=None, user=Machine.getAdminUser(), passwd=None, logoutput=True) xvfb_pid = [int(p.split()[1]) for p in Machine.getProcessList(filter='Xvfb')] for pid in xvfb_pid: Machine.killProcessRemote(pid, host=None, user=Machine.getAdminUser(), passwd=None, logoutput=True) Machine.rm(Machine.getAdminUser(), None, "/tmp/.X99-lock", isdir=False, passwd=None) Machine.runas(Machine.getAdminUser(), selenium_hub_cmd, host=None) Machine.runas(Machine.getAdminUser(), selenium_wd_cmd, host=None) Machine.runinbackgroundAs(Machine.getAdminUser(), cmd="Xvfb :99 -ac -screen 0 1280x1024x24", host=None) time.sleep(10) num_attempts = 0 max_attempts = 5 while num_attempts < max_attempts: try: driver = Selenium.getWebDriver(browserType='firefox', platformType='LINUX', browser_profile=profile) Selenium.setWebDriverWinSize(driver, 1920, 1080) from beaver.component.hadoop import Hadoop if Hadoop.isUIKerberozied() and Machine.isHumboldt(): keytabFile = Machine.getHeadlessUserKeytab("hrt_qa") kinitCmd = '%s -R -kt %s %s' % ( Machine.getKinitCmd(), keytabFile, Machine.get_user_principal("hrt_qa") ) exitCode, stdout = Machine.runas("hrt_qa", kinitCmd) assert exitCode == 0 driver.get(self.getBaseUrl()) break except Exception, e: if num_attempts < max_attempts - 1: restartXvfb() pass else: logger.error("attempt : %s , Failed to get webdriver for Dataplane : %s" % (num_attempts, e)) num_attempts = num_attempts + 1
def instantiateWebdriver(self): os.environ['DISPLAY'] = ":99" Machine.runas(Machine.getAdminUser(), "dbus-uuidgen --ensure") profile = webdriver.FirefoxProfile() profile.set_preference("browser.privatebrowsing.autostart", True) profile.set_preference("network.http.phishy-userpass-length", 255) profile.set_preference("network.automatic-ntlm-auth.trusted-uris", "x.x.x.x") profile.accept_untrusted_certs = True driver = None profile.set_preference("browser.download.manager.showWhenStarting", False) profile.set_preference("browser.download.dir", "/tmp") profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/zip,application/octet-stream") profile.set_preference("browser.helperApps.alwaysAsk.force", False) # QE-4343 profile.set_preference("dom.max_script_run_time", 0) from beaver.component.hadoop import Hadoop if Hadoop.isUIKerberozied() and self.proxy == 'false': domainName = ".hwx.site" if Machine.isIBMPowerPC(): domainName = ".openstacklocal" profile.set_preference("network.negotiate-auth.delegation-uris", domainName) profile.set_preference("network.negotiate-auth.trusted-uris", domainName) def restartXvfb(): selenium_process_list = Machine.getProcessList(filter='selenium-server') selenium_pids = [int(p.split()[1]) for p in selenium_process_list] selenium_cmds = [' '.join(p.split()[3:]) for p in selenium_process_list] selenium_hub_cmd = None selenium_wd_cmd = None for cmd in selenium_cmds: if "role hub" in cmd: selenium_hub_cmd = cmd + " > /tmp/selenium-hub.log 2>&1 &" if "role webdriver" in cmd: selenium_wd_cmd = cmd + " > /tmp/selenium-node.log 2>&1 &" assert selenium_hub_cmd and selenium_wd_cmd, "Failed to find selenium-server processes and restart them" for pid in selenium_pids: Machine.killProcessRemote(pid, host=None, user=Machine.getAdminUser(), passwd=None, logoutput=True) xvfb_pid = [int(p.split()[1]) for p in Machine.getProcessList(filter='Xvfb')] for pid in xvfb_pid: Machine.killProcessRemote(pid, host=None, user=Machine.getAdminUser(), passwd=None, logoutput=True) Machine.rm(Machine.getAdminUser(), None, "/tmp/.X99-lock", isdir=False, passwd=None) Machine.runas(Machine.getAdminUser(), selenium_hub_cmd, host=None) Machine.runas(Machine.getAdminUser(), selenium_wd_cmd, host=None) Machine.runinbackgroundAs(Machine.getAdminUser(), cmd="Xvfb :99 -ac -screen 0 1280x1024x24", host=None) time.sleep(10) num_attempts = 0 max_attempts = 5 while num_attempts < max_attempts: try: os.environ["http_proxy"] = '' #firefox_binary = FirefoxBinary('/base/tools/firefox-45.0/firefox') #driver = Selenium.getWebDriver(browserType='firefox', platformType='LINUX', browser_profile=profile, firefox_binary= firefox_binary) driver = Selenium.getWebDriver(browserType='firefox', platformType='LINUX', browser_profile=profile) # Adding an implicit wait so that the tests wait for some # time (30- seconds) before finding elements on web page # JIRA: https://hortonworks.jira.com/browse/QE-15773 driver.implicitly_wait(30) Selenium.setWebDriverWinSize(driver, 1920, 1080) driver.get(self.getBaseUrl()) break except Exception, e: logger.error("Exception is: %s" % e) if num_attempts < max_attempts - 1: restartXvfb() pass else: logger.error("attempt : %s , Failed to get webdriver for Dataplane : %s" % (num_attempts, e)) num_attempts = num_attempts + 1