Пример #1
0
def setup(request):

    testname = os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(
        ' ')[0]

    headless_mode = (os.environ["HEADLESS_MODE"] == 'True')

    if "login" in testname:
        driverenv = os.environ["DRIVER_ENV"]
        common_path = f'{os.getcwd()}/etc/tests/integration/authx'

        if driverenv == "firefox":
            # Firefox
            fireFoxOptions = ffOptions()
            if headless_mode:
                fireFoxOptions.headless = True

            driver = webdriver.Firefox(
                executable_path=f'{common_path}/geckodriver',
                options=fireFoxOptions)
        elif driverenv == "chrome":
            # Chrome/Brave
            chromeOptions = chOptions()
            if headless_mode:
                chromeOptions.headless = True
            # Change this to reflect the working machine's setup
            chromeOptions.binary_location = '/usr/bin/brave-browser'

            driver_path = f'{common_path}/chromedriver'
            driver = webdriver.Chrome(options=chromeOptions,
                                      executable_path=driver_path)
        else:
            raise Exception(
                "Missing driver configuration! Please check the Makefile and ensure 'firefox' or 'chrome' is being passed to the run_tests.sh file!"
            )

        # Randomly select (within reason) window dimensions and position
        width = random.randint(760, 1900)
        height = random.randint(512, 1024)
        x = random.randint(0, 500)
        y = random.randint(0, 500)

        driver.set_window_size(width, height)
        driver.set_window_position(x, y, windowHandle='current')

    else:
        driver = None

    candig_url = os.environ["CANDIG_PUBLIC_URL"]
    candigauth_url = os.environ["KEYCLOAK_PUBLIC_URL"]
    permissions_data_store_url = os.environ['VAULT_SERVICE_PUBLIC_URL']
    #temp
    candig_server_authz_url = 'http://0.0.0.0:8182/v1/data/permissions/allowed'

    session = request.node
    for item in session.items:
        cls = item.getparent(pytest.Class)
        setattr(cls.obj, "driver", driver)
        setattr(cls.obj, "debug_pause_time_seconds", 0)
        setattr(cls.obj, "candig_url", candig_url)
        setattr(cls.obj, "candigauth_url", candigauth_url)
        setattr(cls.obj, "permissions_data_store_url",
                permissions_data_store_url)
        setattr(cls.obj, "candig_server_authz_url", candig_server_authz_url)

    yield driver
    if driver != None:
        driver.close()
