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 test_duckduckgo_(): """ Straightforward/PageObjectLess style + s, ss for JQuery/Selenide's $, $$ ======================================================================== GO FOR: * the most concise * 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/') s('[name=q]').type('yashaka selene python').press_enter() ss('.result__body') \ .should(have.size_greater_than(5)) \ .first.should(have.text('User-oriented Web UI browser tests')) ss('.result__body').first.s('a').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_adding_and_completing_tasks(): s('#new-todo').type('a').press_enter() s('#new-todo').type('b').press_enter() s('#new-todo').type('c').press_enter() ss('#todo-list>li').should(have.exact_texts('a', 'b', 'c')) s('#todo-list>li:nth-child(2) .toggle').click() s('#todo-list>li:nth-child(2)').should(have.css_class('completed')) s('#todo-list>li:nth-child(1)').should(have.no.css_class('completed')) s('#todo-list>li:nth-child(3)').should(have.no.css_class('completed'))
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 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('[data-test-id="search-form-input"]').type( 'yashaka selene').press_enter() ss('.result').first.click() # Assert ss('[href="/yashaka/selene"]').should(have.size(3))
def test_05brokenimage(self): print("broken image") browser.open_url('https://the-internet.herokuapp.com/broken_images') images = ss(by.css("img")) for image in images: if image.get_attribute("naturalWidth") == "0": print("Image", image.get_attribute("outerHTML"), "is broken")
def check_number_of_products_in_cart_header(self, expected_number: [int]): elements = ss("span.fa-layers-counter.shopping_cart_badge")\ .should(have.size_greater_than_or_equal(0))\ .should(have.size_less_than_or_equal(1)) actual_number = 0 if len(elements) == 0 else int(elements.first.get(query.text)) assert expected_number == actual_number return self
def test_03addRemmoveElement(self): print("Add/remove element") browser.open_url('https://the-internet.herokuapp.com/add_remove_elements/') #add elements howmanyadd = date.howmanyadd add_remove_element().add_elemnts(howmanyadd) howmanydeletesexist = ss("button[onclick='deleteElement()']") assert len(howmanydeletesexist) == howmanyadd # remove elements howmanydelete = date.howmanydlelete add_remove_element().delete_element(howmanydelete) if howmanyadd > howmanydelete: assert len(howmanydeletesexist) == howmanyadd - howmanydelete else: assert howmanydeletesexist.size() == 0
def test_complete_todo(): browser.open('http://todomvc.com/examples/emberjs/') s('#new-todo').type('a').press_enter() s('#new-todo').type('b').press_enter() s('#new-todo').type('c').press_enter() ss('#todo-list>li').should(have.exact_texts('a', 'b', 'c')) s('#todo-list>li:nth-of-type(2) .toggle').click() ss('#todo-list>li.completed').should(have.exact_texts('b')) ss('#todo-list>li:not(.completed)').should(have.exact_texts('a', 'c'))
def __init__(self): self.todos = ss('#todo-list>li') self.clear_completed_button = s('#clear-completed')
def test_search_and_count_links(): s('[name=q]').type('yashaka selene').press_enter() ss('.result').first.click() ss('[href ="/yashaka/selene"]').should(have.size(3))
def get_all_products(self) -> Collection: self.should_be_opened() return ss('div.inventory_list > div.inventory_item')
from selene import have from selene.support.shared import browser from selene.support.shared.jquery_style import s, ss # ARRANGE URL = 'https://www.ecosia.org/' query_string = "'yashaka selene'" # користувач завантажує сторінку в браузері: https://www.ecosia.org/ # browser.config.hold_browser_open = True browser.open(URL) # ACTS # користувач в поле пошуку вводить текст 'yashaka selene' # користувач натискає Enter s('[placeholder="Search the web to plant trees..."]').type(query_string).press_enter() # користувач переходить по першому посиланню серед знайдених результатів s('[class="result-snippet-link"]').click() # ASSERT # користувач перевіряє що на відкритій сторінці # є три локальні посилання на https://github.com/yashaka/selene ss('[href="/yashaka/selene"]').should(have.size(3)) browser.quit()
def step(): ss('[data-testid=result]').first.element( '[data-testid=result-title-a]').click()
from selene import have, driver from selene.support.shared import browser from selene.support.shared.jquery_style import s, ss # Arrange browser.config.hold_browser_open = True # Задержка браузера browser.open("https://www.google.com/") # Act s('[ class="gLFyf gsfi" ]').type( 'yashaka selene').press_enter() # Поиск Элемента по ID class href s('[class="LC20lb DKV0Md"]').click() # s('[href="https://pypi.org/project/selene/2.0.0a33/" ]').click() # <input placeholder="Search the web to plant trees..." aria-label="Search Form" type="search" name="q" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" autofocus="autofocus" required="required" data-test-id="search-form-input" value="" class="input" data-v-b22df982=""> # __layout > div > section > div.content > form > div.input-wrapper > input # //*[@id="__layout"]/div/section/div[1]/form/div[1]/input ss(' [href="https://pypi.org/project/selene/2.0.0a33/" ] li') print('Ссылок на странице =', len(ss('[ href="/yashaka/selene"]')))
from selene import have from selene.support.shared import browser from selene.support.shared.jquery_style import s, ss # Arrange browser.config.hold_browser_open = True # Задержка браузера browser.open("http://todomvc.com/examples/emberjs/") # Act s('[id="new-todo"]').type( 'listen lesson').press_enter() # Поиск Элемента по ID s('[id="new-todo"]').type('have a rest').press_enter() # Ввод текста s('[id="new-todo"]').type('do home work').press_enter() # Assert ss('[id="todo-list"] li').should( have.exact_texts('listen lesson', 'have a rest', 'do home work')) # Подсчет элементов s('[id="todo-list"] li:nth-child(2) .toggle').click() browser.element('[id="todo-list"] li:nth-child(2)').should( have.css_class('completed')) browser.element('[id="todo-list"] li:nth-child(1)').should( have.no.css_class('completed')) browser.element('[id="todo-list"] li:nth-child(2)').should( have.no.css_class('completed'))
def step(more_than=5, first_result_text='User-oriented Web UI browser tests'): ss('.result__body') \ .should(have.size_greater_than(more_than)) \ .first.should(have.text(first_result_text))
from selene.support.conditions import have from selene.support.shared.jquery_style import s, ss from selene.support.shared import browser # Given browser.open('https://www.ecosia.org/') # When s('[name="q"]').type('yashaka selene').press_enter() ss('.result-body .js-result-title').first.click() # Then ss('[href = "/yashaka/selene"]').should(have.size(3))
from selene import have from selene.support.shared import browser from selene.support.shared.jquery_style import s, ss # ARRANGE browser.config.hold_browser_open = True browser.open('http://todomvc.com/examples/emberjs/') # ACTS s('[id="new-todo"]').type('Listen Lesson').press_enter() s('[id="new-todo"]').type('Listen Book').press_enter() s('[id="new-todo"]').type('Watch TV').press_enter() # ASSERT ss('[id="todo-list"] li').should( have.exact_texts('Listen Lesson.', 'Listen Book', 'Watch TV'))
def get_all_products_in_cart(self) -> Collection: self.should_be_opened() return ss('div.cart_list > div.cart_item')
def step(): ss('.result__body').first.element('a').click()
def result(number): return ss('#search .g')[number - 1]