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))
Exemple #2
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'))
 def results_should_be(
     more_than=5,
     first_result_text='User-oriented Web UI browser tests'
 ):
     browser.all('.result__body')\
         .should(have.size_greater_than(more_than))\
         .first.should(have.text(first_result_text))
Exemple #4
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'))
Exemple #5
0
def test_filter_tasks():
    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),
        timeout=config.timeout * 3,
    )

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

    browser.all('#todo-list li').element_by(
        have.exact_text('b')).element('.toggle').click()
    browser.element(by.link_text('Active')).click()
    browser.all('#todo-list li').filtered_by(be.visible).should(
        have.exact_texts('a', 'c'))

    browser.element(by.link_text('Completed')).click()
    browser.all('#todo-list li').filtered_by(be.visible).should(
        have.exact_texts('b'))

    browser.element(by.link_text('All')).click()
    browser.all('#todo-list li').filtered_by(be.visible).should(
        have.exact_texts('a', 'b', 'c'))
Exemple #6
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'))
Exemple #7
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'))
Exemple #8
0
def test_completed_tasks():
    browser.element('[id="new-todo"]').type('a').press_enter()
    browser.element('[id="new-todo"]').type('b').press_enter()
    browser.element('[id="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) .toggle').click()
    browser.element('#todo-list>li:nth-child(2)').should(
        have.css_class('completed'))
    browser.element('#todo-list>li:nth-child(1)').should(
        have.no.css_class('completed'))
    browser.element('#todo-list>li:nth-child(3)').should(
        have.no.css_class('completed'))
Exemple #9
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'))
Exemple #10
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_collection_when_disabled():
    browser.config.timeout = 0.5
    browser.config.log_outer_html_on_failure = False
    browser.open('http://todomvc.com/examples/emberjs/')

    message = None
    try:
        browser.all('footer p').element_by(
            have.attribute('wrong_attr')).should(be.visible)
    except Exception as e:
        message = str(e)

    assert message is not None
    assert 'Actual webelements collection:' not in message
Exemple #12
0
def all(css_or_xpath_or_by: Union[str, tuple]) -> Collection:
    warnings.warn(
        'selene.browser.all is deprecated, '
        'use `from selene.support.shared import browser` import',
        DeprecationWarning,
    )
    return browser.all(css_or_xpath_or_by)
Exemple #13
0
def ss(css_or_xpath_or_by: Union[str, tuple]) -> Collection:
    warnings.warn(
        'selene.support.jquery_style_selectors.ss is deprecated; '
        'use selene.support.shared.jquery_style.ss instead',
        DeprecationWarning,
    )
    return browser.all(css_or_xpath_or_by)
    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)
def test_add_huge_form():
    browser.open('http://suninjuly.github.io/huge_form.html')
    elements = browser.all('[type="text"]')

    for element in elements:
        element.send_keys('ok')

    button = browser.element('.btn')
    button.click()
def test_complete():
    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').filtered_by(have.no.css_class('completed'))

    browser.all('#todo-list > li').filtered_by(
        have.no.css_class('completed')).element('.toggle').click()
    browser.all('#todo-list > li').filtered_by(have.css_class('completed'))
    browser.all('#todo-list > li').filtered_by(have.no.css_class('completed'))
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'))
Exemple #18
0
def test_complete_todo():
    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-of-type(2) .toggle').click()
    browser.all('#todo-list>li.completed').should(have.exact_texts('b'))
    browser.all('#todo-list>li:not(.completed)').should(
        have.exact_texts('a', 'c'))
Exemple #19
0
def test_complete_task():
    # browser.config.driver =
    # browser.config.hook_wait_failure=\
    #     lambda error: TimeoutException(error.msg.replace('file://', ''))
    # browser.config.timeout = 6
    # browser.config.save_screenshot_on_failure = False
    # browser.config.save_page_source_on_failure = False
    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.element('#new-todo').with_(Config(timeout=2)).should(have.value('foo'))
    browser.all('#todo-list>li').should(have.exact_texts('a', 'b', 'c'))

    browser.all('#todo-list>li').element_by(have.exact_text('b'))\
        .element('.toggle').click()
    browser.all('#todo-list>li').filtered_by(have.css_class('completed'))\
        .should(have.exact_texts('b'))
    browser.all('#todo-list>li').filtered_by(have.no.css_class('completed'))\
        .should(have.exact_texts('a', 'c'))
