コード例 #1
0
ファイル: __init__.py プロジェクト: blairwind/blog_rf
 def __init__(self,
              timeout=5.0,
              implicit_wait=0.0,
              run_on_failure='Capture Page Screenshot',
              screenshot_root_directory=None):
     self.timeout = timestr_to_secs(timeout)
     self.implicit_wait = timestr_to_secs(implicit_wait)
     self.speed = 0.0
     self.run_on_failure_keyword \
         = RunOnFailureKeywords.resolve_keyword(run_on_failure)
     self._running_on_failure_keyword = False
     self.screenshot_root_directory = screenshot_root_directory
     libraries = [
         AlertKeywords(self),
         BrowserManagementKeywords(self),
         CookieKeywords(self),
         ElementKeywords(self),
         FormElementKeywords(self),
         FrameKeywords(self),
         JavaScriptKeywords(self),
         RunOnFailureKeywords(self),
         ScreenshotKeywords(self),
         SelectElementKeywords(self),
         TableElementKeywords(self),
         WaitingKeywords(self),
         WindowKeywords(self),
         KeyboardKeywords(self)
     ]
     self._drivers = WebDriverCache()
     DynamicCore.__init__(self, libraries)
     self.ROBOT_LIBRARY_LISTENER = LibraryListener()
     self._element_finder = ElementFinder(self)
コード例 #2
0
    def __init__(self,
                 timeout=5.0,
                 implicit_wait=0.0,
                 run_on_failure='Capture Page Screenshot',
                 screenshot_root_directory=None):
        """SeleniumLibrary can be imported with optional arguments.

        `timeout` is the default timeout used to wait for all waiting actions.
        It can be later set with `Set Selenium Timeout`.

        'implicit_wait' is the implicit timeout that Selenium waits when
        looking for elements.
        It can be later set with `Set Selenium Implicit Wait`.
        See `WebDriver: Advanced Usage`__ section of the SeleniumHQ documentation
        for more information about WebDriver's implicit wait functionality.

        __ http://seleniumhq.org/docs/04_webdriver_advanced.html#explicit-and-implicit-waits

        `run_on_failure` specifies the name of a keyword (from any available
        libraries) to execute when a SeleniumLibrary keyword fails. By default
        `Capture Page Screenshot` will be used to take a screenshot of the current page.
        Using the value "Nothing" will disable this feature altogether. See
        `Register Keyword To Run On Failure` keyword for more information about this
        functionality.

        `screenshot_root_directory` specifies the default root directory that screenshots should be
        stored in. If not provided the default directory will be where robotframework places its logfile.

        Examples:
        | Library `|` SeleniumLibrary `|` 15                                            | # Sets default timeout to 15 seconds                                       |
        | Library `|` SeleniumLibrary `|` 0 `|` 5                                       | # Sets default timeout to 0 seconds and default implicit_wait to 5 seconds |
        | Library `|` SeleniumLibrary `|` 5 `|` run_on_failure=Log Source               | # Sets default timeout to 5 seconds and runs `Log Source` on failure       |
        | Library `|` SeleniumLibrary `|` implicit_wait=5 `|` run_on_failure=Log Source | # Sets default implicit_wait to 5 seconds and runs `Log Source` on failure |
        | Library `|` SeleniumLibrary `|` timeout=10      `|` run_on_failure=Nothing    | # Sets default timeout to 10 seconds and does nothing on failure           |
        """
        self.timeout = timestr_to_secs(timeout)
        self.implicit_wait = timestr_to_secs(implicit_wait)
        self.speed = 0.0
        self.run_on_failure_keyword \
            = RunOnFailureKeywords.resolve_keyword(run_on_failure)
        self._running_on_failure_keyword = False
        self.screenshot_root_directory = screenshot_root_directory
        libraries = [
            AlertKeywords(self),
            BrowserManagementKeywords(self),
            RunOnFailureKeywords(self),
            ElementKeywords(self),
            TableElementKeywords(self),
            FormElementKeywords(self),
            SelectElementKeywords(self),
            JavaScriptKeywords(self),
            CookieKeywords(self),
            ScreenshotKeywords(self),
            WaitingKeywords(self)
        ]
        self._browsers = BrowserCache()
        DynamicCore.__init__(self, libraries)
        self.ROBOT_LIBRARY_LISTENER = LibraryListener()
        self.element_finder = ElementFinder(self)
        self._table_element_finder = TableElementFinder(self)
