Ejemplo n.º 1
0
    def __init__(self,
                 BROWSER='chrome',
                 DRIVER='',
                 HEADLESS=True,
                 IGNORE_CERT_ERROR=False):
        self.driver = None
        self.id = None
        self.password = None
        self.loginflag = False
        fp = None
        options = None
        if BROWSER == 'firefox':
            options = firefoxOptions()
            fp = self.get_firefox_profile()
        elif BROWSER == 'chrome':
            options = chromeOptions()

        if HEADLESS == True:
            options.set_headless(headless=True)

        if IGNORE_CERT_ERROR == True:
            options.add_argument('--ignore-certificate-errors')

        if BROWSER == 'firefox':
            self.driver = webdriver.Firefox(firefox_binary=FIREFOX_BINARY,
                                            firefox_options=options,
                                            log_path='/dev/null',
                                            firefox_profile=fp)
        elif BROWSER == 'chrome':
            if len(DRIVER):
                self.driver = webdriver.Chrome(DRIVER, chrome_options=options)
            else:
                self.driver = webdriver.Chrome(chrome_options=options)
Ejemplo n.º 2
0
    def run_local(self, browser_version):
        """
        Return the local driver
        : TODO Add support to other browsers
        """
        if command_line.get_browser().lower() == "chrome":
            options = chromeOptions()
            options.add_argument("disable-infobars")
            if command_line.headless() == "y":
                options.add_argument("--headless")  # For Headless chrome
            caps = DesiredCapabilities.CHROME
            local_driver = webdriver.Chrome(options=options,
                                            desired_capabilities=caps)
            return local_driver

        if command_line.get_browser().lower() == "ff" \
            or command_line.get_browser().lower() == "firefox":
            profile = FirefoxProfile()
            options = firefoxOptions()

            profile.set_preference("geo.prompt.testing", True)
            profile.set_preference("geo.prompt.testing.allow", True)
            if command_line.headless() == "y":
                options.headless = True  # For Headless firefox
            local_driver = webdriver.Firefox(
                executable_path=GeckoDriverManager().install(),
                firefox_profile=profile,
                options=options)
            return local_driver
Ejemplo n.º 3
0
 def setup_driver_options(self, user_agent):
     if self.driver_type == 'firefox':
         firefox_options = firefoxOptions()
         firefox_options.add_argument("--window-size=1420,1080")
         # firefox_options.add_argument("--headless")
         firefox_options.add_argument("--disable-gpu")
         firefox_options.add_argument(f'user-agent={user_agent}')
         # capabilities = self.setup_proxy(driver_type.lower())
         return firefox_options
     elif self.driver_type == 'chrome':  #add more driver types (chrome, etc if necessary)
         chrome_options = chromeOptions()
         # chrome_options.add_argument("--headless")
         # chrome_options.add_argument("--no-sandbox")
         chrome_options.add_argument("--window-size=1420,1080")
         chrome_options.add_argument("--disable-gpu")
         chrome_options.add_argument(f'user-agent={user_agent}')
         return chrome_options
     else:
         print("not supported driver type")
Ejemplo n.º 4
0
    def __init__(self):
        '''
        用于模拟浏览器进行爬虫操作
        目前是单线程处理,如需多线程需要配合其他库一同使用
        
        变量说明:

        model               : 工作模式 work dev test
        driver              : 驱动器(浏览器控制对象)
        driverStatus        : 驱动器状态
        chrome_options      : 浏览器运行参数 - 可设置无头模式等
        Soup                : 默认保存当前soup
        '''

        self.model = 'def'
        self.driver = {}
        self.driverStatus = False
        self.chrome_options = chromeOptions()
        self.Soup = {}
Ejemplo n.º 5
0
def scrap_spa(recerche):
    from selenium.webdriver import Firefox, Chrome
    from selenium.webdriver.firefox.options import Options as fireOptions
    from selenium.webdriver.chrome.options import Options as chromeOptions
    opts = chromeOptions()
    opts.set_headless()
    opts.add_argument("--remote-debugging-port=9222")
    browser = Chrome(options=opts)
    url = "https://ntealan.net/dictionaries-platform"
    browser.get(url)
    #print(browser.save_screenshot('ntealan.png'))
    # recherche l'élément body dans la page
    #body = browser.find_element_by_tag_name('body')
    #open("body_ntealan.html", 'w').write(body.get_attribute("outerHTML"))

    browser.get('https://duckduckgo.com')
    search_form = browser.find_element_by_id('search_form_input_homepage')
    search_form.send_keys('voiture')
    search_form.submit()
    print(search_form.get_attribute("outerHTML"))