Пример #2
0
    def get_driver_instance(self):

        if self.browser == "chrome":

            chrome_capabilities = webdriver.DesiredCapabilities.CHROME
            chrome_capabilities['platform'] = self.platform
            chrome_capabilities['browserName'] = 'chrome'
            chrome_capabilities['javascriptEnabled'] = True

            options = chromeOptions()
            options.add_argument("--disable-infobars")
            options.add_argument("--disable-extensions")
            options.add_argument("--disable-notifications")
            options.add_argument("--start-maximized")
            options.add_argument("--disable-web-security")
            options.add_argument("--no-proxy-server")
            options.add_argument("--enable-automation")
            options.add_argument("--disable-save-password-bubble")
            options.add_experimental_option(
                'prefs', {
                    'credentials_enable_service': False,
                    'profile': {
                        'password_manager_enabled': False
                    }
                })

            driver = webdriver.Remote(command_executor=self.prop.get(
                'GRID', 'GRID_SERVER'),
                                      desired_capabilities=chrome_capabilities,
                                      options=options)

        elif self.browser == "firefox":

            firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
            firefox_capabilities['platform'] = self.platform
            firefox_capabilities['browserName'] = 'firefox'
            firefox_capabilities['javascriptEnabled'] = True
            firefox_capabilities['marionette'] = True

            options = ffOptions()
            options.log.level = 'trace'

            driver = webdriver.Remote(
                command_executor=self.prop.get('GRID', 'GRID_SERVER'),
                desired_capabilities=firefox_capabilities,
                options=options)

        elif self.browser == "safari":

            safari_capabilities = webdriver.DesiredCapabilities.SAFARI
            safari_capabilities['platform'] = self.platform
            safari_capabilities['browserName'] = 'safari'
            safari_capabilities['javascriptEnabled'] = True

            driver = webdriver.Remote(command_executor=self.prop.get(
                'GRID', 'GRID_SERVER'),
                                      desired_capabilities=safari_capabilities)

        elif self.browser == "sauce":

            username = self.prop.get('CLOUD', 'sl_username')
            automate_key = self.prop.get('CLOUD', 'sl_key')
            url = "https://{}:{}@ondemand.saucelabs.com:443/wd/hub".format(
                username, automate_key)
            caps = {
                'browserName': "Safari",
                'appiumVersion': "1.8.1",
                'deviceName': "iPhone X Simulator",
                'deviceOrientation': "portrait",
                'platformVersion': "11.3",
                'platformName': "iOS",
                'name': "iPhone X Execution"
            }

            driver = webdriver.Remote(command_executor=url,
                                      desired_capabilities=caps)

        elif self.browser == "browserstack_web":

            username = self.prop.get('CLOUD', 'bs_username')
            automate_key = self.prop.get('CLOUD', 'bs_key')
            url = "http://{}:{}@hub.browserstack.com:80/wd/hub".format(
                username, automate_key)

            caps = {
                'browser': 'Firefox',
                'browser_version': '61.0',
                'os': 'OS X',
                'os_version': 'High Sierra',
                'resolution': '1024x768',
                'name': "Mac Safari Execution",
                'browserstack.debug': True,
                'browserstack.networkLogs': True
            }

            driver = webdriver.Remote(command_executor=url,
                                      desired_capabilities=caps)

        elif self.browser == "browserstack_mobile":

            username = self.prop.get('CLOUD', 'bs_username')
            automate_key = self.prop.get('CLOUD', 'bs_key')
            url = "http://{}:{}@hub.browserstack.com:80/wd/hub".format(
                username, automate_key)

            caps = {
                'device': 'Google Pixel',
                'os_version': '7.1',
                'name': "Google Pixcel Execution"
            }

            driver = webdriver.Remote(command_executor=url,
                                      desired_capabilities=caps)

        elif self.browser == "local_chrome":

            options = chromeOptions()
            options.add_argument("--disable-infobars")
            options.add_argument("--disable-extensions")
            options.add_argument("--disable-notifications")
            options.add_argument("--start-maximized")
            options.add_argument("--disable-web-security")
            options.add_argument("--no-proxy-server")
            options.add_argument("--enable-automation")
            options.add_argument("--disable-save-password-bubble")
            options.add_experimental_option(
                'prefs', {
                    'credentials_enable_service': False,
                    'profile': {
                        'password_manager_enabled': False
                    }
                })

            driver = webdriver.Chrome(ChromeDriverManager().install(),
                                      options=options)

        elif self.browser == "local_firefox":

            browser_profile = webdriver.FirefoxProfile()
            browser_profile.set_preference("dom.webnotifications.enabled",
                                           False)

            options = ffOptions()
            options.log.level = 'trace'
            firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
            firefox_capabilities['marionette'] = True

            driver = webdriver.Firefox(
                capabilities=firefox_capabilities,
                executable_path=GeckoDriverManager().install(),
                options=options,
                service_log_path='/tmp/geckodriver.log',
                firefox_profile=browser_profile)

        else:

            options = chromeOptions()
            options.add_argument("--disable-infobars")
            options.add_argument("--disable-extensions")
            options.add_argument("--disable-notifications")
            options.add_argument("--start-maximized")
            options.add_argument("--disable-web-security")
            options.add_argument("--no-proxy-server")
            options.add_argument("--enable-automation")
            options.add_argument("--disable-save-password-bubble")
            options.add_experimental_option(
                'prefs', {
                    'credentials_enable_service': False,
                    'profile': {
                        'password_manager_enabled': False
                    }
                })

            driver = webdriver.Chrome(ChromeDriverManager().install(),
                                      options=options)

        if "chrome" in self.browser:
            driver.fullscreen_window()

        if self.environment == "staging":
            test_data = self.prop.get('RAFT', 'staging_test_data')
            self.config.change_properties_file('RAFT', 'base_test_data',
                                               test_data)
            self.url = self.prop.get('RAFT', 'staging_url')
            self.config.change_properties_file('RAFT', 'base_url', self.url)

        elif self.environment == "prod":
            test_data = self.prop.get('RAFT', 'prod_test_data')
            self.config.change_properties_file('RAFT', 'base_test_data',
                                               test_data)
            self.url = self.prop.get('RAFT', 'prod_url')
            self.config.change_properties_file('RAFT', 'base_url', self.url)

        else:
            test_data = self.prop.get('RAFT', 'staging_test_data')
            self.config.change_properties_file('RAFT', 'base_test_data',
                                               test_data)
            self.url = self.prop.get('RAFT', 'staging_url')
            self.config.change_properties_file('RAFT', 'base_url', self.url)

        driver.get(self.url)

        return driver
