当前位置: 首页>>代码示例>>Python>>正文


Python Utils.build_url方法代码示例

本文整理汇总了Python中utils.Utils.build_url方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.build_url方法的具体用法?Python Utils.build_url怎么用?Python Utils.build_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.Utils的用法示例。


在下文中一共展示了Utils.build_url方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Base

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import build_url [as 别名]
class Base(object):
    def __init__(self, logger, results_folder, base_url=r'http://localhost/',
                 driver=None, driver_wait=default_driver_wait, delay_secs=0):
        if driver is None:
            assert 'Driver is invalid or was not provided.'

        self.driver_wait = driver_wait
        self.base_url = base_url
        self.driver = driver
        self.chain = ActionChains(self.driver)
        self.logger = logger
        self.utils = Utils(delay_secs)
        self.results_folder = results_folder

    def go(self, relative_url=''):
        full_url = self.utils.build_url(self.base_url, relative_url)
        print full_url
        try:
            self.logger.info("Getting %s" % full_url)
            self.driver.get(full_url)
        except Exception:
            self.logger.info("Unexpected error running: %s" % full_url)
            self.logger.info("Exception type: %s" % sys.exc_info()[0])
            self.logger.info("Currently at: %s" % (self.driver.current_url))
            self.get_screenshot(full_url)
            raise

    def wait(self, driver_wait=default_driver_wait):
        return WebDriverWait(self.driver, driver_wait)

    def close_browser(self):
        self.utils.zzz(1)
        self.driver.quit()

    def sleep(self, time):
        self.utils.zzz(float(time))

    def get_screenshot(self, filename=None):
        if filename is None:
            filename = self.driver.current_url

        filename = "%s" % (filename.replace('/', '_'))
        full_path = '%s/%s.%s' % (self.results_folder, filename, 'png')
        self.logger.info("Saving screenshot to %s" % full_path)
        self.driver.save_screenshot(full_path)

    def get_page_title(self):
        return (self.driver.title)

    def get_current_url(self):
        return (self.driver.current_url)

    def scroll_to_element(self, element):
        self.driver.execute_script(
            "window.scrollTo({0}, {1});".format(element.location['x'], 
                                                element.location['y']
                                               )
        )
开发者ID:imuchnik,项目名称:cfgov-refresh,代码行数:60,代码来源:base.py

示例2: Base

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import build_url [as 别名]
class Base(object):
    def __init__(self, logger, results_folder, base_url=r'http://localhost/',
                 driver=None, driver_wait=default_driver_wait, delay_secs=0):
        if driver is None:
            assert 'Driver is invalid or was not provided.'

        self.driver_wait = driver_wait
        self.base_url = base_url
        self.driver = driver
        self.chain = ActionChains(self.driver)
        self.logger = logger
        self.utils = Utils(delay_secs)
        self.results_folder = results_folder

    def go(self, relative_url=''):
        full_url = self.utils.build_url(self.base_url, relative_url)
        try:
            self.logger.info("Getting %s" % full_url)
            self.driver.get(full_url)
        except Exception:
            self.logger.info("Unexpected error running: %s" % full_url)
            self.logger.info("Exception type: %s" % sys.exc_info()[0])
            self.logger.info("Currently at: %s" % (self.driver.current_url))
            raise

    def wait(self, driver_wait=default_driver_wait):
        return WebDriverWait(self.driver, driver_wait)

    # Switch to the tab specified by relative_url
    # And return the page title
    def switch_to_new_tab(self, relative_url):
        for handle in self.driver.window_handles:
            self.driver.switch_to_window(handle)
            # Wait for the URL to display in the address bar
            WebDriverWait(self.driver, 5)\
                .until(lambda s: len(s.current_url) > 1)

            self.logger.info("Current url: %s" % self.driver.current_url)
            if relative_url in (self.driver.current_url):
                return self.driver.title
                self.driver.close()
                break

        return relative_url + " tab not found!"

    def close_browser(self):
        self.utils.zzz(1)
        self.driver.quit()

    def sleep(self, time):
        self.utils.zzz(float(time))

    def get_screenshot(self, filename=None):
        if filename is None:
            filename = self.driver.current_url

        filename = "%s" % (filename.replace('/', '_'))
        full_path = '%s/%s.%s' % (self.results_folder, filename, 'png')
        self.logger.info("Saving screenshot to %s" % full_path)
        self.driver.save_screenshot(full_path)

    def get_page_title(self):
        print "handles: %s" % self.driver.window_handles
        print "current handle: %s" % self.driver.current_window_handle
        print "current title: %s" % self.driver.title
        return self.driver.title

    def get_current_url(self):
        print "handles: %s" % self.driver.window_handles
        print "current handle: %s" % self.driver.current_window_handle
        print "current url: %s" % self.driver.current_url
        return self.driver.current_url

    def enter_month(self, month):
        month_input = self.driver.find_element_by_id('bd-month')
        month_input.send_keys(month)

    def enter_day(self, day):
        day_input = self.driver.find_element_by_id('bd-day')
        day_input.send_keys(day)

    def enter_year(self, year):
        year_input = self.driver.find_element_by_id('bd-year')
        year_input.send_keys(year)

    def enter_income(self, income):
        income_input = self.driver.find_element_by_id('salary-input')
        income_input.send_keys(income)

    def get_estimate(self):
        estimate_button = self.driver.find_element_by_xpath(get_estimates_button)
        estimate_button.click()
        Utils().zzz(1)

    def get_fra_result(self):
        select = self.driver.find_element_by_xpath(fra_result_text)
        return select.text

    def choose_retirement_age(self, retirement_age):
        age_selector = Select(self.driver.find_element_by_id("retirement-age-selector"))