コード例 #3
0
    def __init__(self,
                 timeout=5.0,
                 implicit_wait=0.0,
                 run_on_failure='Capture Page Screenshot',
                 screenshot_root_directory=None,
                 plugins=None,
                 event_firing_webdriver=None):
        """SeleniumLibrary can be imported with several optional arguments.

        - ``timeout``:
          Default value for `timeouts` used with ``Wait ...`` keywords.
        - ``implicit_wait``:
          Default value for `implicit wait` used when locating elements.
        - ``run_on_failure``:
          Default action for the `run-on-failure functionality`.
        - ``screenshot_root_directory``:
          Location where possible screenshots are created. If not given,
          the directory where the log file is written is used.
        - ``plugins``:
          Allows extending the SeleniumLibrary with external Python classes.
        - ``event_firing_webdriver``:
          Class for wrapping Selenium with
          [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.event_firing_webdriver.html#module-selenium.webdriver.support.event_firing_webdriver|EventFiringWebDriver]
        """
        self.timeout = timestr_to_secs(timeout)
        self.implicit_wait = timestr_to_secs(implicit_wait)
        self.speed = 0.0
        self.run_on_failure_keyword \
            = RunOnFailureKeywords.resolve_keyword(run_on_failure)
        self._running_on_failure_keyword = False
        self.screenshot_root_directory = screenshot_root_directory
        self._element_finder = ElementFinder(self)
        self._plugin_keywords = []
        libraries = [
            AlertKeywords(self),
            BrowserManagementKeywords(self),
            CookieKeywords(self),
            ElementKeywords(self),
            FormElementKeywords(self),
            FrameKeywords(self),
            JavaScriptKeywords(self),
            RunOnFailureKeywords(self),
            ScreenshotKeywords(self),
            SelectElementKeywords(self),
            TableElementKeywords(self),
            WaitingKeywords(self),
            WindowKeywords(self)
        ]
        if is_truthy(plugins):
            plugin_libs = self._parse_plugins(plugins)
            libraries = libraries + plugin_libs
        self._drivers = WebDriverCache()
        DynamicCore.__init__(self, libraries)
        self.ROBOT_LIBRARY_LISTENER = LibraryListener()
        if is_truthy(event_firing_webdriver):
            self.event_firing_webdriver = self._parse_listener(
                event_firing_webdriver)
        else:
            self.event_firing_webdriver = None
        self._running_keyword = None
コード例 #4
0
    def __init__(self,
                 timeout=5.0,
                 implicit_wait=0.0,
                 run_on_failure='Capture Page Screenshot',
                 screenshot_root_directory=None,
                 demo=False):
        """SeleniumLibrary can be imported with several optional arguments.

        - ``timeout``:
          Default value for `timeouts` used with ``Wait ...`` keywords.
        - ``implicit_wait``:
          Default value for `implicit wait` used when locating elements.
        - ``run_on_failure``:
          Default action for the `run-on-failure functionality`.
        - ``screenshot_root_directory``:
          Location where possible screenshots are created. If not given,
          the directory where the log file is written is used.
        - ``Demo``
          Flash the element before click, input and etc actions. Set value
          True if you want it.
        """
        self.timeout = timestr_to_secs(timeout)
        self.implicit_wait = timestr_to_secs(implicit_wait)
        self.speed = 0.0
        self.run_on_failure_keyword \
            = RunOnFailureKeywords.resolve_keyword(run_on_failure)
        self._running_on_failure_keyword = False
        self.screenshot_root_directory = screenshot_root_directory
        self.demo = demo
        libraries = [
            AlertKeywords(self),
            BrowserManagementKeywords(self),
            CookieKeywords(self),
            ElementKeywords(self),
            FormElementKeywords(self),
            FrameKeywords(self),
            JavaScriptKeywords(self),
            RunOnFailureKeywords(self),
            ScreenshotKeywords(self),
            SelectElementKeywords(self),
            TableElementKeywords(self),
            WaitingKeywords(self),
            WindowKeywords(self)
        ]
        self._drivers = WebDriverCache()
        DynamicCore.__init__(self, libraries)
        self.ROBOT_LIBRARY_LISTENER = LibraryListener()
        self._element_finder = ElementFinder(self)
