def test_is_displayed_fails_with_waiting_if_element_not_exist(): given_at_other_page() original_timeout = config.timeout # todo: switch to something like s("#todo-list").with_timeout(0.1).is_displayed() config.timeout = 0.1 with pytest.raises(TimeoutException): s("#todo-list").is_displayed() config.timeout = original_timeout
def test_assure_and_alias_methods(): given_active("a") s("#clear-completed").assure(hidden) s("#clear-completed").insist(hidden) # alias s("#clear-completed").should(hidden) # alias s("#clear-completed").should_be(hidden) # alias s("#clear-completed").should_have(hidden) # alias
def __init__(self): self.organization2Field = s( by.xpath("//*[text()='Поиск']" "/ancestor::div[contains(@class, 'ErrorNotificator')]")) self.loginField = s('[name="login"]') self.passwordField = s('[name="password"]') self.loginButton = s('button')
def search_organization(self, input_text, hint_list): self.BranchName.set_value(input_text) #Вводим значение для поля self.ShowButton.click() self.ClearButton.click() a = hint_list for i, ii in enumerate(a): self.BranchName.set_value(a[i]) self.ShowButton.click() field_info = a[i] element_to_select = s(by.xpath(f".//*[text()='{field_info}']")) b = element_to_select.text print(a[i]) print(b) #self.ClearButton.click() element_to_select.click() self.ShowSessions.click() self.TimeSelection.click() self.SelectDate.click() self.DateChoose.click() self.DateChoose.click() self.ShowButton.click() element_of_time = s( by.xpath( "//*[@class='mui-date-picker']/descendant-or-self::*[text()='Выберите начало промежутка']/following-sibling::input" )) c = element_of_time.get_attribute('value') print(c) self.ClearButton.click() #value_to_select = organization_list.s(by.xpath("//*[text()='1']/ancestor::*[@role='gridcell']")) assert field_info == b self.FirstElementSessionTable.click() self.open3()
def set_city(self, input_text, result, hint_list): self.event_city.scroll_to() self.event_city.set_value(input_text) #Вводим значение для поля tooltip_holder = s("div.token-input-dropdown-timepad ul") tooltip_holder.should(visible) tooltips_all = ss("div.token-input-dropdown-timepad ul li") assert len(tooltips_all) > 0, f"Для поля город отстутствуют подсказки" value_to_select = None for tooltip_el in tooltips_all: hint_text = tooltip_el.text if hint_text in hint_list: hint_list.remove(hint_text) if hint_text == result: value_to_select = tooltip_el assert value_to_select is not None, ( f"Необходимое значение {result} для поля город" f" отстутствует в списке подсказок") assert len( hint_list ) <= 0, f"В выпадающем списке подсказок отсутствует: {hint_list}" value_to_select.click() selected_value = s("li.token-input-token-timepad p") selected_value.should_have(text(result))
def __init__(self): self.loggedUser = s( "#navbar > ul.nav.navbar-nav.navbar-right > li.user_info > span:nth-child(1) > strong" ) self.logo = s("a.navbar-brand") self.logout_btn = s("#logout") self.users_link = s("#users_link")
def __init__(self): super().__init__() self.url = "https://sprintboards.io/auth/login" self.email = s(by.css("[type=email]")) self.password = s(by.css("[type=password]")) self.login_button = s(by.css("[type=submit]"))
def test_assure_not_and_alias_methods(): given_at_other_page() s("#new-todo").should_not(exist) s("#new-todo").insist_not(exist) # alias s("#new-todo").should_not(exist) # alias s("#new-todo").should_not_be(exist) # alias s("#new-todo").should_not_have(exist) # alias
def test_rozetka_sign_in_out(): rozetka = RozetkaMainPage().load_page() sign_page = rozetka.login() sign_page.sign_in() s(".header-topline__user-link").should( have.no.text('увійдіть в особистий кабінет')) user_page = sign_page.load_user_page() user_page.sign_out()
def test_can_get_latest_screenshot_path(): config.reports_folder = os.path.dirname(os.path.abspath(__file__)) + '/../../build/screenshots' open_url(start_page) with pytest.raises(TimeoutException): s("#s").should_be(visible) picture = latest_screenshot() assert os.path.exists(picture)
def __init__(self): self.privacy_policy_accept = s( 'div.amo_sendpulse_dp label.widget-settings__checkbox-privacy-policy' ) self.install_widget_btn = s('button[id="amo_sendpulse_dp"]') self.sp_id_input = s('input[name="sendpulse_id"]') self.sp_secret_input = s('input[name="sendpulse_secret"]') self.save_settings_btn = s('#save_amo_sendpulse_dp')
def open_widget_settings(self): self.search_input.set('SendPulse') s('*[data-body-fixed="1"]').should_not_be(visible) (s('.widget-card__wrapper[title="SendPulse"]').should_be( visible).should_be(clickable).click()) return WidgetSettings()
def open_contact_detail(self, email): # browser.execute_script("location.reload()") self.search_input.set(email).press_enter() s('*[data-body-fixed="0"]').should_be(visible) s('.page-loading').should_not_be(visible) ss('div[id^="list_item"] div[data-field-id="name"]').find_by( text(email)).s("a").click() return ContactDetailSection()
def test_can_make_screenshot_automatically(): visit(start_page) config.timeout = 0.1 with pytest.raises(TimeoutException) as ex: s("#selene_link").should_have(exact_text("Selen site")) expected = os.path.join(get_default_screenshot_folder(), 'screen_{id}.png'.format(id=get_screen_id())) assert os.path.exists(expected)
def step_impl(context): """Активирует чек бокс про-версия""" context.pro_version = s(".trade_container.wrapper").get_attribute( 'version') actions = ActionChains(browser.driver()) actions.click( s(".filter_mobile_container .filter_checkbox_switch [name='proVersion']" )).perform() sleep(2)
def __init__(self): super().__init__() self.url = "https://sprintboards.io/boards/create" self.title = s(by.css("h1")) self.session_name = s(by.css("[placeholder=\"Session Name\"]")) self.owner = s(by.css(".custom-select")) self.create_board_button = s(by.css("[type=submit]")) self.popup_title = s(by.css(".swal-title"))
def __init__(self): # login form elements self.login_input = s('#login-form-login') self.password_input = s('#login-form-password') self.sign_in_button = s('#login-form-login-button') # keeptit html main page self.nav_bar = s('.nav.navbar-nav') self.sign_in_item = self.nav_bar.s('#signin-page')
def test_upload_from_pc(self): s('#jobsListAttachJobButton').click() app = Application().connect(title_re="Open*") app.Open.Edit.set_edit_text('C:\\Users\\ssoloshchenko\\Desktop\\jobs\\vector .pdf') # update path to local file while True: try: app.Open.Button.click() # open button is getting focused except pywinauto.findbestmatch.MatchError: break time.sleep(1) return self
def install_widget(self, user_id, secret): self.privacy_policy_accept.click() self.install_widget_btn.click() self.sp_id_input.set(user_id) self.sp_secret_input.set(secret) self.save_settings_btn.click() s('.widget-settings').should_not(visible) # after widget pop-up is closed two widgets are displayed. # Should be only 1. By search it is not filtered browser.execute_script("location.reload()") return SettingsSection()
def test_login_with_empty_fields(self): page = login_methods.LoginPage(driver) page.user_login_with_empty_data() actual_email_error_text = s(LoginPageLocators.ERROR_EMPTY_EMAIL_FIELD) actual_password_error_text = s( LoginPageLocators.ERROR_EMPTY_PASSWORD_FIELD) actual_email_error_text.should( have.exact_text("The field is required.")) actual_password_error_text.should( have.exact_text("The field is required."))
def setup_function(f): global browser global shaded_browser set_driver(get_test_driver()) open_url(TODOMVC_URL) s("#new-todo").should_be(visible) browser = get_test_driver() browser.get(TODOMVC_URL) WebDriverWait(browser, 4).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, "#new-todo"))) shaded_browser = get_test_driver()
def __init__(self): # header section self.header_wrap = s('.navigation-menu') self.header_logo = self.header_wrap.s('.logo') self.header_setting_icon = self.header_wrap.s('.settings') # table with online devices self.sync_device_table = s("#sync-devices") self.all_add_link = ss('#sync-devices-button') self.add_link = s('#sync-devices-button') self.setting_icon = s('.edit-device-menu-item.edit-item') # add online drive drop-down self.add_online_drive_link = s('.open').s(by.text('Online Drive')) self.all_add_dropdown_open = ss('.dropdown-menu .drive-device') # modal window 'create new item' self.modal_wrap = s('.modal.in') self.modal_name_input = self.modal_wrap.s('#name') self.modal_save_button = self.modal_wrap.s('.btn-success') self.modal_delete_icon = self.modal_wrap.s('.delete-item') # modal alert for confirm delete item self.confirm_delete_yes_button = s( by.xpath("//a[contains(@id, 'yes-button')]")) # error message popup self.error_alert_popup = s('.message.alert.alert-error') # header logout alert self.logout_alert = self.header_setting_icon.s('.open .dropdown-menu') self.logout_alert_sign_out_button = self.logout_alert.s('#logout')
def test_selement_search_fails_with_message_when_implicitly_waits_for_condition(): GIVEN_PAGE.opened_with_body(''' <button id='hidden-button' style='display:none'>You can't click me, ha ha! :P</button> ''') config.timeout = 0.1 with pytest.raises(TimeoutException) as ex: s('#hidden-button').click() assert exception_message(ex) == \ ['failed while waiting 0.1 seconds', 'to assert Visible', "for first_by('css selector', '#hidden-button')", '', 'reason: ConditionMismatchException: condition did not match', 'screenshot: //.selene/screenshots/*/screen_*.png']
def open_bar(self, bar_xpath: str, opener_xpath: str) -> None: """ Открыть выдвигающуюся панель :param bar_xpath: Xpath панели :param opener_xpath: Xpath элемента открывания панели """ self.log.debug(f"Work '{self.get_method_name()}'") # Если панель закрыта, то открыть if "width: 0px;" in s(by.xpath(bar_xpath)).get_attribute("style"): self.shading_disappearing() # Затемнение self.highlight(s(by.xpath(opener_xpath))) s(by.xpath(opener_xpath)).click() # Проверить, что панель открылась assert "width: 0px;" not in s( by.xpath(bar_xpath)).get_attribute("style")
def step_impl(context, price1, price2): """Устанавливает филтр цен от {price1} до {price2}""" s('.filter .price_inputs [input="max"]').hover().click().send_keys( Keys.CONTROL + "a").send_keys(Keys.BACK_SPACE) s('.filter .price_inputs [input="max"]').send_keys(price2) s('.filter .price_inputs [input="min"]').hover().click().send_keys( Keys.BACK_SPACE) s('.filter .price_inputs [input="min"]').send_keys(price1)
def step_impl(context, value): """Проверяет, что фильтр тип установлен в состояние {value}""" assert s( '.filter_mobile_container .filter_exterior_type .list_menu_dropdown [title="%s"]' % value).get_attribute( 'class') == 'type_item is_active', 'Фильтр тип не установлен'
class Cart: element: SeleneElement = s("table#cart_summary") @property def items(self): return self.element.find_all(".cart_item") def item(self, index: int) -> CartItem: return CartItem(self.items[index - 1]) def should_have_number_of_items(self, number: int): if number > 0: self.items.should(have.size(number)) else: raise ValueError("Number should be > 0") return self def should_have_only(self, *args: Product): self.should_have_number_of_items(len(args)) for index, product in enumerate(args): self.item(index + 1).should_have(product) return self def delete(self, *args: Product): raise NotImplementedError
def test_filter_tasks(self): browser.visit(APP_URL) s('#new-todo').should(be.enabled).set_value('a').press_enter() s('#new-todo').should(be.enabled).set_value('b').press_enter() s('#new-todo').should(be.enabled).set_value('c').press_enter() ss("#todo-list>li").should(have.texts('a', 'b', 'c')) ss("#todo-list>li").element_by(exact_text('b')).find(".toggle").click() s(by_link_text("Active")).click() ss("#todo-list>li").filtered_by(be.visible).should(have.texts('a', 'c')) s(by_link_text("Completed")).click() ss("#todo-list>li").filtered_by(be.visible).should(have.texts('b'))
class HomePage(BasePage): def __init__(self): # TODO change url format passing super().__init__(f'{way2automation["hostname"]}{way2automation["base_url"]}') self._page_content = 'div[class="container margin-top-20"]' droppable_page_link = s('div[class*="linkbox"] > ul> li > a[href*="droppable"]')
def browser_sign_in() -> str: browser.open_url("https://leetcode.com/accounts/login/") s('[name="login"]').set(LEETCODE_EMAIL.get()) s('[name="password"]').set(LEETCODE_PASSWORD.get()) s("#initial-loading").should_not(be.visible) s("#signin_btn").should(be.visible).click() s(".storyboard").should(be.visible) leetcode_session = driver().get_cookie("LEETCODE_SESSION") if leetcode_session is None: raise ValueError return leetcode_session["value"]