Skip to content

Commit

Permalink
update failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Kidman committed Apr 14, 2021
1 parent 14fd844 commit 10963e2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 82 deletions.
117 changes: 58 additions & 59 deletions tests/ui/test_element.py
Original file line number Diff line number Diff line change
@@ -1,190 +1,189 @@
import pytest
from pylenium.driver import Pylenium
from selenium.common.exceptions import ElementNotInteractableException


def test_element_with_no_siblings(py):
py.visit('https://deckshop.pro')
elements = py.get("a[href='/spy/']").siblings()
THE_INTERNET = 'https://the-internet.herokuapp.com'
DEMO_QA = 'https://demoqa.com'


def test_element_with_no_siblings(py: Pylenium):
py.visit(f'{THE_INTERNET}/dropdown')
elements = py.get('#page-footer > div').siblings()
assert elements.should().be_empty()


def test_element_parent_and_siblings(py):
py.visit('https://demoqa.com/menu')
def test_element_parent_and_siblings(py: Pylenium):
py.visit(f'{DEMO_QA}/menu')
parent = py.contains('Main Item 1').parent()
assert parent.tag_name() == 'li'
assert parent.siblings().should().have_length(2)


def test_element_text(py):
py.visit('https://demoqa.com/text-box')
def test_element_text(py: Pylenium):
py.visit(f'{DEMO_QA}/text-box')
assert py.get('#userName-label').should().have_text('Full Name')


def test_find_in_element_context(py):
py.visit('https://demoqa.com/menu')
def test_find_in_element_context(py: Pylenium):
py.visit(f'{DEMO_QA}/menu')
menu_2 = py.contains('Main Item 2')
items = menu_2.parent().find('li')
assert items.should().have_length(5)


def test_input_type_and_get_value(py):
def test_input_type_and_get_value(py: Pylenium):
py.visit('https://deckshop.pro')
search_field = py.get('#smartSearch')
assert search_field.type('golem').should().have_value('golem')
assert search_field.clear().should().have_value('')


def test_children(py):
py.visit('https://deckshop.pro')
first_row_of_cards_in_deck = py.get("[href*='/deck/detail/'] > span").children()
assert first_row_of_cards_in_deck.should().have_length(4)
def test_children(py: Pylenium):
py.visit(f'{THE_INTERNET}/dropdown')
options = py.get('#dropdown').children()
assert options.should().have_length(3)


def test_forced_click(py):
py.visit('https://demoqa.com/checkbox')
def test_forced_click(py: Pylenium):
py.visit(f'{DEMO_QA}/checkbox')
# without forcing, this raises ElementNotInteractableException
py.get("[type='checkbox']").click(force=True)
assert py.get('#result').should().contain_text('You have selected')


def test_not_forcing_click_raises_error(py):
py.visit('https://demoqa.com/checkbox')
with pytest.raises(ElementNotInteractableException):
py.get("[type='checkbox']").click()


def test_element_should_be_clickable(py):
py.visit('https://demoqa.com/buttons')
def test_element_should_be_clickable(py: Pylenium):
py.visit(f'{DEMO_QA}/buttons')
assert py.contains("Click Me").should().be_clickable()


def test_element_should_not_be_clickable(py):
py.visit('https://demoqa.com/checkbox')
def test_element_should_not_be_clickable(py: Pylenium):
py.visit(f'{DEMO_QA}/checkbox')
with pytest.raises(AssertionError):
py.get('[type="checkbox"]').should(timeout=3).be_clickable()


def test_element_should_be_visible(py):
def test_element_should_be_visible(py: Pylenium):
py.visit('http://book.theautomatedtester.co.uk/chapter1')
py.get('#loadajax').click()
assert py.get('#ajaxdiv').should().be_visible()


def test_element_should_be_hidden(py):
def test_element_should_be_hidden(py: Pylenium):
py.visit('https://deckshop.pro')
assert py.get('#smartHelp').should().be_hidden()


def test_element_should_be_focused(py):
def test_element_should_be_focused(py: Pylenium):
py.visit('https://deckshop.pro')
py.get('#smartSearch').click()
assert py.get('#smartSearch').should().be_focused()


def test_element_should_not_be_focused(py):
def test_element_should_not_be_focused(py: Pylenium):
py.visit('https://deckshop.pro')
assert py.get('#smartSearch').should().not_be_focused()


def test_elements_should_be_empty(py):
def test_elements_should_be_empty(py: Pylenium):
py.visit('https://google.com')
assert py.find('select', timeout=3).should().be_empty()
assert py.findx('//select', timeout=0).should().be_empty()


def test_elements_should_not_be_empty(py):
py.visit('https://the-internet.herokuapp.com/add_remove_elements/')
def test_elements_should_not_be_empty(py: Pylenium):
py.visit(f'{THE_INTERNET}/add_remove_elements/')
py.contains('Add Element').click()
py.contains('Add Element').click()
assert py.find('.added-manually').should().not_be_empty()