コード例 #5
0
 def setUp(self):
     ctx = mock()
     ctx._browser = mock()
     self.cookie = CookieKeywords(ctx)
     self.ctx = ctx
     self.default_cookie = {'name': 'name', 'value': 'value'}
コード例 #6
0
class KeywordArgumentsCookieTest(unittest.TestCase):
    def setUp(self):
        ctx = mock()
        ctx._browser = mock()
        self.cookie = CookieKeywords(ctx)
        self.ctx = ctx
        self.default_cookie = {'name': 'name', 'value': 'value'}

    def tearDown(self):
        unstub()

    def test_add_cookie_default(self):
        self.cookie.add_cookie('name', 'value')
        verify(self.ctx._browser).add_cookie(self.default_cookie)

    def test_add_cookie_secure_true(self):
        self.cookie.add_cookie('name',
                               'value',
                               path='None',
                               domain='None',
                               secure='True')
        cookie = self.default_cookie
        cookie['secure'] = 'True'
        verify(self.ctx._browser).add_cookie(cookie)

    def test_add_cookie_secure_false(self):
        self.cookie.add_cookie('name',
                               'value',
                               path='None',
                               domain='None',
                               secure='None')
        verify(self.ctx._browser).add_cookie(self.default_cookie)

    def test_add_cookie_domain_true(self):
        self.cookie.add_cookie('name',
                               'value',
                               path='None',
                               domain='MyDomain',
                               secure=None)
        cookie = self.default_cookie
        cookie['domain'] = 'MyDomain'
        verify(self.ctx._browser).add_cookie(cookie)

    def test_add_cookie_domain_false(self):
        self.cookie.add_cookie('name',
                               'value',
                               path='None',
                               domain='False',
                               secure=None)
        verify(self.ctx._browser).add_cookie(self.default_cookie)

    def test_add_cookie_path_true(self):
        self.cookie.add_cookie('name',
                               'value',
                               path='/foo/bar',
                               domain=None,
                               secure=None)
        cookie = self.default_cookie
        cookie['path'] = '/foo/bar'
        verify(self.ctx._browser).add_cookie(cookie)

    def test_add_cookie_path_false(self):
        self.cookie.add_cookie('name',
                               'value',
                               path='None',
                               domain=None,
                               secure=None)
        verify(self.ctx._browser).add_cookie(self.default_cookie)
コード例 #7
0
 def setUp(self):
     self.ctx = mock()
     self.ctx.driver = self.driver = mock()
     self.cookie = CookieKeywords(self.ctx)
     self.default_cookie = {'name': 'name', 'value': 'value'}
コード例 #8
0
def cookie(ctx):
    return CookieKeywords(ctx)
 def setUp(self):
     self.ctx = mock()
     self.ctx.browser = self.browser = mock()
     self.cookie = CookieKeywords(self.ctx)
     self.default_cookie = {'name': 'name', 'value': 'value'}
class KeywordArgumentsCookieTest(unittest.TestCase):

    def setUp(self):
        self.ctx = mock()
        self.ctx.browser = self.browser = mock()
        self.cookie = CookieKeywords(self.ctx)
        self.default_cookie = {'name': 'name', 'value': 'value'}

    def tearDown(self):
        unstub()

    def test_add_cookie_default(self):
        self.cookie.add_cookie('name', 'value')
        verify(self.browser).add_cookie(self.default_cookie)

    def test_add_cookie_secure_true(self):
        self.cookie.add_cookie('name', 'value', path='None', domain='None',
                               secure='True')
        cookie = self.default_cookie
        cookie['secure'] = 'True'
        verify(self.browser).add_cookie(cookie)

    def test_add_cookie_secure_false(self):
        self.cookie.add_cookie('name', 'value', path='None', domain='None',
                               secure='None')
        verify(self.browser).add_cookie(self.default_cookie)

    def test_add_cookie_domain_true(self):
        self.cookie.add_cookie('name', 'value', path='None', domain='MyDomain',
                               secure=None)
        cookie = self.default_cookie
        cookie['domain'] = 'MyDomain'
        verify(self.browser).add_cookie(cookie)

    def test_add_cookie_domain_false(self):
        self.cookie.add_cookie('name', 'value', path='None', domain='False',
                               secure=None)
        verify(self.browser).add_cookie(self.default_cookie)

    def test_add_cookie_path_true(self):
        self.cookie.add_cookie('name', 'value', path='/foo/bar', domain=None,
                               secure=None)
        cookie = self.default_cookie
        cookie['path'] = '/foo/bar'
        verify(self.browser).add_cookie(cookie)

    def test_add_cookie_path_false(self):
        self.cookie.add_cookie('name', 'value', path='None', domain=None,
                               secure=None)
        verify(self.browser).add_cookie(self.default_cookie)