Ejemplo n.º 6
0
def __driver(driver_path):
    if driver_path.split('/')[-1] == "chromedriver.exe" or driver_path.split(
            '\\')[-1] == "chromedriver.exe":
        flag = 'Chrome'
        _options = chromeOptions()
    elif driver_path.split('/')[-1] == "geckodriver.exe" or driver_path.split(
            '\\')[-1] == "geckodriver.exe":
        flag = 'Firefox'
        _options = fireOptions()
    # # _options.add_argument("--proxy-server=http://115.221.116.136:8888")
    # _options.add_argument('--no-sandbox')  # 解决DevToolsActivePort文件不存在的报错
    # # _options.add_argument('window-size=1920x1080')  # 指定浏览器分辨率
    # _options.add_argument('--disable-gpu')  # 谷歌文档提到需要加上这个属性来规避bug
    # _options.add_argument('--hide-scrollbars')  # 隐藏滚动条, 应对一些特殊页面
    # _options.add_argument('blink-settings=imagesEnabled=false')  # 不加载图片, 提升速度
    # _options.add_argument('--headless')  # 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败

    if flag == "Chrome":
        return Chrome(chrome_options=_options, executable_path=driver_path)
    elif flag == "Firefox":
        return Firefox(firefox_options=_options, executable_path=driver_path)
Ejemplo n.º 7
0
def login(username, password, filedir):

    DRIVER_LOCATION = './chrome_driver/chromedriver.exe'
    options = chromeOptions()
    options.add_argument("start-maximized")
    options.add_argument('--no-sandbox')
    prefs = {"download.default_directory": filedir}
    options.add_experimental_option("prefs", prefs)
    session = webdriver.Chrome(chrome_options=options,
                               executable_path=DRIVER_LOCATION)

    session.get(LUMO_LOGIN_URL)

    login_field = session.find_element_by_id("login")
    login_field.clear()
    login_field.send_keys(username)
    pwd_field = session.find_element_by_id('password')
    pwd_field.clear()
    pwd_field.send_keys(password)

    sign_in_button = session.find_element_by_xpath(
        "//input[@value='Sign in'][@type='submit']")
    sign_in_button.click()

    log.info('Logged in')

    if re.search('Invalid user or password', session.page_source):
        log.error("DISCONNECTING")
        disconnect(session)
        raise Exception('Invalid username or password provided')

    try:
        myElem = WebDriverWait(session, 5).until(
            EC.presence_of_element_located((By.ID, 'table-my-runs-body')))
        log.info("Page is ready!")
    except TimeoutException:
        log.error("Timeout on load...")

    return session
def python_selenium_test(browser_var='chrome'):
    print('Hello, world!')

    if ('headless' in browser_var.lower()):
        if ('chrome' in browser_var.lower()):
            chrome_options = chromeOptions()
            chrome_options.add_argument("--headless")
            browser = webdriver.Chrome(chrome_options=chrome_options)
        elif ('firefox' in browser_var.lower()):
            firefox_options = firefoxOptions()
            firefox_options.add_argument("--headless")
            browser = webdriver.Firefox(options=firefox_options)
    else:
        if ('chrome' in browser_var.lower()):
            browser = webdriver.Chrome()
        elif ('firefox' in browser_var.lower()):
            browser = webdriver.Firefox()
    wait = ui.WebDriverWait(browser, 5)

    browser.get('https://the-internet.herokuapp.com/login')

    wait.until(
        expected_conditions.visibility_of_element_located((By.ID, 'username')))
    browser.find_element_by_id('username').click()
    browser.find_element_by_id('username').send_keys('tomsmith')

    wait.until(
        expected_conditions.visibility_of_element_located((By.ID, 'password')))
    browser.find_element_by_id('password').click()
    browser.find_element_by_id('password').send_keys('SuperSecretPassword!')

    browser.find_element_by_css_selector('button[type=submit]').click()

    wait.until(lambda browser: browser.find_element_by_css_selector(
        '.button > i.icon-signout'))

    time.sleep(5)
    browser.quit()
Ejemplo n.º 9
0
    def __init__(self, driver=None):
        '''
    Instantiate NoVNCbot for interacting with a VNC Console
    @param driver: 			Optional override that accepts the following values
    					String: firefox, ff  -- Creates Firefox browser in headless mode
					String: chrome  -- Creates chrome browser in headless mode
					WebDriver:	-- Uses webdriver  created by caller
					None:	Creates Firefox browser in headless mode
    '''
        if isinstance(driver, WebDriver):
            self.driver = driver
        elif isinstance(driver, str) and (driver.lower() == 'firefox'
                                          or driver.lower() == 'ff'):
            firefox_options = firefoxOptions()
            firefox_options.headless = True
            self.driver = webdriver.Firefox(options=firefox_options)
        elif isinstance(driver, str) and (driver.lower() == 'chrome'):
            chrome_options = chromeOptions()
            chrome_options.add_argument("--headless")
            self.driver = webdriver.Chrome(options=chrome_options)
        else:
            default_options = firefoxOptions()
            default_options.headless = True
            self.driver = webdriver.Firefox(options=default_options)
