Exemplo n.º 1
0
 def setUpClass(cls):
     cls.failed_test = False
     # Django Test Setup
     if cls.config['load_init_data']:
         test_data_file = os.path.join(
             os.path.dirname(os.path.realpath(__file__)), 'data.py')
         entrypoint = "python manage.py shell --command='import data; data.setup()'"
         cmd = subprocess.Popen([
             'docker-compose', 'run', '--rm', '--entrypoint', entrypoint,
             '--volume', test_data_file + ':/opt/openwisp/data.py',
             'dashboard'
         ],
                                universal_newlines=True,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE,
                                cwd=cls.root_location)
         output, error = map(str, cmd.communicate())
         with open(cls.config['logs_file'], 'w') as logs_file:
             logs_file.write(output)
             logs_file.write(error)
         subprocess.run(['docker-compose', 'up', '--detach'],
                        stdout=subprocess.DEVNULL,
                        stderr=subprocess.DEVNULL,
                        cwd=cls.root_location)
     # Create base drivers (Firefox)
     if cls.config['driver'] == "firefox":
         profile = webdriver.FirefoxProfile()
         profile.accept_untrusted_certs = True
         options = webdriver.FirefoxOptions()
         capabilities = DesiredCapabilities.FIREFOX
         capabilities['loggingPrefs'] = {'browser': 'ALL'}
         if cls.config['headless']:
             options.add_argument('-headless')
         cls.base_driver = webdriver.Firefox(
             options=options,
             capabilities=capabilities,
             service_log_path='/tmp/geckodriver.log',
             firefox_profile=profile)
         cls.second_driver = webdriver.Firefox(
             options=options,
             capabilities=capabilities,
             service_log_path='/tmp/geckodriver.log',
             firefox_profile=profile)
     # Create base drivers (Chromium)
     if cls.config['driver'] == "chromium":
         chrome_options = ChromiumOptions()
         chrome_options.add_argument('--ignore-certificate-errors')
         capabilities = DesiredCapabilities.CHROME
         capabilities['goog:loggingPrefs'] = {'browser': 'ALL'}
         if cls.config['headless']:
             chrome_options.add_argument("--headless")
         cls.base_driver = webdriver.Chrome(
             options=chrome_options, desired_capabilities=capabilities)
         cls.second_driver = webdriver.Chrome(
             options=chrome_options, desired_capabilities=capabilities)
     cls.base_driver.set_window_size(1366, 768)
     cls.second_driver.set_window_size(1366, 768)
Exemplo n.º 2
0
      "\' and config file \'" + args.config_file + "\'\n")

#Import user configuration file
SHM_Config = importlib.import_module(args.config_file)

#Set up Webdriver
if args.engine == 'firefox':
    from selenium.webdriver.firefox.options import Options as FireFoxOptions
    firefox_options = FireFoxOptions()
    firefox_options.headless = True
    driver = webdriver.Firefox(options=firefox_options,
                               executable_path=SHM_Config.geckodriverpath)

if args.engine == 'chromium':
    from selenium.webdriver.chrome.options import Options as ChromiumOptions
    chrome_options = ChromiumOptions()
    chrome_options.add_argument("--headless")
    chrome_options.add_argument("--window-size=1920,1080")
    chrome_options.add_argument('--start-maximized')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument("--disable-extensions")
    chrome_options.add_argument('disable-infobars')
    driver = webdriver.Chrome(options=chrome_options)

# Apply the user configuration to the modem and publisher (so any failures due to misconfiguration happen quickly)
modem = SHM_Config.modem(SHM_Config.modemOptions)
publisher = SHM_Config.publisher(SHM_Config.publisherOptions)

# Capture the data from the hub
DataRecord = modem.CaptureStats(driver)