class AtTodoMvcWithClearedStorageAfterEachTest:

    todos = browser.all('#todo-list>li')

    def open_todomvc(self):
        browser.open('') \
            .should(have.js_returned(True,
                 'return ($._data($("#clear-completed").get(0), "events")'
                 '.hasOwnProperty("click") && '
                 '(Object.keys(require.s.contexts._.defined).length === 39))'))

    def add(self, *texts):
        for text in texts:
            browser.element('#new-todo').type(text).press_enter()

    def todos_should_be(self, *with_texts):
        self.todos.should(have.exact_texts(*with_texts))

    def todo(self, text):
        return self.todos.element_by(have.exact_text(text))

    def start_editing(self, text, new_text):
        self.todo(text).double_click()
        return self.todos.element_by(have.css_class('editing')) \
            .element('.edit').set_value(new_text)

    def edit(self, text, new_text):
        self.start_editing(text, new_text).press_enter()

    def cancel_edit(self, text, new_text):
        self.start_editing(text, new_text).press_escape()

    def toggle(self, text):
        self.todo(text).element('.toggle').click()

    def clear_completed(self):
        browser.element('#clear-completed').click()

    def delete(self, text):
        self.todo(text).hover().element('.destroy').click()
Exemple #21
0
    def test_filter_tasks(self):
        browser.open(APP_URL)
        clear_completed_js_loaded = "return $._data($('#clear-completed').get(0), 'events').hasOwnProperty('click')"
        browser.wait.for_(have.js_returned(True, clear_completed_js_loaded))

        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')).element(".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'))
Exemple #22
0
def test_todomvc_can_add_todos():
    browser.open(todomvc.url)

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

    browser.all("#todo-list>li").should(have.texts('todo from A test'))
Exemple #23
0
 def __init__(self):
     self.details = self.Details(browser.element('#order_details'))
     self.add_item = browser.element('#add_item')
     self.items = self.Items(browser.all('[id^="item"]'))
Exemple #24
0
from selene import have
from selene.support.shared import browser
from web_test.assist.allure.report import step
"""
The file is named with _org in the end just to make it more explicit –
that this official python site page
"""

_url = 'https://www.python.org/'

_results = browser.all('.list-recent-events>li')


@step
def open():
    browser.open(_url)


@step
def should_be_opened():
    browser.should(have.url(_url))


@step
def search(text):
    browser.element('#id-search-field').type(text).press_enter()


@step
def should_have_result(index, text):
    _results[index].should(have.text(text))
from selene.support.shared import browser
from selene.support.conditions import be
from selene.support.conditions import have


browser.open(
    'http://selenium.dunossauro.live/aula_07'
)

label = browser.element(
    '[for="nome"]'
)

label.should(have.text('nome'))


browser.all(
    'input'
).should(have.size(4)).first.type('Duduzin')


label.should(have.text('Não vale mentir o nome'))
from selene import have
from selene.support.shared import browser

#Arrenge
browser.config.hold_browser_open = True
browser.open("https://www.ecosia.org/")

#Action
browser.element('[data-test-id="search-form-input"]').type(
    'yashaka selene').press_enter()
browser.all('.result').first.click()

#Assert
browser.all('[href="/yashaka/selene"]').should(have.size(3))
Exemple #27
0
def test_todomvc_shares_todos_in_same_browser_session():
    # When
    browser.open(todomvc.url)

    # Then
    (browser.all("#todo-list>li").should(have.texts('todo from B test')))
 def __init__(self):
     self.elements = browser.all('.results_links_deep')
Exemple #29
0
 def __init__(self):
     self.elements = browser.all('.result')
Exemple #30
0
 def __init__(self):
     self.todos = browser.all('#todo-list>li')
     self.be_completed = have.css_class('completed')
     self.be_active = self.be_completed.not_