def test_elements_should_have_length(py):
py.visit('https://the-internet.herokuapp.com/add_remove_elements/')
def test_elements_should_have_length(py: Pylenium):
py.visit(f'{THE_INTERNET}/add_remove_elements/')
py.contains('Add Element').click()
py.contains('Add Element').click()
assert py.find('.added-manually').should().have_length(2)


def test_elements_should_be_greater_than(py):
py.visit('https://the-internet.herokuapp.com/add_remove_elements/')
def test_elements_should_be_greater_than(py: Pylenium):
py.visit(f'{THE_INTERNET}/add_remove_elements/')
py.contains('Add Element').click()
py.contains('Add Element').click()
assert py.find('.added-manually').should().be_greater_than(1)


def test_elements_should_be_less_than(py):
py.visit('https://the-internet.herokuapp.com/add_remove_elements/')
def test_elements_should_be_less_than(py: Pylenium):
py.visit(f'{THE_INTERNET}/add_remove_elements/')
py.contains('Add Element').click()
py.contains('Add Element').click()
assert py.find('.added-manually').should().be_less_than(3)


def test_element_attribute(py):
def test_element_attribute(py: Pylenium):
search_field = '[name="q"]'
py.visit('https://google.com')
assert py.get(search_field).get_attribute('title') == 'Search'
assert py.get(search_field).should().have_attr('title', 'Search')


def test_element_property(py):
def test_element_property(py: Pylenium):
search_field = '[name="q"]'
py.visit('https://google.com')
assert py.get(search_field).get_property('maxLength') == 2048
assert py.get(search_field).should().have_prop('maxLength', 2048)


def test_element_should_disappear(py):
def test_element_should_disappear(py: Pylenium):
spinner = '#serverSideDataTable_processing'
py.visit('https://www.copart.com/lotSearchResults/?free=true&query=nissan')
assert py.get(spinner).should().disappear()


def test_element_has_attribute(py):
py.visit('http://the-internet.herokuapp.com/checkboxes')
def test_element_has_attribute(py: Pylenium):
py.visit(f'{THE_INTERNET}/checkboxes')
py.find('[type="checkbox"]')[1].should().have_attr('checked')


def test_element_does_not_have_attribute(py):
py.visit('http://the-internet.herokuapp.com/checkboxes')
def test_element_does_not_have_attribute(py: Pylenium):
py.visit(f'{THE_INTERNET}/checkboxes')
py.get('[type="checkbox"]').should().not_have_attr('checked')


def test_element_has_attribute_with_value(py):
py.visit('http://the-internet.herokuapp.com/checkboxes')
def test_element_has_attribute_with_value(py: Pylenium):
py.visit(f'{THE_INTERNET}/checkboxes')
py.get('[type="checkbox"]').should().have_attr('type', 'checkbox')


def test_element_does_not_have_attribute_with_value(py):
py.visit('http://the-internet.herokuapp.com/checkboxes')
def test_element_does_not_have_attribute_with_value(py: Pylenium):
py.visit(f'{THE_INTERNET}/checkboxes')
py.should().contain_title('The Internet')
py.get('[type="checkbox"]').should().not_have_attr('type', 'box')


def test_element_css_value(py):
py.visit('https://demoqa.com/buttons')
def test_element_css_value(py: Pylenium):
py.visit(f'{DEMO_QA}/buttons')
element = py.contains('Click Me')
assert element.css_value('backgroundColor') == "rgba(0, 123, 255, 1)"
assert element.css_value('background-color') == "rgba(0, 123, 255, 1)"


def test_element_invalid_css_property_name(py):
py.visit('https://demoqa.com/buttons')
def test_element_invalid_css_property_name(py: Pylenium):
py.visit(f'{DEMO_QA}/buttons')
element = py.contains('Click Me')
assert element.css_value('bg-color') == ''
assert element.css_value('length') is None


def test_getx_nested_element(py):
py.visit('https://demoqa.com/automation-practice-form')
def test_getx_nested_element(py: Pylenium):
py.visit(f'{DEMO_QA}/automation-practice-form')
container = py.getx('//*[@id="subjectsContainer"]')
element = container.getx('.//input')
element_id = element.get_attribute('id')
assert element_id == 'subjectsInput'


def test_findx_nested_element(py):
py.visit('https://demoqa.com/automation-practice-form')

def test_findx_nested_element(py: Pylenium):
py.visit(f'{DEMO_QA}/automation-practice-form')
container = py.getx('//*[@id="hobbiesWrapper"]')
elements = container.findx('.//input')
assert len(elements) == 3
Expand Down
45 changes: 22 additions & 23 deletions tests/ui/test_pydriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@
from pylenium.driver import Pylenium


def test_jit_webdriver(py):
def test_jit_webdriver(py: Pylenium):
assert py._webdriver is None
assert py.webdriver is not None
assert py._webdriver is not None


def test_py_request(py):
py.visit('https://statsroyale.com')
def test_py_request(py: Pylenium):
response = py.request.get('https://statsroyale.com/api/cards')
assert response.ok
assert response.json()[0]['name']


