Ejemplo n.º 1
0
    def test_filter_tasks(self):
        browser.open('https://todomvc4tasj.herokuapp.com/')
        clear_completed_js_loaded = "return $._data($('#clear-completed').get(0), 'events').hasOwnProperty('click')"
        browser.wait_to(have.js_returned(True, clear_completed_js_loaded))
        browser.wait_to(have.title(u'TroopJS • TodoMVC'))

        browser.element('#new-todo').should(
            be.enabled).set_value('a').press_enter()
        browser.element('#new-todo').should(
            be.enabled).set_value('b').press_enter()
        browser.element('#new-todo').should(
            be.enabled).set_value('c').press_enter()

        browser.all("#todo-list>li").should(have.texts('a', 'b', 'c'))

        browser.all("#todo-list>li").element_by(
            have.exact_text('b')).find(".toggle").click()

        browser.element(by.link_text("Active")).click()
        browser.all("#todo-list>li").filtered_by(be.visible).should(
            have.texts('a', 'c'))

        browser.element(by.link_text("Completed")).click()
        browser.all("#todo-list>li").filtered_by(be.visible).should(
            have.texts('b'))
    def test_selene_demo(self):
        tasks = browser.all("#todo-list>li")
        active_tasks = tasks.filtered_by(have.css_class("active"))

        browser.open(app_url)
        browser.should(have.js_returned(True, is_TodoMVC_loaded))

        for task_text in ["1", "2", "3"]:
            browser.element("#new-todo").set_value(task_text).press_enter()
        tasks.should(have.texts("1", "2",
                                "3")).should_each(have.css_class("active"))
        browser.element("#todo-count").should(have.text('3'))

        tasks[2].element(".toggle").click()
        active_tasks.should(have.texts("1", "2"))
        active_tasks.should(have.size(2))

        tasks.filtered_by(have.css_class("completed")).should(have.texts("3"))
        tasks.element_by(not_(have.css_class("completed"))).should(
            have.text("1"))
        tasks.filtered_by(not_(have.css_class("completed"))).should(
            have.texts("1", "2"))

        browser.element(by.link_text("Active")).click()
        tasks[:2].should(have.texts("1", "2"))
        tasks[2].should(be.hidden)

        browser.element(by.id("toggle-all")).click()
        browser.element("//*[@id='clear-completed']").click()
        tasks.should(be.empty)
Ejemplo n.º 3
0
def test_search():
    browser.open('https://www.ecosia.org/')
    browser.element(by.name('q')).type('github yashaka selene').press_enter()

    browser.all('.result').first.element('.result-url').click()

    browser.should(have.title_containing('yashaka/selene'))
Ejemplo n.º 4
0
def test_results_accuracy():
    browser.open('https://www.ecosia.org/')

    browser.element('[name=q]').type('yashaka selene').press_enter()
    browser.all('.result').first.click()

    browser.all('[href="/yashaka/selene"]').should(have.size(3))
Ejemplo n.º 5
0
def test_can_init_default_browser_on_visit():
    browser.open(empty_page)
    GivenPage(browser.driver).opened_with_body('''
        <h1 id="header">Selene</h1>''')

    browser.element("#header").should(have.exact_text("Selene"))
    assert browser.driver.name == 'chrome'
Ejemplo n.º 6
0
def test_duckduckgo():
    """
    Straightforward/PageObjectLess style
    ===================================

    GO FOR:
    * KISS (Keep It Simple Stupid), straightforward style
      * easy for newbies in automation (no need to learn modules/OOP(classes))
      * easy for some DEVs if they will use these tests (and they should!)
        they know selectors and internals of app they develop
        hence, building more abstractions (modules/classes) on top of more
        low level straightforward code (like below) would add too much complexity
        to them, and harder in day-to-day usage

    TRADEOFFS:
    - given selectors are duplicated all over the project code base
      when you want to change it
      then you have to use global Find&Replace text,
           with sometimes pretty thorough manual checks line by line
           all places where the change will be applied.
           You CAN'T use some refactoring features of IDE like Refactor>Rename
    """

    browser.open('https://duckduckgo.com/')

    browser.element('[name=q]')\
        .should(be.blank)\
        .type('yashaka selene python').press_enter()
    browser.all('.result__body') \
        .should(have.size_greater_than(5)) \
        .first.should(have.text('User-oriented Web UI browser tests'))

    browser.all('.result__body').first.element('a').click()
    browser.should(have.title_containing('yashaka/selene'))
Ejemplo n.º 7
0
def test_no_hold_on_default_false():
    browser.open('http://todomvc.com/examples/emberjs/')
    driver = browser.driver
    browser.element('#new-todo').type('a').press_enter()

    atexit._run_exitfuncs()

    assert not Help(driver).has_browser_still_alive()
Ejemplo n.º 8
0
def test_shared_browser_reopens_on_url_open_action():
    browser.open('https://duckduckgo.com/')
    browser.element('[id="search_form_input_homepage"]').click()

    browser.quit()
    browser.open('https://duckduckgo.com/')

    browser.element('[id="search_form_input_homepage"]').click()