Ejemplo n.º 10
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
Ejemplo n.º 11
0
    def loginBB(self):

        if self.browserName == "Google Chrome":
            # declaring webdriver
            try:
                chrome_options = chromeOptions()
                chrome_options.add_argument("--use-fake-ui-for-media-stream")
                chrome_options.add_argument('log-level=3')
                chrome_options.add_argument("--start-maximized")
                driver = webdriver.Chrome(options=chrome_options)
            except:
                logger.error("Check if chromedrivers are in the path")
                input()
                exit()


        elif self.browserName == "Brave":
            BraveFlag=False
            try:
                brave_path = "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"
                brave_options = chromeOptions()
                brave_options.add_argument("--use-fake-ui-for-media-stream")
                brave_options.add_argument('log-level=3')
                brave_options.add_argument("--start-maximized")
                brave_options.binary_location = brave_path
                driver = webdriver.Chrome(chrome_options=brave_options)
                BraveFlag=True
            except:
                logger.error("Check if chromedrivers are in the path")


            if not BraveFlag:
                try:
                    brave_path = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"
                    brave_options = chromeOptions()
                    brave_options.add_argument("--use-fake-ui-for-media-stream")
                    brave_options.add_argument('log-level=3')
                    brave_options.add_argument("--start-maximized")
                    brave_options.binary_location = brave_path
                    driver = webdriver.Chrome(chrome_options=brave_options)
                except:
                    logger.error("Check if chromedrivers are in the path")
                    logger.warning("Exiting ..... ")
                    input()
                    exit()


        elif self.browserName == "Mozilla Firefox":
            try:
                firefox_options = FirefoxOptions()
                firefox_options.add_argument("--use-fake-ui-for-media-stream")
                firefox_options.add_argument('log-level=3')
                firefox_options.add_argument("--start-maximized")
                firefox_options.set_preference("media.navigator.permission.disabled", True)
                driver = webdriver.Firefox(options=firefox_options)
                driver.maximize_window()
            except:
                logger.error("Check if geeckodriver are in the path")
                input()
                exit()


        networkAvaliable = connectionCheck()
        if not networkAvaliable:
            is_connected()
        

        # entering username and password in BB
        counter=0
        while(networkAvaliable):
            counter+=1

            try:
                driver.get('https://cuchd.blackboard.com/')
                WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='button-1']"))).click()
                driver.find_element_by_name('user_id').send_keys(self.userName)
                driver.find_element_by_name('password').send_keys(self.password)
                driver.find_element_by_id('entry-login').click()
                break
            except:
                logger.error("Unable to login BB")
                is_connected()

            if counter==5:
                fiveFailedAttempts()


        time.sleep(2)
        currentURL = str(driver.current_url)


        if currentURL == "https://cuchd.blackboard.com/ultra/course":
            logger.info("Logged in successfully to Black Board")

        return driver