Пример #3
0
    def get_driver_instance(self):

        if self.browser == "chrome":

            chrome_capabilities = webdriver.DesiredCapabilities.CHROME
            chrome_capabilities['platform'] = self.platform
            chrome_capabilities['browserName'] = 'chrome'
            chrome_capabilities['javascriptEnabled'] = True

            options = chromeOptions()
            options.add_argument("--disable-infobars")
            options.add_argument("--disable-extensions")
            options.add_argument("--disable-notifications")
            options.add_argument("--start-maximized")
            options.add_argument("--disable-web-security")
            options.add_argument("--no-proxy-server")
            options.add_argument("--enable-automation")
            options.add_argument("--disable-save-password-bubble")
            options.add_experimental_option('prefs', {'credentials_enable_service': False,
                                                      'profile': {'password_manager_enabled': False}})

            driver = webdriver.Remote(
                command_executor=self.prop.get('GRID', 'GRID_SERVER'),
                desired_capabilities=chrome_capabilities, options=options)

        elif self.browser == "firefox":

            firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
            firefox_capabilities['platform'] = self.platform
            firefox_capabilities['browserName'] = 'firefox'
            firefox_capabilities['javascriptEnabled'] = True
            firefox_capabilities['marionette'] = True

            options = ffOptions()
            options.log.level = 'trace'

            driver = webdriver.Remote(command_executor=self.prop.get('GRID', 'GRID_SERVER'),
                                      desired_capabilities=firefox_capabilities, options=options)

        elif self.browser == "safari":

            safari_capabilities = webdriver.DesiredCapabilities.SAFARI
            safari_capabilities['platform'] = self.platform
            safari_capabilities['browserName'] = 'safari'
            safari_capabilities['javascriptEnabled'] = True

            driver = webdriver.Remote(
                command_executor=self.prop.get('GRID', 'GRID_SERVER'),
                desired_capabilities=safari_capabilities)

        elif self.browser == "edge":

            edge_capabilities = webdriver.DesiredCapabilities.EDGE
            edge_capabilities['platform'] = self.platform
            edge_capabilities['browserName'] = 'MicrosoftEdge'
            edge_capabilities['javascriptEnabled'] = True

            driver = webdriver.Remote(
                command_executor=self.prop.get('GRID', 'GRID_SERVER'),
                desired_capabilities=edge_capabilities)

        elif self.browser == "sauce":
            username = self.prop.get('CLOUD', 'sl_username')
            automate_key = self.prop.get('CLOUD', 'sl_key')
            url = "https://" + username + ":" + automate_key + "@ondemand.saucelabs.com:443/wd/hub"

            caps = {}
            caps['browserName'] = "Safari"
            caps['appiumVersion'] = "1.8.1"
            caps['deviceName'] = "iPhone X Simulator"
            caps['deviceOrientation'] = "portrait"
            caps['platformVersion'] = "11.3"
            caps['platformName'] = "iOS"
            caps['name'] = "iPhone X Execution"

            driver = webdriver.Remote(
                command_executor=url,
                desired_capabilities=caps)

        elif self.browser == "browserstack_desktop":
            username = self.prop.get('CLOUD', 'bs_username')
            automate_key = self.prop.get('CLOUD', 'bs_key')
            url = "http://" + username + ":" + automate_key + "@hub.browserstack.com:80/wd/hub"

            caps = {}
            caps['browser'] = 'Firefox'
            caps['browser_version'] = '61.0'
            caps['os'] = 'OS X'
            caps['os_version'] = 'High Sierra'
            caps['resolution'] = '1024x768'
            caps['name'] = "Mac Safari Execution"
            caps['browserstack.debug'] = True
            caps['browserstack.networkLogs'] = True

            driver = webdriver.Remote(
                command_executor=url,
                desired_capabilities=caps)

        elif self.browser == "browserstack_mobile":
            username = self.prop.get('CLOUD', 'bs_username')
            automate_key = self.prop.get('CLOUD', 'bs_key')
            url = "http://" + username + ":" + automate_key + "@hub-cloud.browserstack.com/wd/hub"

            caps={}

            caps['device'] = 'Google Pixel'
            caps['os_version'] = '7.1'
            caps['name'] = "Google Pixcel Execution"

            driver = webdriver.Remote(
                command_executor=url,
                desired_capabilities=caps)

        elif self.browser == "local_edge":

            driver_location = os.path.join(self.cur_path, r"../ExternalDrivers/MicrosoftWebDriver.exe")
            os.environ["webdriver.edge.driver"] = driver_location

            edge_capabilities = webdriver.DesiredCapabilities.EDGE
            driver = webdriver.Edge(capabilities=edge_capabilities, executable_path=driver_location)

        elif self.browser == "local_firefox":
            driver_location = os.path.join(self.cur_path, r"../ExternalDrivers/geckodriver.exe")
            os.environ["webdriver.gecko.driver"] = driver_location

            browser_profile = webdriver.FirefoxProfile()
            browser_profile.set_preference("dom.webnotifications.enabled", False)

            options = ffOptions()
            options.log.level = 'trace'
            firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
            firefox_capabilities['marionette'] = True
            driver = webdriver.Firefox(capabilities=firefox_capabilities, executable_path=driver_location,
                                       options=options, log_path='/tmp/geckodriver.log',
                                       firefox_profile=browser_profile)

        elif self.browser == "local_chrome":
            driver_location = os.path.join(self.cur_path, r"../ExternalDrivers/chromedriver.exe")
            os.environ["webdriver.chrome.driver"] = driver_location

            options = chromeOptions()
            options.add_argument("--disable-infobars")
            options.add_argument("--disable-extensions")
            options.add_argument("--disable-notifications")
            options.add_argument("--start-maximized")
            options.add_argument("--disable-web-security")
            options.add_argument("--no-proxy-server")
            options.add_argument("--enable-automation")
            options.add_argument("--disable-save-password-bubble")
            options.add_experimental_option('prefs', {'credentials_enable_service': False,
                                                      'profile': {'password_manager_enabled': False}})

            driver = webdriver.Chrome(driver_location, options=options)

        else:
            driver_location = os.path.join(self.cur_path, r"../ExternalDrivers/chromedriver.exe")
            os.environ["webdriver.chrome.driver"] = driver_location

            options = chromeOptions()
            options.add_argument("--disable-infobars")
            options.add_argument("--disable-extensions")
            options.add_argument("--disable-notifications")
            options.add_argument("--start-maximized")
            options.add_argument("--disable-web-security")
            options.add_argument("--no-proxy-server")
            options.add_argument("--enable-automation")
            options.add_argument("--disable-save-password-bubble")
            options.add_experimental_option('prefs', {'credentials_enable_service': False,
                                                      'profile': {'password_manager_enabled': False}})

            driver = webdriver.Chrome(driver_location, options=options)

        if "chrome" in self.browser:
            driver.fullscreen_window()

        if self.environment == "staging":
            test_data = self.prop.get('RAFT', 'staging_test_data')
            self.config.change_properties_file('RAFT', 'base_test_data', test_data)
            self.url = self.prop.get('RAFT', 'staging_url')
            self.config.change_properties_file('RAFT', 'base_url', self.url)

        elif self.environment == "prod":
            test_data = self.prop.get('RAFT', 'prod_test_data')
            self.config.change_properties_file('RAFT', 'base_test_data', test_data)
            self.url = self.prop.get('RAFT', 'prod_url')
            self.config.change_properties_file('RAFT', 'base_url', self.url)

        else:
            test_data = self.prop.get('RAFT', 'staging_test_data')
            self.config.change_properties_file('RAFT', 'base_test_data', test_data)
            self.url = self.prop.get('RAFT', 'staging_url')
            self.config.change_properties_file('RAFT', 'base_url', self.url)

        driver.get(self.url)

        return driver