Ejemplo n.º 9
0
def test_shared_browser_reopens_on_url_open_action():
    browser.open('http://google.ru')
    browser.element('[name="q"]').click()

    browser.quit()
    browser.open('http://google.ru')

    browser.element('[name="q"]').click()
Ejemplo n.º 10
0
class MainPage(Header, BasePage):
    path = ''

    edit_all = browser.element(by.xpath("//small[text()='Edit All']"))
    clear_all = browser.element(by.xpath("//small[text()='Clear All']"))
    list_vew = browser.element(
        by.xpath("//button[contains(text(),'List View')]"))
    search_field = browser.element(by.name("searchText"))
    sort_by = browser.element(by.xpath("//span[text()='Sort By']"))
Ejemplo n.º 11
0
class LoginPage(Header, BasePage):
    path = ''

    email_field = browser.element(by.name('email'))
    password_field = browser.element(by.name('password'))
    do_not_remember_your_password_btn = browser.element(
        by.class_name('auth0-lock-input-wrap'))
    show_password_btn = browser.element(
        by.xpath("//label[@title='Show password']"))
Ejemplo n.º 12
0
def test_find_link_text():
    browser.open('http://suninjuly.github.io/find_link_text')
    browser.element('[href="find_link_text_redirect13.html"]').click()

    # Add
    browser.element('[name=first_name]').type('Elena').press_enter()
    browser.element('[name=last_name]').type('Sheremet').press_enter()
    browser.element('.city').type('Dnipro').press_enter()
    browser.element('#country').type('Ukraine').press_enter()
Ejemplo n.º 13
0
def test_hold_on_explicit_true():
    browser.config.hold_browser_open = True
    browser.open('http://todomvc.com/examples/emberjs/')
    browser.element('#new-todo').type('a').press_enter()

    atexit._run_exitfuncs()
    browser.element('#new-todo').type('b').press_enter()

    browser.all('#todo-list>li').should(have.texts('a', 'b'))
Ejemplo n.º 14
0
def test_can_init_custom_browser_on_visit():
    browser.config.browser_name = 'firefox'

    browser.open(empty_page)
    GivenPage(browser.driver).opened_with_body('''
        <a id="selene_link">Selene site</a>
        ''')

    browser.element("#selene_link").should(have.exact_text("Selene site"))
    assert browser.driver.name == 'firefox'
Ejemplo n.º 15
0
    def assert_action_successful_on_reload(entity):
        browser.element('[href*=notification_message]').click()
        notification = browser.element('#flash')
        webelement = notification()
        actual = webelement.text
        expected = 'Action successful\n×'

        if actual != expected:
            raise AssertionError(f'notification message was wrong:'
                                 f'\texpected: {expected}'
                                 f'\t  actual: {actual}')
Ejemplo n.º 16
0
def test_shared_browser_not_reopen_on_action_after_been_closed():
    browser.open('http://google.ru')
    browser.element('[name="q"]').click()

    browser.quit()

    with pytest.raises(RuntimeError) as error:
        browser.element('[name="q"]').click()
    assert 'Webdriver has been closed.' in str(error.value)
    assert 'You need to call open(url) to open a browser again.' in str(
        error.value)
Ejemplo n.º 17
0
def test_shared_browser_not_reopen_on_action_after_been_closed():
    browser.open('https://duckduckgo.com/')
    browser.element('[id="search_form_input_homepage"]').click()

    browser.quit()

    with pytest.raises(RuntimeError) as error:
        browser.element('[id="search_form_input_homepage"]').click()
    assert 'Webdriver has been closed.' in str(error.value)
    assert 'You need to call open(url) to open a browser again.' in str(
        error.value)
Ejemplo n.º 18
0
def setup_function():
    global selenium_browser
    selenium_browser = get_test_driver()
    selenium_browser.get(TODOMVC_URL)
    WebDriverWait(selenium_browser, 4).until(
        expected_conditions.visibility_of_element_located(
            (By.CSS_SELECTOR, "#new-todo")))

    browser.config.driver = get_test_driver()
    browser.open(TODOMVC_URL)
    browser.element("#new-todo").should(be.visible)
Ejemplo n.º 19
0
def test_search():
    browser.open('https://google.com/ncr')

    browser.element(by.name('q')).should(be.blank)\
        .type('python selene').press_enter()

    results = browser.all('#search .g')
    results.should(have.size_greater_than_or_equal(6))
    results.first.should(have.text('Concise API for Selenium'))
    results.first.element('.r>a').click()

    browser.should(have.title_containing('yashaka/selene'))
Ejemplo n.º 20
0
def x_test_hold_on_explicit_true__when__set_after_open():
    """
    todo: probably it will not work right now... should we bother?
    """
    browser.open('http://todomvc.com/examples/emberjs/')
    browser.element('#new-todo').type('a').press_enter()

    browser.config.hold_browser_open = True
    atexit._run_exitfuncs()
    browser.element('#new-todo').type('b').press_enter()

    browser.all('#todo-list>li').should(have.texts('a', 'b'))