def test_execute_script(py):
def test_execute_script(py: Pylenium):
py.visit('https://google.com')
webelement = py.get("[name='q']").webelement
assert py.execute_script('return arguments[0].parentNode;', webelement)


def test_google_search(py):
def test_google_search(py: Pylenium):
py.visit('https://google.com')
py.get("[name='q']").type('puppies', Keys.ENTER)
assert py.should().contain_title('puppies')


def test_cookies(py):
def test_cookies(py: Pylenium):
cookie_to_set = {'name': 'foo', 'value': 'bar'}
cookie_to_test = {
'domain': 'www.google.com',
Expand All @@ -48,51 +47,51 @@ def test_cookies(py):
assert py.get_cookie('foo') is None


def test_viewport(py):
def test_viewport(py: Pylenium):
py.visit('https://google.com')
py.viewport(1280, 800)
assert {'width': 1280, 'height': 800} == py.window_size


def test_get_xpath(py):
def test_get_xpath(py: Pylenium):
py.visit('https://google.com')
py.getx('//*[@name="q"]').type('QA at the Point', Keys.ENTER)
assert py.should().contain_title('QA at the Point')


def test_find_xpath(py):
py.visit('https://deckshop.pro')
assert py.findx('//a[@class="nav-link"]').should().be_greater_than(1)
def test_find_xpath(py: Pylenium):
py.visit('https://the-internet.herokuapp.com/checkboxes')
assert py.findx('//input[@type="checkbox"]').should().be_greater_than(1)


def test_hover_and_click_to_page_transition(py):
def test_hover_and_click_to_page_transition(py: Pylenium):
py.visit('https://qap.dev')
py.get('a[href="/about"]').hover().get('a[href="/leadership"][class*=Header]').click()
assert py.contains('Carlos Kidman').should().have_text('Carlos Kidman')
assert py.contains('Carlos Kidman').should().contain_text('Carlos Kidman')


def test_pylenium_wait_until(py):
def test_pylenium_wait_until(py: Pylenium):
py.visit('https://qap.dev')
element = py.wait(use_py=True).until(lambda x: x.find_element_by_css_selector('[href="/about"]'))
assert element.tag_name() == 'a'
assert element.hover()


def test_pylenium_wait_until_with_seconds(py):
def test_pylenium_wait_until_with_seconds(py: Pylenium):
py.visit('https://qap.dev')
py.wait(use_py=True).sleep(2)
element = py.wait(5, use_py=True).until(lambda x: x.find_element_by_css_selector('[href="/about"]'))
assert element.tag_name() == 'a'
assert element.hover()


def test_webdriver_wait_until(py):
def test_webdriver_wait_until(py: Pylenium):
py.visit('https://qap.dev')
element = py.wait(5).until(lambda x: x.find_element_by_css_selector('[href="/about"]'))
assert element.tag_name == 'a'


def test_switch_to_frame_then_back(py):
def test_switch_to_frame_then_back(py: Pylenium):
py.visit('http://the-internet.herokuapp.com/iframe')
py.switch_to.frame('mce_0_ifr').get('#tinymce').clear().type('foo')
assert py.switch_to.default_content().contains('An iFrame').tag_name() == 'h3'
Expand All @@ -101,7 +100,7 @@ def test_switch_to_frame_then_back(py):
assert py.switch_to.parent_frame().contains('An iFrame').tag_name() == 'h3'


def test_switch_to_frame_by_element(py):
def test_switch_to_frame_by_element(py: Pylenium):
py.visit('http://the-internet.herokuapp.com/iframe')
iframe = py.get('#mce_0_ifr')
py.switch_to.frame_by_element(iframe).get('#tinymce').clear().type('foo')
Expand All @@ -110,12 +109,12 @@ def test_switch_to_frame_by_element(py):
assert py.get('#tinymce').text() == 'foobar'


def test_have_url(py):
def test_have_url(py: Pylenium):
py.visit('https://qap.dev')
py.should().have_url('https://www.qap.dev/')


def test_loading_extension_to_browser(py, project_root):
def test_loading_extension_to_browser(py: Pylenium, project_root):
py.config.driver.extension_paths.append(f'{project_root}/tests/ui/Get CRX.crx')
py.visit('chrome://extensions/')
shadow1 = py.get('extensions-manager').open_shadow_dom()
Expand All @@ -124,17 +123,17 @@ def test_loading_extension_to_browser(py, project_root):
assert ext_shadow_dom.get('#name-and-version').should().contain_text('Get CRX')


def test_should_not_find(py):
def test_should_not_find(py: Pylenium):
py.visit('https://google.com')
assert py.should().not_find('select')


def test_should_not_find_xpath(py):
def test_should_not_find_xpath(py: Pylenium):
py.visit('https://google.com')
assert py.should().not_findx('//select')


def test_should_not_contain(py):
def test_should_not_contain(py: Pylenium):
py.visit('https://google.com')
assert py.should().not_contain('foobar')

Expand Down

0 comments on commit 10963e2

Please sign in to comment.