def do_text_bold(self): """ method to do text bold """ Browser().switch_to_frame_by_locator(*self.__IFRAME) element = self.__TEXT_FIELD.find_element() element.send_keys(Keys.CONTROL + self.settings['KEY_a']) Browser().switch_to_default_content() self.__BOLD_BUTTON.click()
def send_text(self, text): """ method to send random text """ Browser().switch_to_frame_by_locator(*self.__IFRAME) element = self.__TEXT_FIELD element.selenium_clear() element.send_keys(text) Browser().switch_to_default_content()
def get_text(self): """ method to get text :return: text """ Browser().switch_to_frame_by_locator(*self.__IFRAME) text = self.__TEXT_FIELD.find_element().text Browser().switch_to_default_content() return text
def is_text_bold(self): """ method to check text is bold :return: if the text is bold then return true or not return false """ Browser().switch_to_frame_by_locator(*self.__IFRAME) if self.__BOLD_TEXT.find_element(): return True else: return False
def create_browser(request): with allure.step("Creating a browser session"): browser = request.config.getoption('--browser') selenoid = request.config.getoption('--selenoid') lang = request.config.getoption('--lang') Browser.get_browser().set_up_driver(browser_key=browser, selenoid=selenoid, lang=lang) Browser().get_default_url() yield with allure.step("Close sessions of all browsers"): for browser_key in list(Browser.get_browser().get_driver_names()): Browser.get_browser().quit(browser_key=browser_key)
def send_text(text): Browser().send_alert_text(text)
def get_alert_text(): return Browser().get_alert_text()
def close_alert(): Browser().accept_alert()
from selenium.webdriver.common.by import By from selenium.webdriver.remote.webelement import WebElement from selenium.webdriver.support import expected_conditions from framework.browser.browser import Browser from framework.enums.web_element_attributes import WebElementAttributes from framework.models.web_driver_wait import DriverWait from framework.utils.logger import debug from resources import config browser = Browser() class BaseElement: def __init__(self, by: By, loc: str, name: str): self.__by = by self.__loc = loc self.__name = f"{type(self).__name__}, '{name}'" debug(f"Creating instance of {self.__name}") def is_displayed(self) -> bool: return self.web_element.is_displayed() def click(self): self.web_element.click() def wait_and_click(self): self.wait_for_clickable() self.web_element.click() def get_attribute(self, attribute: WebElementAttributes) -> str:
class TestVkApi: browser = Browser() def setup_class(self): self.browser.maximize() self.browser.set_implicitly_wait(config.TIMEOUT) def setup_method(self): Step.steps_counter = 1 if os.path.exists(config.PATH_TO_DOWNLOAD_JPG_PICTURE): os.remove(config.PATH_TO_DOWNLOAD_JPG_PICTURE) if os.path.exists(config.PATH_TO_DOWNLOAD_PNG_PICTURE): os.remove(config.PATH_TO_DOWNLOAD_PNG_PICTURE) with Step(f"Go to {config.URL}"): self.browser.enter_url(config.URL) unauthorized_page = UnauthorizedPage() assert unauthorized_page.is_page_opened( ), "Unauthorized_page wasn't opened" def teardown_method(self): log_out() def teardown_class(self): self.browser.close() def test_vk_case_1(self): with Step("Authorize as User_1"): log_in(vk_config.LOGIN_1, vk_config.PASSWORD_1) news_page = NewsPage() assert news_page.is_page_opened(), "News page wasn't opened" with Step("Go to my page"): news_page.side_bar.navigate_to(SideBarItems.MY_PAGE) my_page = MyPage() assert my_page.is_page_opened(), "My page wasn't opened" with Step("Creating post with random line and getting post's id"): random_string = get_random_string() owner_id = my_page.header.owner_id post_id = create_new_post(random_string, vk_config.ACCESS_TOKEN_1) assert my_page.post_form.is_post_displayed( post_id, owner_id, random_string), "Post wasn't published" with Step("Editing post and upload picture"): edited_random_string = f"edited_{random_string}" uploaded_photo_id = edit_post_and_attach_file( edited_random_string, VkAttachmentsTypes.PHOTO, post_id, config.PATH_TO_JPG_PICTURE, vk_config.ACCESS_TOKEN_1) assert my_page.post_form.is_post_displayed( post_id, owner_id, edited_random_string), "Post wasn't edited" assert is_photo_uploaded(uploaded_photo_id, config.PATH_TO_JPG_PICTURE, config.PATH_TO_DOWNLOAD_JPG_PICTURE ), "Photo wasn't uploaded to post" with Step("Adding random comment to the post"): random_comment = get_random_string() add_comment_to_post(random_comment, post_id, vk_config.ACCESS_TOKEN_1) assert my_page.post_form.is_comment_added( owner_id, random_comment), "Comment wasn't added" with Step("Like edited post"): my_page.post_form.like_post(post_id) assert is_item_liked_by_user( VkItems.POST, post_id, owner_id, vk_config.ACCESS_TOKEN_1), "Post wasn't liked" with Step("Delete created post"): delete_post(post_id, vk_config.ACCESS_TOKEN_1) assert is_post_deleted(post_id), "Post wasn't deleted" def test_vk_case_2(self): with Step("Authorize as User_1"): log_in(vk_config.LOGIN_1, vk_config.PASSWORD_1) news_page = NewsPage() assert news_page.is_page_opened(), "News page wasn't opened" with Step("Go to my page"): news_page.side_bar.navigate_to(SideBarItems.MY_PAGE) my_page = MyPage() assert my_page.is_page_opened(), "My page wasn't opened" with Step("Creating post with random line and getting post's id"): random_string = get_random_string() first_user_page_url = self.browser.get_current_url() first_user_id = my_page.header.owner_id post_id = create_new_post(random_string, vk_config.ACCESS_TOKEN_1) assert my_page.post_form.is_post_displayed( post_id, first_user_id, random_string), "Post wasn't published" with Step("Like created post as User_1"): my_page.post_form.like_post(post_id) with Step("Log out"): log_out() with Step(f"Go to {config.URL}"): self.browser.enter_url(config.URL) unauthorized_page = UnauthorizedPage() assert unauthorized_page.is_page_opened( ), "Unauthorized_page wasn't opened" with Step("Authorize as User_1"): log_in(vk_config.LOGIN_2, vk_config.PASSWORD_2) news_page_for_second_user = NewsPage() assert news_page_for_second_user.is_page_opened( ), "News page for second user wasn't opened" with Step(f"Go to {first_user_page_url}"): self.browser.enter_url(first_user_page_url) assert my_page.is_page_opened( ), "Main page for first user wasn't opened" second_user_id = my_page.header.owner_id with Step(f"Check that created post is on the first user's page"): assert my_page.post_form.is_post_displayed( post_id, first_user_id, random_string), "Created post is absent" with Step("Like post by User_2"): my_page.post_form.like_post(post_id) wait_while_entering_captcha() with Step("Check that post was liked by User_1 and User_2"): assert is_item_liked_by_user( VkItems.POST, post_id, first_user_id, vk_config.ACCESS_TOKEN_1), "Post wasn't liked by User_1" assert is_item_liked_by_user( VkItems.POST, post_id, second_user_id, vk_config.ACCESS_TOKEN_1), "Post wasn't liked by User_2" def test_vk_case_3(self): with Step("Authorize as User_1"): log_in(vk_config.LOGIN_1, vk_config.PASSWORD_1) news_page = NewsPage() assert news_page.is_page_opened(), "News page wasn't opened" with Step("Go to my page"): news_page.side_bar.navigate_to(SideBarItems.MY_PAGE) my_page = MyPage() assert my_page.is_page_opened(), "My page wasn't opened" with Step("Creating post with random line and getting post's id"): random_string = get_random_string() user_page_url = self.browser.get_current_url() user_id = my_page.header.owner_id post_id = create_new_post(random_string, vk_config.ACCESS_TOKEN_1) assert my_page.post_form.is_post_displayed( post_id, user_id, random_string), "Post wasn't published" with Step("Log out"): log_out() with Step(f"Go to {config.URL}"): self.browser.enter_url(config.URL) unauthorized_page = UnauthorizedPage() assert unauthorized_page.is_page_opened( ), "Unauthorized_page wasn't opened" with Step(f"Go to {user_page_url}"): self.browser.enter_url(user_page_url) assert my_page.is_page_opened( ), "Main page for first user wasn't opened" with Step(f"Check that created post is on the user's page"): assert my_page.post_form.is_post_displayed( post_id, user_id, random_string), "Created post is absent" def test_vk_case_4(self): with Step("Authorize as User_1"): log_in(vk_config.LOGIN_1, vk_config.PASSWORD_1) news_page = NewsPage() assert news_page.is_page_opened(), "News page wasn't opened" with Step("Navigate to my page"): news_page.side_bar.navigate_to(SideBarItems.MY_PAGE) my_page = MyPage() assert my_page.is_page_opened(), "My page wasn't opened" with Step("Creating post with random line and getting post's id"): random_string = get_random_string() owner_id = my_page.header.owner_id post_id = create_new_post(random_string, vk_config.ACCESS_TOKEN_1) assert my_page.post_form.is_post_displayed( post_id, owner_id, random_string), "Post wasn't published" with Step("Editing post with random line and uploading doc"): edited_message = f"edited_{random_string}" edit_post_and_attach_file(edited_message, VkAttachmentsTypes.DOC, post_id, config.PATH_TO_FILE, vk_config.ACCESS_TOKEN_1) with Step("Check that post was edited"): assert my_page.post_form.is_post_displayed( post_id, owner_id, edited_message), "Post wasn't edited" assert is_doc_uploaded( post_id, config.PATH_TO_FILE), "File wasn't uploaded to post" with Step("Adding random comment to the post"): random_comment = get_random_string() add_comment_to_post(random_comment, post_id, vk_config.ACCESS_TOKEN_1) assert my_page.post_form.is_comment_added( owner_id, random_comment), "Comment wasn't added" with Step("Like edited post"): my_page.post_form.like_post(post_id) assert is_item_liked_by_user( VkItems.POST, post_id, owner_id, vk_config.ACCESS_TOKEN_1), "Post wasn't liked" with Step("Delete created post"): delete_post(post_id, vk_config.ACCESS_TOKEN_1) assert is_post_deleted(post_id), "Post wasn't deleted" def idfn(val): return "params: {0}".format(str(val)) @pytest.fixture(scope="function", params=[ (config.PATH_TO_JPG_PICTURE, config.PATH_TO_DOWNLOAD_JPG_PICTURE), (config.PATH_TO_PNG_PICTURE, config.PATH_TO_DOWNLOAD_PNG_PICTURE), ], ids=idfn) def parameters_for_case_5(self, request): return request.param def test_vk_case_5(self, parameters_for_case_5): path_to_picture, path_to_downloaded_picture = parameters_for_case_5 with Step("Authorize as User_2"): log_in(vk_config.LOGIN_2, vk_config.PASSWORD_2) news_page = NewsPage() assert news_page.is_page_opened(), "News page wasn't opened" with Step("Navigate to my page"): news_page.side_bar.navigate_to(SideBarItems.MY_PAGE) my_page = MyPage() assert my_page.is_page_opened(), "My page wasn't opened" with Step( "Creating post with random line and photo and getting post's id" ): random_string = get_random_string() owner_id = my_page.header.owner_id post_id, uploaded_photo_id = create_new_post_with_attachment( random_string, VkAttachmentsTypes.PHOTO, path_to_picture, vk_config.ACCESS_TOKEN_2) assert my_page.post_form.is_post_displayed( post_id, owner_id, random_string), "Post wasn't created" assert is_photo_uploaded( uploaded_photo_id, path_to_picture, path_to_downloaded_picture), "Photo wasn't uploaded to post"
def __init__(self): self.driver = Browser().get_driver()
def __init__(self, timeout: int, poll_frequency: int = 0): self.__web_driver_wait = WebDriverWait(Browser().driver, timeout, poll_frequency=poll_frequency)