Пример #4
0
def create_browser(url, browser_type='Firefox'):

    if browser_type == 'Chrome':
        options = chromeOptions()
        options.add_argument("--disable-extensions")
        options.add_argument("--disable-gpu")
        options.add_argument("--headless")
        options.add_argument("--log-level=3")
        try:
            browser = webdriver.Chrome(options=options)
            #browser = webdriver.Safari()
        ### If session fails, try to close any pre-existing browsers and re-try.
        except SessionNotCreatedException as e:
            print('Closing Session\n', e)
            try:
                browser.close()
            except:
                pass
            try:
                browser.quit()
            except:
                pass
            browser = webdriver.Chrome(options=options)

        try:
            browser.get(url)
            time.sleep(5)
        except:
            print('sleeping 5 seconds.')
            time.sleep(5)
            try:
                browser.get(url)
                time.sleep(5)
            except:
                print('sleeping 60 seconds.')
                time.sleep(60)
                try:
                    browser.get(url)
                    time.sleep(5)
                except:
                    return None

    elif browser_type == 'Firefox':
        options = ffOptions()
        options.headless = True

        try:
            browser = webdriver.Firefox(options=options)
            #browser = webdriver.Safari()
        ### If session fails, try to close any pre-existing browsers and re-try.
        except SessionNotCreatedException as e:
            print('Closing Session\n', e)
            try:
                browser.close()
            except:
                pass
            try:
                browser.quit()
            except:
                pass
            browser = webdriver.Firefox(options=options)

        try:
            browser.get(url)
            time.sleep(5)
        except:
            print('sleeping 5 seconds.')
            time.sleep(5)
            try:
                browser.get(url)
                time.sleep(5)
            except:
                print('sleeping 60 seconds.')
                time.sleep(60)
                try:
                    browser.get(url)
                    time.sleep(5)
                except:
                    return None

    return browser
