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)
Beispiel #2
0
def test_should_have_text(session_browser):
    GivenPage(session_browser.driver).opened_with_body('''
        <ul>Hello:
           <li>Yakov</li>
           <li>Jakob</li>
        </ul>
        ''')

    session_browser.all('li').should(have.text('ako'))
    session_browser.all('li').should(have.text(''))
Beispiel #3
0
def test_pypi():
    """
    LocatorModules/PageObjectLess
    LocatorModules == page locators/selectors are simply vars in python modules
    Might be also called as PageModules
    ===========================================================================

    Here the page model is implemented in the simplest modular way
    with simplification to "just vars, no functions for steps" in python modules.

    GO FOR:
    * a bit higher abstraction (no more technical selectors in tests code)
      * extra readability in test code
    * reusable vars with locators
    * easier refactoring (Refactor>Rename, etc. can be applied)
    * yet KISS modeling (Keep It Simple Stupid)

    TRADEOFFS:
    - common ones for "programming without functions" style ;)
      some code might be too bulky,
      business steps might be hardly visible in a long e2e test
   """
    browser.open(pypi.url)

    pypi.search.type('selene').press_enter()
    pypi.results\
        .should(have.size_greater_than_or_equal(9)) \
        .first.should(have.text('Concise API for selenium in Python'))

    pypi.results.first.click()
    browser.should(have.url(pypi.url + 'project/selene/'))
    browser.should(have.title_containing('selene · PyPI'))
 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))
Beispiel #5
0
def test_otus():
    browser.open_url('https://otus.ru/')
    # print(browser.title())  # 'Онлайн курсы для профессионалов'
    browser.element(by.text('Отзывы')).click()
    el = browser.elements(by.css('.review-tile')).first().text
    print(el)
    browser.should(have.text('Selenium'))
Beispiel #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'))
Beispiel #7
0
def test_search():
    browser.open('https://www.ecosia.org/')
    browser.element(by.name('q')).type('github yashaka selene').press_enter()

    browser.all('.result')\
        .element_by_its('.result-title', have.text('yashaka/selene'))\
        .element('.result-url').click()

    browser.should(have.title_containing('yashaka/selene'))
def test_google_one(selene_config):
    start = time.time()
    logger.info(f'before start browser: {time.time() - start} seconds')
    browser.open("/")
    logger.info(f'browser start duration: {time.time() - start} seconds')
    s(by.name("q")).should(be.blank) \
        .type("selenium").press_enter()
    ss(".srg .g").should(have.size_greater_than(0)) \
        .first.should(have.text("Selenium automates browsers"))
def test_google_two(selene_config):
    start = time.time()
    logger.info(f'before start browser: {time.time() - start} seconds')
    browser.open("/")
    logger.info(f'browser start duration: {time.time() - start} seconds')
    s(by.name("q")).should(be.blank) \
        .type("selenium").press_enter()
    ss(".srg .g").should(have.size_greater_than(0)) \
        .first.should(have.text("The Selenium project is a member of Software "
                                "Freedom Conservancy"))
def test_unicode_text(session_browser):
    GivenPage(session_browser.driver).opened_with_body('''
        <ul>Привет:
           <li>Саше</li>
           <li>Яше</li>
        </ul>
        ''')

    element = session_browser.element('li')

    element.should(have.exact_text('Саше')).should(have.text('Са'))
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'))
Beispiel #12
0
def test_should_have_text_exception(session_browser):
    browser = session_browser.with_(timeout=0.1)
    GivenPage(browser.driver).opened_with_body('''
        <ul>Hello:
           <li>Alex</li>
           <li>Alex</li>
        </ul>
        ''')

    with pytest.raises(TimeoutException) as error:
        browser.all('li').should(have.text('Yakov'))
    assert "has text Yakov" in error.value.msg
    assert "AssertionError: actual text: Alex" in error.value.msg