Ejemplo n.º 21
0
def test_wait_for_notification_after_reload_v5():
    """
    with default rendering (built into selene's condition) of error message on failure
    AND simplified syntax with lambdas
    """
    browser.open(
        'https://the-internet.herokuapp.com/notification_message_rendered')

    browser.wait.for_(lambda _: (
        browser.element('[href*=notification_message]').click(),
        have.exact_text('Action successful\n×')(browser.element('#flash')),
    ))
Ejemplo n.º 22
0
def test_one_element_when_enabled():
    browser.config.timeout = 0.5
    browser.config.log_outer_html_on_failure = True
    browser.open('http://todomvc.com/examples/emberjs/')

    message = None
    try:
        browser.element('#new-todo').should(have.attribute('wrong_attr'))
    except Exception as e:
        message = str(e)

    assert message is not None
    assert 'Actual webelement:' in message
def test_complete_task():
    browser.open('http://todomvc.com/examples/emberjs/')

    browser.element('#new-todo').type('a').press_enter()
    browser.element('#new-todo').type('b').press_enter()
    browser.element('#new-todo').type('c').press_enter()
    browser.all('#todo-list>li').should(have.exact_texts('a', 'b', 'c'))

    browser.element('#todo-list>li:nth-child(2)').should(have.exact_text('b'))
    browser.element('#todo-list>li:nth-child(2) .toggle').click()
    browser.all('#todo-list>li.completed').should(have.exact_text('b'))
    browser.all('#todo-list>li:not(.completed)').should(
        have.exact_texts('a', 'c'))
Ejemplo n.º 24
0
def test_can_make_screenshot_automatically():
    browser.open(EMPTY_PAGE_URL)
    config.timeout = 0.1

    with pytest.raises(TimeoutException):
        browser.element("#selene_link").should(have.exact_text("Selen site"))

    expected = os.path.join(
        get_default_screenshot_folder(),
        f'{get_screen_id()}.png',
    )
    assert os.path.exists(expected)
    assert os.path.isfile(expected)
Ejemplo n.º 25
0
def test_todomvc_starts_with_cleaned_storage_at_new_browser():
    # When
    browser.open(todomvc.url)

    # Then
    (browser.all("#todo-list>li").should(have.size(0)).should(
        have.no.texts('todo from A test')))

    # When
    browser.element('#new-todo').set_value('todo from B test').press_enter()

    # Then
    browser.all("#todo-list>li").should(have.texts('todo from B test'))
Ejemplo n.º 26
0
def test_wait_for_notification_after_reload_v6():
    """
    with default rendering (built into selene's condition) of error message on failure
    and simplified syntax with lambdas
    AND with optimised performance and removed potential side effects of "nested waiting"
    """
    browser.open(
        'https://the-internet.herokuapp.com/notification_message_rendered')

    browser.wait.for_(lambda _: (
        browser.element('[href*=notification_message]')().click(),
        have.exact_text('Action successful\n×')(browser.element('#flash')),
    ))
    '''
Ejemplo n.º 27
0
def test_find_xpath_form():
    browser.open('http://suninjuly.github.io/find_xpath_form')

    # Add
    browser.element('[name=first_name]').type('Elena')
    browser.element('[name=last_name]').type('Sheremet')
    browser.element('.city').type('Dnipro')
    browser.element('#country').type('Ukraine')

    button = browser.element('/html/body/div/form/div[6]/button[3]')
    button.click()
Ejemplo n.º 28
0
def test_can_get_latest_screenshot_path():
    config.reports_folder = (
        os.path.dirname(os.path.abspath(__file__)) +
        f'/../../build/screenshots_{next(browser.config.counter)}')
    browser.open(EMPTY_PAGE_URL)
    config.timeout = 0.1

    with pytest.raises(TimeoutException):
        browser.element("#s").should(be.visible)

    picture = browser.last_screenshot
    expected = os.path.join(config.reports_folder, f'{get_screen_id()}.png')
    assert picture == expected
    assert os.path.exists(picture)
    assert os.path.isfile(picture)
Ejemplo n.º 29
0
 def __set_registration_data(self):
     data = REGISTRATION_DATA
     first_name = data['first_name']
     last_name = data['last_name']
     self.__first_name_input.with_(Config(timeout=10)).should(
         be.visible).set_value(first_name)
     self.__last_name_input.set_value(last_name)
     self.__company_name_input.set_value(data['company_name'])
     set_select_option(
         browser.element(self.__country_select)(), data['country'])
     self.__city_input.set_value(data['city'])
     self.__phone_input.click().type(data['phone'])
     set_select_option(
         browser.element(self.__template_select)(), data['template'])
     return {'first_name': first_name, 'last_name': last_name}
Ejemplo n.º 30
0
def element(css_or_xpath_or_by: Union[str, tuple]) -> Element:
    warnings.warn(
        'selene.browser.element is deprecated, '
        'use `from selene.support.shared import browser` import',
        DeprecationWarning,
    )
    return browser.element(css_or_xpath_or_by)