Пример #5
0
    def get_driver_instance(self):

        if self.browser == "chrome":

            chrome_capabilities = webdriver.DesiredCapabilities.CHROME
            chrome_capabilities['platform'] = self.platform
            chrome_capabilities['browserName'] = 'chrome'
            chrome_capabilities['javascriptEnabled'] = True

            options = chromeOptions()
            options.add_argument("--disable-infobars")
            options.add_argument("--disable-extensions")
            options.add_argument("--disable-notifications")
            options.add_argument("--start-maximized")
            options.add_argument("--disable-web-security")
            options.add_argument("--no-proxy-server")
            options.add_argument("--enable-automation")
            options.add_argument("--disable-save-password-bubble")
            options.add_experimental_option(
                'prefs', {
                    'credentials_enable_service': False,
                    'profile': {
                        'password_manager_enabled': False
                    }
                })

            driver = webdriver.Remote(command_executor=self.prop.get(
                'GRID', 'GRID_SERVER'),
                                      desired_capabilities=chrome_capabilities,
                                      options=options)

        elif self.browser == "firefox":

            firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
            firefox_capabilities['platform'] = self.platform
            firefox_capabilities['browserName'] = 'firefox'
            firefox_capabilities['javascriptEnabled'] = True
            firefox_capabilities['marionette'] = True

            options = ffOptions()
            options.log.level = 'trace'

            driver = webdriver.Remote(
                command_executor=self.prop.get('GRID', 'GRID_SERVER'),
                desired_capabilities=firefox_capabilities,
                options=options)

        elif self.browser == "safari":

            safari_capabilities = webdriver.DesiredCapabilities.SAFARI
            safari_capabilities['platform'] = self.platform
            safari_capabilities['browserName'] = 'safari'
            safari_capabilities['javascriptEnabled'] = True

            driver = webdriver.Remote(command_executor=self.prop.get(
                'GRID', 'GRID_SERVER'),
                                      desired_capabilities=safari_capabilities)

        else:
            test_data = self.prop.get('RAFT', 'staging_test_data')
            self.config.change_properties_file('RAFT', 'base_test_data',
                                               test_data)
            self.url = self.prop.get('RAFT', 'staging_url')
            self.config.change_properties_file('RAFT', 'base_url', self.url)

        driver.get(self.url)

        return driver