#.........这里部分代码省略.........
开发者ID:Ooblioob,项目名称:retirement,代码行数:103,代码来源:base.py

示例3: Base

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import build_url [as 别名]
class Base(object):
    def __init__(self, logger, results_folder, base_url=r'http://localhost/',
                 driver=None, driver_wait=default_driver_wait, delay_secs=0):
        if driver is None:
            assert 'Driver is invalid or was not provided.'

        self.driver_wait = driver_wait
        self.base_url = base_url
        self.driver = driver
        self.chain = ActionChains(self.driver)
        self.logger = logger
        self.utils = Utils(delay_secs)
        self.results_folder = results_folder

    def go(self, relative_url=''):
        full_url = self.utils.build_url(self.base_url, relative_url)
        try:
            self.logger.info("Getting %s" % full_url)
            self.driver.get(full_url)
        except Exception:
            self.logger.info("Unexpected error running: %s" % full_url)
            self.logger.info("Exception type: %s" % sys.exc_info()[0])
            self.logger.info("Currently at: %s" % (self.driver.current_url))
            self.get_screenshot(full_url)
            raise

    def wait(self, driver_wait=default_driver_wait):
        return WebDriverWait(self.driver, driver_wait)

    # Switch to the tab specified by relative_url
    # And return the page title
    def switch_to_new_tab(self, relative_url):
        for handle in self.driver.window_handles:
            self.driver.switch_to_window(handle)
            # Wait for the URL to display in the address bar
            WebDriverWait(self.driver, 5)\
                .until(lambda s: len(s.current_url) > 1)

            self.logger.info("Current url: %s" % self.driver.current_url)
            if relative_url in (self.driver.current_url):
                return self.driver.title
                self.driver.close()
                break

        return relative_url + " tab not found!"

    def close_browser(self):
        self.utils.zzz(1)
        self.driver.quit()

    def sleep(self, time):
        self.utils.zzz(float(time))

    def get_screenshot(self, filename=None):
        if filename is None:
            filename = self.driver.current_url

        filename = "%s" % (filename.replace('/', '_'))
        full_path = '%s/%s.%s' % (self.results_folder, filename, 'png')
        self.logger.info("Saving screenshot to %s" % full_path)
        self.driver.save_screenshot(full_path)

    def get_page_title(self):
        return (self.driver.title)

    def get_current_url(self):
        return (self.driver.current_url)

    # # EMAIL SIGNUP
    # def set_email_address(self, email_address):
    #     element = self.driver.find_element_by_id(EMAIL)
    #     element.send_keys(email_address)

    # def click_signup_button(self):
    #     element = self.driver.find_element_by_xpath(SIGNUP)
    #     element.click()

    # def get_email_label(self):
    #     l_wait = 5
    #     # Wait for the label to display
    #     try:
    #         element = WebDriverWait(self.driver, self.driver_wait)\
    #             .until(EC.visibility_of_element_located((By.XPATH,
    #                                                      EMAIL_LBL)))
    #         return element.text
    #     except TimeoutException:
    #         return "Element NOT found!"

    # def is_multiple_email_labels(self):
    #     l_wait = 5
    #     # If the list has > 1 elements then multiple labels are displayed
    #     try:
    #         WebDriverWait(self.driver, l_wait)\
    #             .until(lambda s: len(s.find_elements(By.XPATH, EMAIL_LBL)) > 1)
    #         return True
    #     except TimeoutException:
    #         return False

    # def is_sign_button_visible(self):
    #     l_wait = 2
#.........这里部分代码省略.........
开发者ID:DarthDippy,项目名称:aat_demo,代码行数:103,代码来源:base.py