Beispiel #13
0
 def follow_result_link(self, text):
     """
     Here we could return "next page object",
     following so called Fluent PageObject pattern
     but usually it might lead to confusion in such cases.
     For example, what if we fail to follow the link
     and this is "as expected", e.g. according to our
     "negative" test case conditions.
     Then it's logically to expect "same pageobject" not "next one"
     Now we have two potential state as a result of this method execution.
     And it's not clear what to return;)
     So better to return "void"/None in such cases.
     Usually Fluent PageObject makes sense only in cases
     with only 1 possible result state, for example:
     - returning self (we for sure stay on the same page)
     - returning "sub-page-object" i.e. object of component on the page
       (it's always there)
     """
     self.results.element_by(have.text(text)).element('a').click()
Beispiel #14
0
def should_have_result(index, text):
    _results[index].should(have.text(text))
 def should_have_text(self, index, value) -> Results:
     self.elements[index].should(have.text(value))
     return self
Beispiel #16
0
 def index_of_header_by_text(self, value, /):
     return self.index_of_header_by(
         have.text(value)
     )
Beispiel #17
0
def test_login_and_try_to_add_device():
    browser.open('/')

    Form('.o_login_form').submit(UserData(
        email='admin',
        password='******',
    ))

    Dropdown.for_('o_menu_apps').select('«Company»')
    """
    # OR:
    Dropdown.for_('o_menu_apps').select('company_root')
    # OR:
    Dropdown.for_('o_menu_apps').select_by_xmlid('company_root')
    """

    Dropdown.by_title('Registry').select('«Devices»')
    """
    # OR:
    Dropdown.for_(
        'o_menu_sections', title='Registry'
    ).select('«Devices»')
    """

    Table().cell(row=have.text('main-phone'), column='«Device ID»').click()

    # First Try
    browser.element('action_share_access').click()

    Modal.by_title('«Share Access»').form.fill(
        AccessData(
            access_label='director access',
            owner_id=InputDropdown.Value(
                text='*****@*****.**',
                autocomplete=None,
            ),
            key_id=InputDropdown.Value(
                text='asdf-lkjh-jkli-ieqw',
                autocomplete=None,
            ),
            receiver_id=InputDropdown.Value(
                text='*****@*****.**',
                autocomplete=None,
            ),
        )).submit(by_button='do_share').should_have_validation_for(
            AccessData(
                owner_id=...,
                key_id=...,
            ))
    """
    # OR:
    dialog = Modal.by_title('Share Access').element
    dialog.element('access_label').type('director access')
    dialog.element('owner_id').element('input').type('*****@*****.**')
    dialog.element('receiver_id').element('input').type('*****@*****.**')
    dialog.element('do_share').click()
    # todo: check validation ...
    dialog.element('do_close').click()
    # ...
    """

    # Second Try
    browser.element('action_add_device_to_hub').click()

    Modal.by_title('«Share Access»').form.fill(
        AccessData(
            device_label='director access',
            owner_id=InputDropdown.Value(text='admin@'),
            receiver_id=InputDropdown.Value(text='*****@*****.**'),
        )).submit(by_button=['do_share', 'do_close'])
def follow_result_link(text):
    results.element_by(have.text(text)).element('a').click()
    browser.switch_to_next_tab()
 def should_be_price_in_basket_equal_product_price(self):
     self.product_price_in_message\
         .should(have.text(self.product_price.get(query.text)))
     return self
Beispiel #20
0
 def should_have_result(self, index, text) -> Google:
     self.results[index].should(have.text(text))
     return self
 def login_failed(self):
     s('h3[data-test="error"]')\
         .should(have.text("Epic sadface: Username and password do not match any user in this service"))\
         .s('button.error-button')
 def should_be_message_that_basket_is_empty(self):
     self.message_about_empty_basket.should(
         have.text('Your basket is empty. Continue shopping'))
     return self
 def step(more_than=5,
          first_result_text='User-oriented Web UI browser tests'):
     ss('[data-testid=result]') \
         .should(have.size_greater_than(more_than)) \
         .first.should(have.text(first_result_text))
 def should_be_message_about_add_product_to_basket(self):
     self.product_name_in_message\
         .should(have.text(self.product_name.get(query.text)))
     return self
Beispiel #25
0
    def by_title(text: str, /):
        text = (text[1:-1] if is_quoted_with_double_guillemets(text) else text)

        return Modal(
            browser.all('header').element_by(have.text(text)).element('..'))