Пример #6
0
    def webdriver_createBrowserOptions(browserName,
                                       desiredCapabilities,
                                       browserMobProxy=None,
                                       randomProxy=None):
        """
        Translates desired capabilities from the Testrun (or globals) into specific BrowserOptions for the
        currently active browser

        @param browserName: any of the GC.BROWSER*
        @param desiredCapabilities: Settings from TestRun or globals
        @param browserMobProxy: Proxy-Server IP+Port of internal BrowserMobProxy.
        @param randomProxy: Proxy-Server IP+Port of random external Proxy
        @return: the proper BrowserOptions for the currently active browser.
        """

        # Default Download Directory for Attachment downloads
        if browserName == GC.BROWSER_CHROME:
            lOptions = ChromeOptions()
            prefs = {
                "plugins.plugins_disabled": ["Chrome PDF Viewer"],
                "plugins.always_open_pdf_externally":
                True,
                "profile.default_content_settings.popups":
                0,
                "download.default_directory":
                helper.browserHelper_setBrowserDownloadDirRandom(
                ),  # IMPORTANT - ENDING SLASH V IMPORTANT
                "directory_upgrade":
                True
            }
            lOptions.add_experimental_option("prefs", prefs)
            # Set Proxy for Chrome. First RandomProxy (External), if set. If not, then internal Browsermob
            if randomProxy:
                lOptions.add_argument(
                    f"--proxy-server={randomProxy['ip']}:{randomProxy['port']}"
                )
            elif browserMobProxy:
                lOptions.add_argument('--proxy-server={0}'.format(
                    browserMobProxy.proxy))
        elif browserName == GC.BROWSER_FIREFOX:
            lOptions = ffOptions()
        else:
            lOptions = None

        if desiredCapabilities and lOptions:
            # sometimes instead of DICT comes a string with DICT-Format
            if isinstance(
                    desiredCapabilities, str
            ) and "{" in desiredCapabilities and "}" in desiredCapabilities:
                desiredCapabilities = json.loads(
                    desiredCapabilities.replace("'", '"'))

            if isinstance(desiredCapabilities, dict):
                if desiredCapabilities.get(GC.BROWSER_MODE_HEADLESS):
                    logger.debug("Starting in Headless mode")
                    lOptions.headless = True
                else:
                    # statement not matched
                    pass
            else:
                # statement not matched
                pass
        else:
            # statement not matched
            pass

        return lOptions
Пример #7
0
    def __init__(self, driver, driver_exe, headless=True):

        self.consolidated_df = pd.DataFrame()
        self.load_status = False
        self.headless = headless

        if driver.lower() == 'chrome':
            if self.headless:
                options = chOptions()
                options.add_argument('--headless')
                options.add_argument('--disable-gpu')
                options.add_argument("--log-level=3")

                try:
                    webdriver.Chrome.__init__(self,
                                              driver_exe,
                                              chrome_options=options)
                except:
                    logger.warning(
                        'Can\'t launch web driver with the given exe file',
                        exc_info=True)
                    try:
                        webdriver.Chrome.__init__(self, chrome_options=options)
                    except Exception as e:
                        raise ValueError(e)

            else:
                try:
                    webdriver.Chrome.__init__(self, driver_exe)
                except:
                    logger.warning(
                        'Can\'t launch web driver with the given exe file',
                        exc_info=True)
                    try:
                        webdriver.Chrome.__init__(self)
                    except Exception as e:
                        raise ValueError(e)

        elif driver.lower() == 'firefox':
            if self.headless:
                options = ffOptions()
                options.add_argument('--headless')
                options.add_argument('--disable-gpu')
                options.add_argument("--log-level=3")

                try:
                    webdriver.Firefox.__init__(self,
                                               driver_exe,
                                               options=options)
                except:
                    logger.warning(
                        'Can\'t launch web driver with the given exe file',
                        exc_info=True)
                    try:
                        webdriver.Firefox.__init__(self)
                    except Exception as e2:
                        raise ValueError(e2)

            else:
                try:
                    webdriver.Firefox.__init__(self, driver_exe)
                except:
                    logger.warning(
                        'Can\'t launch web driver with the given exe file',
                        exc_info=True)
                    try:
                        webdriver.Firefox.__init__(self)
                    except Exception as e:
                        raise ValueError(e)
Пример #8
0
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options as ffOptions
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import time

url = 'https://129.158.112.190/dv/ui/home.jsp'

firefox_options = ffOptions()
firefox_options.set_headless(headless=True)
firefox_driver = os.getcwd() + "\\geckodriver.exe"
driver = webdriver.Firefox(firefox_options=firefox_options, executable_path=firefox_driver)
# https://github.com/mozilla/geckodriver/releases
driver.get(url)

wait = WebDriverWait(driver, 10)
wait.until(EC.visibility_of_element_located((By.ID, "btn_login")))
user = driver.find_element_by_id("idUser")
driver.execute_script("arguments[0].setAttribute('value', '')", user)
pasw = driver.find_element_by_id("idPassword")
driver.execute_script("arguments[0].setAttribute('value', '')", pasw)
btnlgn = driver.find_element_by_id("btn_login")
btnlgn.click()
wait = WebDriverWait(driver, 60)
wait.until(EC.visibility_of_element_located((By.ID, "openNavMenuBtnSet")))
btnnav = driver.find_element_by_id("openNavMenuBtnSet")
btnnav.click()