def test_citations(self, main_page: MainPage): """Test that citations in the footer are correct""" for _ in range(25): citation = main_page.wisdom_citation with check.check, allure.step(f"Check '{citation}'"): assert main_page.wisdom_citation in wisdom_citations main_page.refresh()
def authorize(email, password): page = MainPage(driver=driver) page.click(page.locators.LOGIN_BUTTON, timeout=5) page.fill_field(page.locators.EMAIL_INPUT, email) page.fill_field(page.locators.PASSWORD_INPUT, password) page.click(page.locators.CONFIRM_LOGIN_BUTTON, timeout=5) return AccountPage(driver=driver)
def dashboard_page(driver): main_page = MainPage(driver) main_page.click(main_page.locators.LOGIN_BUTTON) modal_login = ModalLogin(driver) modal_login.find(modal_login.locators.LOGIN).send_keys(email) modal_login.find(modal_login.locators.PASSWORD).send_keys(password) modal_login.click(modal_login.locators.SUBMIT_BUTTON) return DashboardPage(driver)
def check_links(main_page: MainPage, params: tuple): driver = main_page.driver for locator, label in params: handle = driver.current_window_handle with check.check: check_link(main_page, locator, f'invalid url for {label} link') if handle == driver.current_window_handle: main_page.make_request() else: driver.close() driver.switch_to.window(handle)
def test_vk_id(self, vk_id, main_page: MainPage, mock_client: MockClient): """Test that vk_id is displayed correctly if it has correct string value""" username = main_page.username mock_client.set_vk_id(username, vk_id) time.sleep(2) main_page.refresh() with allure.step('search for vk_id'): try: real_vk_id = main_page.vk_id except WebDriverException as err: allure.attach.file(main_page.make_screenshot('vk_id'), attachment_type=allure.attachment_type.PNG, name='vk_id--not--found.png') raise AssertionError('vk_id element not found') from err with allure.step('Compare expected and real vk_id'): check.equal(real_vk_id, vk_id)
def test_segment_deleting(self, login: MainPage, my_segment_name): segment_page = login.go_to_segment_page() segment_page.create_segment(my_segment_name) segment_page.delete_segment(my_segment_name) time.sleep(1) with pytest.raises(TimeoutException): segment_page.find(segment_page.locators.MY_SEGMENT_NAME_LOC, timeout=1)
def go_to(self, page_name: str): from ui.pages.main_page import MainPage if page_name == 'sources-news-settings': # Свайп до вкладки с источниками. self.swipe_to_element(self.locators.BUTTON_SOURCES_NEWS) # Перейти на вкладку с источниками новостей. self.click(self.locators.BUTTON_SOURCES_NEWS) return SourcesNewsSettingsPage(driver=self.driver, configuration=self.configuration) elif page_name == 'about-application-settings': # Свайп до вкладки с описаниями. self.swipe_to_element(self.locators.BUTTON_ABOUT_APP) # Нажимаем на кнопку. self.click(self.locators.BUTTON_ABOUT_APP) return AboutApplicationPage(driver=self.driver, configuration=self.configuration) elif page_name == 'main-page': # Перейти на главное меню. self.click(self.locators.BUTTON_GO_MAIN) return MainPage(driver=self.driver, configuration=self.configuration) else: raise UnsupportedPageException(f'Not found page "{page_name}".')
def test_main_page_links(main_page: MainPage): """Test links of main page have valid urls Steps: - Pass registration and enter main page (in fixture) - Click a link - Return to main page - Repeat for each links expect 'HOME' Expected results: All urls follow to some pages but not to main page """ allure.attach.file(main_page.make_screenshot('main-page'), attachment_type=allure.attachment_type.PNG, name='main-page.png') link_locators = main_page.locators check_links( main_page, ((link_locators.API, 'API'), (link_locators.FUTURE, 'future'), (link_locators.SMTP, 'SMTP'), (link_locators.PYTHON, 'Python'), (link_locators.LINUX, 'Linux'), (link_locators.NETWORK, 'network'))) check_nested_links( main_page, ((link_locators.PYTHON, link_locators.PYTHON_HISTORY, 'history'), (link_locators.PYTHON, link_locators.FLASK, 'Flask'), (link_locators.LINUX, link_locators.CENTOS, 'CentOS'), (link_locators.NETWORK, link_locators.WIRESHARK_NEWS, 'WireShark news'), (link_locators.NETWORK, link_locators.WIRESHARK_DOWNLOAD, 'WireShark downloads'), (link_locators.NETWORK, link_locators.TCPDUMP_EXAMPLES, 'TcpDump examples')))
def check_nested_link(main_page: MainPage, parent_locator, nested_locator, error_msg=''): html = main_page.find((By.TAG_NAME, 'html')) driver = main_page.driver try: ActionChains(driver) \ .move_to_element(driver.find_element(parent_locator)) \ .pause(1) \ .click(driver.find_element(nested_locator)) \ .perform() main_page.wait(main_page.load_time).until( conditions.staleness_of(html)) except WebDriverException as err: raise AssertionError(error_msg) from err assert main_page.check_url_negative()
def setup(self, driver): self.driver: webdriver = driver self.main_page: MainPage = MainPage(driver) self.dashboard_page: DashboardPage = DashboardPage(driver) self.create_new_campaign_page:CreateNewCampaignPage = CreateNewCampaignPage(driver) self.segments_list_page: SegmentsListPage = SegmentsListPage(driver) self.create_new_segment_page: CreateNewSegmentPage = CreateNewSegmentPage(driver)
def login(driver, config): main_page = AuthPage(driver, config) main_page.click(main_page.locators.LOGIN_BUTTON) main_page.find(main_page.locators.LOGIN_FIELD).send_keys( config['username']) main_page.find(main_page.locators.PASSWORD_FIELD).send_keys( config['password']) main_page.click(main_page.locators.CONFIRM_LOGIN) return MainPage(driver, config['username'])
def auth(driver, config): page_object = BasePage(driver, config) login = config['email'] paswd = config['password'] locator = basic_locators.BasePageLocators() page_object.click(locator.AUTH_BUTTON) page_object.find(locator.EMAIL).send_keys(login) page_object.find(locator.PASSWORD).send_keys(paswd) page_object.click(locator.ACCEPT) return MainPage(driver, config)
def incorrect_input(driver, config): page_object = BasePage(driver, config) login = '******' paswd = 'Incorrect_user_password' config['fake_email'] = login locator = basic_locators.BasePageLocators() page_object.click(locator.AUTH_BUTTON) page_object.find(locator.EMAIL).send_keys(login) page_object.find(locator.PASSWORD).send_keys(paswd) page_object.click(locator.ACCEPT) return MainPage(driver, config)
def login(base_page, config): email, password = config["email"], config["password"] base_page.click(base_page.locators.LOGIN_BUTTON) email_elem = base_page.find(locator=base_page.locators.EMAIl_INPUT) email_elem.clear() email_elem.send_keys(email) passw_elem = base_page.find(locator=base_page.locators.PASSWORD_INPUT) passw_elem.clear() passw_elem.send_keys(password) base_page.click(base_page.locators.AUTH_BUTTON) yield MainPage(base_page.driver) base_page.click(base_page.locators.LOGOUT_FIELD) base_page.click(base_page.locators.EXIT_BUTTON)
def check_link(main_page: MainPage, locator, error_msg=''): html = main_page.find((By.TAG_NAME, 'html')) try: main_page.click(locator) main_page.wait(main_page.load_time).until( conditions.staleness_of(html)) except WebDriverException as err: raise AssertionError(error_msg) from err assert main_page.check_url_negative()
def log_to_main_page(driver, correct_auth_data): lg_page = LoginPage(driver) lg_page.click(lg_page.locators.ENTER_BUTTON) lg_page.fill_field(lg_page.locators.INPUT_LOGIN, correct_auth_data['login']) lg_page.fill_field(lg_page.locators.INPUT_PASSWORD, correct_auth_data['password']) lg_page.find(lg_page.locators.GO_TO_MAIN_PAGE_BUTTON).click() mn_page = MainPage(driver) yield mn_page mn_page.click(mn_page.locators.USER_BUTTON) time.sleep(0.5) mn_page.click(mn_page.locators.LOG_OUT)
def create_campaign(self, link, name, male=True, female=True, ages="30-50"): from ui.pages.main_page import MainPage self.click(self.locators.TRAFFIC) self.find(self.locators.LINK_FIELD).send_keys(link) sleep(3) self.click(self.locators.CLEAR_NAME_BUTTON, 20) self.find(self.locators.NAME_FIELD).send_keys(name) self.click(self.locators.SEX_FIELD) if not male: self.click(self.locators.MALE_CHECKBOX) if not female: self.click(self.locators.FEMALE_CHECKBOX) if ages != "": self.click(self.locators.AGE_FIELD) self.click(self.locators.AGE_CHOICE) self.click(self.locators.RANDOM_AGE) self.find(self.locators.AGE_INPUT).clear() self.find(self.locators.AGE_INPUT).send_keys(ages) self.click(self.locators.FORMAT_TEASER) self.find(self.locators.BANNER_TITLE).send_keys("Create 10 min email") self.find(self.locators.BANNER_TEXT).send_keys("Come on") self.find(self.locators.UPLOAD_FILE).send_keys( os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, 'resources', '123.jpg'))) sleep(3) self.click(self.locators.SAVE_FILE) sleep(3) self.click(self.locators.ADD_ADVERT) self.click(self.locators.CONFIRM_CREATING) return MainPage(self.driver, self.config)
def logout(self): from ui.pages.main_page import MainPage self.click(self.locators.LOGOUT) return MainPage(self.driver, self.config)
def test_segment_creating(self, login: MainPage, my_segment_name): segment_page = login.go_to_segment_page() segment_page.create_segment(my_segment_name) segment_page.find(segment_page.locators.MY_SEGMENT_NAME_LOC)
def test_company_creating(self, login: MainPage, my_company_name): company_page = login.go_to_company_page() company_page.create_company(my_company_name) company_page.find(company_page.locators.MYCOMPANY_NAME_IN_LIST)
def main_page(driver): return MainPage(driver=driver)
def setup(self, driver): self.main_page: MainPage = MainPage(driver)
def dashboard(driver, secrets): """ Фикстура для авторизации """ MainPage(driver).auth(secrets['login'], secrets['password']) return DashboardPage(driver)
def test_scenario_single_user_2(self, api_client: ApiClient, mysql_client: MysqlClient, registration_page: RegistrationPage): """Test scenario for API Steps: 0 Generate credentials 1 Pass registration with these credentials 2 Block user via API 3 Refresh page 4 Try to authorize to the site 5 Accept user via API 6 Try to authorize user Expected results: Step 1: database table has record with these credentials and values `access` = 1, `active` = 1, `start_active_time` ~ time.time() Step 2: `access` = 0, no other changes Step 3: user is redirected to authorization page, `access` = 0, `active` = 0 Step 4: user doesn't succeed to authorize, Step 6: `access` = 1, no other changes Step 7: User succeeds to authorize, `active` changed to 1, start_active_time changed and almost equal time.time(), no other changes Step 8: `active` = 0, no other changes Step 9: `access` = 0, no other changes Step 10: User doesn't succeed to authorize, the record doesn't changed """ username, email, password = make.auth_data() with allure.step('Register user'): main_page = registration_page.pass_registration( username, email, password) start_time = time.time() record = mysql_client.get_record(username) assert record is not None assert record == Record(username, email, password, 1, 1, start_time) # access = 1, active = 1 with allure.step('Block user'): api_client.block_user(username=username) record = mysql_client.get_record(username) assert record is not None assert record == Record(username, email, password, 0, 0, start_time) # access = 0, active = 0 with allure.step('Refresh page'): main_page.refresh() assert not MainPage.is_opened(main_page.driver) assert AuthorizationPage.is_opened(main_page.driver) # logout record = mysql_client.get_record(username) assert record is not None assert record == Record(username, email, password, 0, 0, start_time) # no change authorization_page = AuthorizationPage(main_page.driver, main_page.settings) with allure.step('Authorize user (who is blocked)'): with pytest.raises(AuthorizationError): authorization_page.authorize(username, password) record = mysql_client.get_record(username) assert record is not None assert record == Record(username, email, password, 0, 0, start_time) # no change with allure.step('Accept user'): api_client.block_user(username=username) record = mysql_client.get_record(username) assert record is not None assert record == Record(username, email, password, 1, 0, start_time) # access = 1 with allure.step('Authorize user (who was accepted)'): authorization_page.authorize(username, password) record = mysql_client.get_record(username) start_time = time.time() assert record is not None assert record == Record(username, email, password, 1, 1, start_time) # active = 1
def test_authorization_pos(self, login: MainPage): login.find(login.locators.BALANCE)
def authorization(driver, config, auth_page, api_client): page = auth_page page.authorize(api_client.username, api_client.password) return MainPage(driver, config)
def main_page(driver, config): return MainPage(driver, config)
def authorize(self, db_setup): new = db_setup.add_user() self.login_page.auth_with_text(new.username, new.password) yield MainPage(driver=self.login_page.driver) db_setup.delete_user(new.id)
def registration(driver, config, reg_page): page = reg_page page.registrate('qwertyui', '*****@*****.**', '12345678') return MainPage(driver, config)
def authorization(driver): MainPage(driver).authorization()