コード例 #1
0
def browser(request, browser_config):
    caps = {}
    caps.update(browser_config)

    build_tag = "nerodia-build"
    username = environ.get('SAUCE_USERNAME', None)
    access_key = environ.get('SAUCE_ACCESS_KEY', None)

    selenium_endpoint = "http://ondemand.saucelabs.com/wd/hub"

    caps['username'] = username
    caps['accesskey'] = access_key
    caps['name'] = request.node.name
    caps['build'] = build_tag

    executor = RemoteConnection(selenium_endpoint, resolve_ip=False)
    remote = webdriver.Remote(command_executor=executor,
                              desired_capabilities=caps)

    browser = Browser(browser=remote, desired_capabilities=caps)
    yield browser

    sauce_result = "failed" if request.node.rep_call.failed else "passed"
    browser.execute_script("sauce:job-result={}".format(sauce_result))
    browser.quit()
コード例 #2
0
ファイル: browser_tests.py プロジェクト: CTimmerman/nerodia
    def test_passes_capabilities_to_selenium(self, browser_manager):
        browser_name = browser_manager.name
        caps_name = 'internetexplorer' if browser_name == 'ie' else browser_name
        caps = getattr(DesiredCapabilities, caps_name.upper()).copy()
        caps.update({'acceptInsecureCerts': True})
        browser = Browser(browser_name, desired_capabilities=caps)
        insecure = browser.wd.capabilities['acceptInsecureCerts']
        browser.quit()

        assert insecure is True
コード例 #3
0
ファイル: browser_tests.py プロジェクト: CTimmerman/nerodia
 def test_takes_listener_as_argument(self, browser_manager):
     from selenium.webdriver.support.abstract_event_listener import AbstractEventListener
     from selenium.webdriver.support.event_firing_webdriver import EventFiringWebDriver
     ael = AbstractEventListener()
     new_browser = None
     try:
         new_browser = Browser(**dict(browser_manager.kwargs, listener=ael))
         assert isinstance(new_browser.wd, EventFiringWebDriver)
     finally:
         if new_browser:
             new_browser.quit()
コード例 #4
0
ファイル: browser_tests.py プロジェクト: CTimmerman/nerodia
    def test_remote_when_passed_url_arg(self, browser, browser_manager):
        from selenium.webdriver.remote.webdriver import RemoteConnection, WebDriver
        caps_name = 'internetexplorer' if browser.name == 'internet explorer' else browser.name
        caps = getattr(DesiredCapabilities, caps_name.upper()).copy()
        browser = Browser(browser_manager.name, desired_capabilities=caps)
        driver = browser.wd
        executor = driver.command_executor
        browser.quit()

        assert driver.__class__.__name__ == WebDriver.__name__
        assert driver.name == caps.get('browserName')
        assert isinstance(executor, RemoteConnection)
コード例 #5
0
class Login():
    def __init__(self):
        self.browser = {}

    @keyword
    def open_browser(self, name='chrome'):
        self.browser = Browser(browser=name)

    @keyword
    def open_on_sauce(self):
        caps = {
            'platformName': 'Windows 10',
            'plaformVersion': 'latest',
            'browserName': 'chrome'
        }

        username = environ.get('SAUCE_USERNAME', None)
        access_key = environ.get('SAUCE_ACCESS_KEY', None)

        selenium_endpoint = "http://ondemand.saucelabs.com/wd/hub"

        caps['username'] = username
        caps['accesskey'] = access_key
        caps['name'] = 'Robot Nerodia - Login'

        executor = RemoteConnection(selenium_endpoint, resolve_ip=False)
        remote = webdriver.Remote(command_executor=executor,
                                  desired_capabilities=caps)

        self.browser = Browser(browser=remote, desired_capabilities=caps)

    @keyword
    def go_to_login(self):
        self.browser.goto(BASE_TEST_URL + "login")

    @keyword
    def login_as(self, username, password):
        self.browser.input(id='username').send_keys(username)
        self.browser.input(id='password').send_keys(password)
        self.browser.button(class_name='radius').click()

    @keyword
    def is_error_message_visible(self):
        assert self.browser.element(class_name='error').present

    @keyword
    def is_login_successful(self):
        assert self.browser.element(class_name='success').present

    @keyword
    def close_browser(self):
        self.browser.quit()
コード例 #6
0
ファイル: browser_tests.py プロジェクト: CTimmerman/nerodia
    def test_accepts_firefox_profile(self, browser_manager, webserver):
        from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
        home_page = webserver.path_for('special_chars.html')

        profile = FirefoxProfile()
        profile.set_preference('browser.startup.homepage', home_page)
        profile.set_preference('browser.startup.page', 1)
        kwargs = browser_manager.kwargs.copy()
        kwargs['options'] = {'profile': profile}

        new_browser = Browser(**kwargs)
        try:
            assert new_browser.url == home_page
        finally:
            new_browser.quit()
コード例 #7
0
def browser(request):
    caps = {
        "browserName": "Chrome",
        "sauce:options": {
            "browserName": "Chrome",
            "platformName": "Windows 10",
            "browserVersion": "latest"
        }
    }

    username = os.environ['SAUCE_USERNAME']
    access_key = os.environ['SAUCE_ACCESS_KEY']

    remote_url = 'https://{}:{}@ondemand.saucelabs.com/wd/hub/'.format(username, access_key)

    remote = webdriver.Remote(command_executor=remote_url, desired_capabilities=caps)
    driver = Browser(browser=remote, desired_capabilities=caps)
    driver.goto(TEST_APP_URL)
    yield driver

    driver.quit()
コード例 #8
0
ファイル: browser_tests.py プロジェクト: CTimmerman/nerodia
    def test_accepts_browser_options(self, browser_manager, mocker):
        from importlib import import_module
        browser_name = browser_manager.name
        module = import_module(
            'selenium.webdriver.{}.options'.format(browser_name))
        opts = module.Options()

        mock = mocker.patch(
            'selenium.webdriver.{}.webdriver.WebDriver'.format(browser_name))

        caps_name = 'internetexplorer' if browser_name == 'ie' else browser_name
        caps = getattr(DesiredCapabilities, caps_name.upper()).copy()

        browser = Browser(browser_name, options=opts)
        browser.quit()

        key = 'desired_capabilities' if browser_name in ['safari', 'chrome'
                                                         ] else 'capabilities'

        kwargs = {}
        kwargs[key] = caps
        kwargs['options'] = opts
        mock.assert_called_once_with(**kwargs)
コード例 #9
0
ファイル: form_example.py プロジェクト: orlandocsosa/nerodia
# Radio buttons can be selected with `text` or `label` locators
browser.radio(text='Canada').set()

# Date Field elements accept Date objects
birthday = fake.date_of_birth()
browser.date_field(id='address_birthday').set(birthday)

age = fake.date_time_this_year().year - birthday.year
browser.text_field(id='address_age').set(age)

browser.text_field(id='address_website').set(fake.url())

# File Field elements upload file with the '#set' method, but require the full system path
file_name = 'nerodia_example.txt'
file = open(file_name, 'w+').close()
path = os.path.realpath(file_name)
browser.file_field(id='address_picture').set(path)

# Checkboxes can be selected by 'label' or 'text' locators
browser.checkbox(label='Dancing').set()
browser.checkbox(name='address[interest_climb]').set()

browser.textarea(id='address_note').set(
    'See, filling out a form with Nerodia is as easy as with Watir!')
browser.button(data_test='submit').click()

sleep(3)

browser.quit()