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))
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'))
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'))
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_registration1_form(): browser.open('http://suninjuly.github.io/registration1.html') browser.element('[class="form-control first"]').type('Elena') browser.element('[class="form-control second"]').type('Sheremet') browser.element('[class="form-control third"]').type('*****@*****.**') button = browser.element('[class="btn btn-default"]') button.click()
def open_app(self): browser.open('#/') browser.should( have.js_returned( True, 'return Object.keys(require.s.contexts._.defined).length === 39' ))
def open_app(): browser.open('https://todomvc4tasj.herokuapp.com/') window_uploaded = "return $._data($('#clear-completed')[0], 'events')" \ ".hasOwnProperty('click') " \ "& " \ "Object.keys(require.s.contexts._.defined).length == 39" browser.should(have.js_returned(True, window_uploaded))
def visit(self): download_page = "return $._data($('#clear-completed')[0],"\ "'events').hasOwnProperty('click')" browser.open('https://todomvc4tasj.herokuapp.com') browser.should(have.js_returned(True, download_page)) return self
def test_search(): browser.open('https://www.ecosia.org/') s('[name=q]').type('yashaka selene').press_enter() ss('.result').first.click() ss('[href="/yashaka/selene"]').should(have.size(3))
def visit(): """ Also, here... we have to rename open to visit, in order to eliminate potential conflicts with python built in `open` function """ browser.open('https://www.searchencrypt.com')
def test_search(): browser.open('https://google.com/ncr') search('yashaka selene') follow_result_link(1) githib_page_shuold_be('yashaka/selene')
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 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 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_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'
def visit(): browser.config.hold_browser_open = True browser.open("http://todomvc4tasj.herokuapp.com/") browser.should( have.js_returned( True, "return $._data($('#clear-completed')[0], 'events').hasOwnProperty('click')" ))
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()
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()
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()
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()
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'))
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_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_can_make_screenshot_with_custom_name_with_empty_path(): browser.open(EMPTY_PAGE_URL) actual = browser.save_screenshot(file="custom.png") expected = 'custom.png' assert actual == expected assert os.path.exists(actual) assert os.path.isfile(actual)
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'
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_search(): # ARRANGE browser.open("https://www.ecosia.org/") # ACT s('[name="q"]').type("yashaka selene").press_enter() s('a.result-title').click() # ASSERT ss('[href="/yashaka/selene"]').should(have.size(3))
def register(self, login: str = None, password: str or int = None): browser.open(REGISTRATION_URL) self.__email_input.set_value(login or self.login) self.__password_input.should(be.visible).set_value(password or self.password) self.__submit_button.click() customer = self.__set_registration_data() self.__register_submit_button.click() self.__register_submit_button.with_(Config(timeout=10)).should( be.not_.visible) return customer
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)
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()