Ejemplo n.º 12
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
Ejemplo n.º 13
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
Ejemplo n.º 14
0
    def getDetailsFromUIMS(self):

        if self.browserName == "Google Chrome":
            # declaring webdriver
            try:
                chrome_options = chromeOptions()
                chrome_options.add_argument("--use-fake-ui-for-media-stream")
                chrome_options.add_argument('log-level=3')
                chrome_options.add_argument("--start-maximized")
                chrome_options.add_argument('--headless')
                prefs = {"download.default_directory": str(os.getcwd())}
                chrome_options.add_experimental_option("prefs", prefs)
                driver = webdriver.Chrome(options=chrome_options)
            except:
                logger.error("Check if chromedrivers are in the path")
                input()
                exit()

        elif self.browserName == "Brave":
            BraveFlag = False

            try:
                brave_path = "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"
                brave_options = chromeOptions()
                brave_options.add_argument("--use-fake-ui-for-media-stream")
                brave_options.add_argument('log-level=3')
                brave_options.add_argument("--start-maximized")
                brave_options.add_argument('--headless')
                prefs = {"download.default_directory": str(os.getcwd())}
                brave_options.add_experimental_option("prefs", prefs)
                brave_options.binary_location = brave_path
                driver = webdriver.Chrome(chrome_options=brave_options)
                BraveFlag = True
            except:
                logger.error("Check if chromedrivers are in the path")

            if not BraveFlag:
                try:
                    brave_path = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"
                    brave_options = chromeOptions()
                    brave_options.add_argument(
                        "--use-fake-ui-for-media-stream")
                    brave_options.add_argument('log-level=3')
                    brave_options.add_argument("--start-maximized")
                    brave_options.add_argument('--headless')
                    prefs = {"download.default_directory": str(os.getcwd())}
                    brave_options.add_experimental_option("prefs", prefs)
                    brave_options.binary_location = brave_path
                    driver = webdriver.Chrome(chrome_options=brave_options)
                except:
                    logger.error("Check if chromedrivers are in the path")
                    logger.warning("Exiting ..... ")
                    input()
                    exit()

        elif self.browserName == "Mozilla Firefox":
            try:
                firefox_options = FirefoxOptions()
                firefox_options.add_argument("--use-fake-ui-for-media-stream")
                firefox_options.add_argument('log-level=3')
                firefox_options.add_argument("--start-maximized")
                firefox_options.add_argument('--headless')
                profile = webdriver.FirefoxProfile()
                profile.set_preference("browser.download.folderList", 2)
                profile.set_preference(
                    "browser.download.manager.showWhenStarting", False)
                profile.set_preference("browser.download.dir",
                                       str(os.getcwd()))
                profile.set_preference(
                    "browser.helperApps.neverAsk.saveToDisk", "text/csv")
                driver = webdriver.Firefox(options=firefox_options,
                                           firefox_profile=profile)
            except:
                logger.error("Check if geeckodriver are in the path")
                input()
                exit()

        networkAvaliable = connectionCheck()
        if not networkAvaliable:
            is_connected()

        logger.info("Logging into UIMS")
        counter = 0

        # entering username and password in CUIMS
        while (networkAvaliable):
            try:
                driver.get('https://uims.cuchd.in/uims/')
                WebDriverWait(driver, 20).until(
                    EC.element_to_be_clickable(
                        (By.XPATH, "//input[@name='txtUserId']"))).send_keys(
                            self.userName)
                WebDriverWait(driver, 20).until(
                    EC.element_to_be_clickable(
                        (By.XPATH, "//input[@name='btnNext']"))).click()
                WebDriverWait(driver, 20).until(
                    EC.element_to_be_clickable(
                        (By.XPATH,
                         "//input[@name='txtLoginPassword']"))).send_keys(
                             self.password)
                WebDriverWait(driver, 20).until(
                    EC.element_to_be_clickable(
                        (By.XPATH, "//input[@name='btnLogin']"))).click()
            except:
                logger.error("Problem Logging in UIMS")
                is_connected()

            # Checking if username and password are correct
            driver.get('https://uims.cuchd.in/UIMS/StudentHome.aspx')
            currentURL = str(driver.current_url)
            if currentURL != "https://uims.cuchd.in/UIMS/StudentHome.aspx":
                counter += 1
                logger.error("Username or Password is incorrect")
                getDetailsOBJ = GetUserDetails("userData.txt")
                newDetails = getDetailsOBJ.getCorrectDetails()
                self.userName = newDetails['username']
                self.password = newDetails['password']

                # User unable to give valid input
                if newDetails['failInput']:
                    driver.close()
                    input()
                    exit()

                logger.info(
                    f"Username: {self.userName}  Password: {self.password}")
            else:
                logger.info("Logged is successfully to UIMS")
                break

            # valid input but not valid cridentials for UIMS
            if counter == 3:
                threeFailedInputs()

        # going to time table page
        logger.info("Getting your Time Table")
        counter = 0

        while (networkAvaliable):
            counter += 1
            try:
                driver.get('https://uims.cuchd.in/UIMS/frmMyTimeTable.aspx')
                # checking if time table page is opned
                WebDriverWait(driver, 60).until(
                    EC.element_to_be_clickable(
                        (By.XPATH,
                         f"//span[text()='My Time Table']"))).click()
                break
            except:
                logger.error("Problem fetching Time Table")
                is_connected()

            if counter == 5:
                fiveFailedAttempts()

        html = driver.page_source
        soup = BeautifulSoup(html, "lxml")
        ControlID = str(soup(text=re.compile('ControlID')))[1722:1754]

        # downloading time table csv file
        while (networkAvaliable):
            url = f'https://uims.cuchd.in/UIMS/Reserved.ReportViewerWebControl.axd?ReportSession=ycmrf5jtz5d1gjjcfk4bleib&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID={ControlID}&OpType=Export&FileName=rptStudentTimeTable&ContentDisposition=OnlyHtmlInline&Format=CSV'
            try:
                if self.browserName == "Mozilla Firefox":
                    driver.set_page_load_timeout(5)
                driver.get(url)
                time.sleep(2)
                break
            except TimeoutException:
                break
            except:
                logger.error("Problem downloading Time Table")
                is_connected()

        driver.quit()
Ejemplo n.º 15
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