コード例 #11
0
ファイル: __init__.py プロジェクト: haiducnguyen17/CoreFW
import os
from SeleniumLibrary import SeleniumLibrary
from SeleniumLibrary.keywords import (
    AlertKeywords, BrowserManagementKeywords, CookieKeywords, ElementKeywords,
    FormElementKeywords, FrameKeywords, JavaScriptKeywords,
    RunOnFailureKeywords, ScreenshotKeywords, SelectElementKeywords,
    TableElementKeywords, WaitingKeywords, WebDriverCache, WindowKeywords)
from robot.libraries.OperatingSystem import OperatingSystem

root = os.path.dirname(os.path.abspath(__file__)) + "\\.."
SL = SeleniumLibrary()
OS = OperatingSystem()

browserManagementKeywords = BrowserManagementKeywords(SL)
cookieKeywords = CookieKeywords(SL)
frameKeywords = FrameKeywords(SL)
javaScriptKeywords = JavaScriptKeywords(SL)
screenshotKeywords = ScreenshotKeywords(SL)
elementKeywords = ElementKeywords(SL)
formElementKeywords = FormElementKeywords(SL)
waitingKeywords = WaitingKeywords(SL)
windowKeywords = WindowKeywords(SL)
selectElementKeywords = SelectElementKeywords(SL)
tableElementKeywords = TableElementKeywords(SL)
コード例 #12
0
ファイル: __init__.py プロジェクト: beyfound/SeleniumLibrary
    def __init__(self,
                 timeout=5.0,
                 implicit_wait=0.0,
                 run_on_failure='Capture Page Screenshot',
                 screenshot_root_directory=None,
                 plugins=None):
        """SeleniumLibrary can be imported with several optional arguments.

        - ``timeout``:
          Default value for `timeouts` used with ``Wait ...`` keywords.
        - ``implicit_wait``:
          Default value for `implicit wait` used when locating elements.
        - ``run_on_failure``:
          Default action for the `run-on-failure functionality`.
        - ``screenshot_root_directory``:
          Location where possible screenshots are created. If not given,
          the directory where the log file is written is used.
        - ``plugins``:
          Allows extending the SeleniumLibrary with external Python classes.
        """
        self.timeout = timestr_to_secs(timeout)
        self.implicit_wait = timestr_to_secs(implicit_wait)
        self.speed = 0.0
        self.run_on_failure_keyword \
            = RunOnFailureKeywords.resolve_keyword(run_on_failure)
        self._running_on_failure_keyword = False
        self.screenshot_root_directory = screenshot_root_directory
        self._element_finder = ElementFinder(self)
        self._plugin_keywords = []
        libraries = [
            AlertKeywords(self),
            BrowserManagementKeywords(self),
            CookieKeywords(self),
            ElementKeywords(self),
            FormElementKeywords(self),
            FrameKeywords(self),
            JavaScriptKeywords(self),
            RunOnFailureKeywords(self),
            ScreenshotKeywords(self),
            SelectElementKeywords(self),
            TableElementKeywords(self),
            WaitingKeywords(self),
            WindowKeywords(self)
        ]
        if is_truthy(plugins):
            parsed_plugins = self._string_to_modules(plugins)
            for index, plugin in enumerate(
                    self._import_modules(parsed_plugins)):
                if not isclass(plugin):
                    message = "Importing test library: '%s' failed." % parsed_plugins[
                        index].plugin
                    raise DataError(message)
                plugin = plugin(self, *parsed_plugins[index].args,
                                **parsed_plugins[index].kw_args)
                if not isinstance(plugin, LibraryComponent):
                    message = 'Plugin does not inherit SeleniumLibrary.base.LibraryComponent'
                    raise PluginError(message)
                self._store_plugin_keywords(plugin)
                libraries.append(plugin)
        self._drivers = WebDriverCache()
        DynamicCore.__init__(self, libraries)
        self.ROBOT_LIBRARY_LISTENER = LibraryListener()