示例4: Base

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import build_url [as 别名]
class Base(object):
    def __init__(self, logger, results_folder, base_url=r'http://localhost/',
                 driver=None, driver_wait=default_driver_wait, delay_secs=0):
        if driver is None:
            assert 'Driver is invalid or was not provided.'

        self.driver_wait = driver_wait
        self.base_url = base_url
        self.driver = driver
        self.chain = ActionChains(self.driver)
        self.logger = logger
        self.utils = Utils(delay_secs)
        self.results_folder = results_folder

    def go(self, relative_url=''):
        full_url = self.utils.build_url(self.base_url, relative_url)
        try:
            self.logger.info("Getting %s" % full_url)
            self.driver.get(full_url)
        except Exception:
            self.logger.info("Unexpected error running: %s" % full_url)
            self.logger.info("Exception type: %s" % sys.exc_info()[0])
            self.logger.info("Currently at: %s" % (self.driver.current_url))
            self.get_screenshot(full_url)
            raise

    def wait(self, driver_wait=default_driver_wait):
        return WebDriverWait(self.driver, driver_wait)

    def close_browser(self):
        self.utils.zzz(1)
        self.driver.quit()

    def sleep(self, time):
        self.utils.zzz(float(time))

    def get_screenshot(self, filename=None):
        if filename is None:
            filename = self.driver.current_url

        filename = "%s" % (filename.replace('/', '_'))
        full_path = '%s/%s.%s' % (self.results_folder, filename, 'png')
        self.logger.info("Saving screenshot to %s" % full_path)
        self.driver.save_screenshot(full_path)

    def get_page_title(self):
        return (self.driver.title)

    def get_current_url(self):
        return (self.driver.current_url)

    # EMAIL SIGNUP
    def set_email_address(self, email_address):
        element = self.driver.find_element_by_id(EMAIL)
        element.send_keys(email_address)

    def click_signup_button(self):
        element = self.driver.find_element_by_xpath(SIGNUP)
        element.click()

    def get_email_label(self):
        msg = 'Element %s not found after %s secs' % (EMAIL_LBL,
                                                      self.driver_wait)
        # Wait for the label to display
        element = WebDriverWait(self.driver, self.driver_wait)\
            .until(EC.visibility_of_element_located((By.XPATH,
                                                    EMAIL_LBL)), msg)
        return element.text

    def is_multiple_email_labels(self):
        l_wait = 5
        # If the list has > 1 elements then multiple labels are displayed
        try:
            WebDriverWait(self.driver, l_wait)\
                .until(lambda s: len(s.find_elements(By.XPATH, EMAIL_LBL)) > 1)
            return True
        except TimeoutException:
            return False
开发者ID:ascott1,项目名称:owning-a-home,代码行数:80,代码来源:base.py

示例5: Base

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import build_url [as 别名]
class Base(object):
    def __init__(self, logger, results_folder, base_url=r'http://localhost/',
                 driver=None, driver_wait=default_driver_wait, delay_secs=0):
        if driver is None:
            assert 'Driver is invalid or was not provided.'

        self.driver_wait = driver_wait
        self.base_url = base_url
        self.driver = driver
        self.chain = ActionChains(self.driver)
        self.logger = logger
        self.utils = Utils(delay_secs)
        self.results_folder = results_folder

    def go(self, relative_url=''):
        full_url = self.utils.build_url(self.base_url, relative_url)
        try:
            self.logger.info("Getting %s" % full_url)
            self.driver.get(full_url)
        except Exception:
            self.logger.info("Unexpected error running: %s" % full_url)
            self.logger.info("Exception type: %s" % sys.exc_info()[0])
            self.logger.info("Currently at: %s" % (self.driver.current_url))
            raise

    def wait(self, driver_wait=default_driver_wait):
        return WebDriverWait(self.driver, driver_wait)

    # Switch to the tab specified by relative_url
    # And return the page title
    def switch_to_new_tab(self, relative_url):
        for handle in self.driver.window_handles:
            self.driver.switch_to_window(handle)
            # Wait for the URL to display in the address bar
            WebDriverWait(self.driver, 5)\
                .until(lambda s: len(s.current_url) > 1)

            self.logger.info("Current url: %s" % self.driver.current_url)
            if relative_url in (self.driver.current_url):
                return self.driver.title
                self.driver.close()
                break

        return relative_url + " tab not found!"

    def close_browser(self):
        self.utils.zzz(1)
        self.driver.quit()

    def sleep(self, time):
        self.utils.zzz(float(time))

    def get_screenshot(self, filename=None):
        if filename is None:
            filename = self.driver.current_url

        filename = "%s" % (filename.replace('/', '_'))
        full_path = '%s/%s.%s' % (self.results_folder, filename, 'png')
        self.logger.info("Saving screenshot to %s" % full_path)
        self.driver.save_screenshot(full_path)

    def get_page_title(self):
        return (self.driver.title)

    def get_current_url(self):
        return (self.driver.current_url)

    def choose_age(self, age):
        select = Select(self.driver.find_element_by_id(ret_age_selector))
        select.select_by_visible_text(age)
开发者ID:OrlandoSoto,项目名称:retirement,代码行数:72,代码来源:base.py


注:本文中的utils.Utils.build_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。