def test_invalid_credentials(self, username, email, password, confirm_password,
                                 registration_page: RegistrationPage):
        """Test registration with invalid credentials

        Steps:
            - Open registration page and try to pass registration
        Expected results:
            Current page url path doesn't contain 'welcome', so the current page is main
        """
        with pytest.raises(RegistrationError):
            registration_page.pass_registration(username=username, email=email,
                                                password=password,
                                                confirm_password=confirm_password)
示例#2
0
    def setup(self, driver, db_connection):
        self.driver: webdriver = driver

        self.login_page: LoginPage = LoginPage(driver)
        self.registration_page: RegistrationPage = RegistrationPage(driver)
        self.welcome_page: WelcomePage = WelcomePage(driver)

        self.mysql_client = db_connection
 def test_authorization_positive(self, username, email, password,
                                 registration_page: RegistrationPage):
     """Test authorization after registration"""
     main_page = registration_page.pass_registration(username=username, email=email,
                                                     password=password)
     authorization_page = main_page.logout()
     authorization_page.authorize(username=username, password=password)
     allure.attach.file(main_page.make_screenshot('test_authorization_positive'),
                        attachment_type=allure.attachment_type.PNG)
     main_page.check_url()
    def test_valid_credentials(self, username, email, password,
                               registration_page: RegistrationPage):
        """Test registration with valid credentials

        Steps:
            - Open registration page and try to pass registration
        Expected results:
            Current page url path contains 'welcome', so the current page is main
        """
        try:
            main_page = registration_page.pass_registration(username=username, email=email,
                                                            password=password)
        except RegistrationError as err:
            raise AssertionError from err
        main_page.check_url()
 def test_integrity(self, username, email, password, registration_page: RegistrationPage):
     """Test integrity of registration and authorization"""
     try:
         main_page = registration_page.pass_registration(username=username, email=email,
                                                         password=password)
     except RegistrationError:
         with allure.step('Registration not succeed. Check that authorization will not succeed'):
             authorization_page = AuthorizationPage(registration_page.driver,
                                                    registration_page.settings)
             authorization_page.make_request()  # open authorization page
             with pytest.raises(AuthorizationError):
                 authorization_page.authorize(username=username, password=password)
     else:
         with allure.step('Registration succeed. Check that authorization will succeed'):
             authorization_page = main_page.logout()
             try:
                 authorization_page.authorize(username=username, password=password)
             except AuthorizationError as err:
                 allure.attach.file(
                     authorization_page.make_screenshot('not_succeed_authorization'),
                     attachment_type=allure.attachment_type.PNG,
                     name='not_succeed_authorization.png')
                 raise AssertionError from err  # to mark test as failed, not broken
示例#6
0
def registration_page(driver, settings):
    page = RegistrationPage(driver, settings)
    page.make_request()
    return page
示例#7
0
    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
示例#8
0
def registration_page(driver):
    return RegistrationPage(driver=driver)
示例#9
0
def test_scenario1(registration_page: RegistrationPage, api_client: ApiClient):
    """Test how API functions influence user

    Steps:
        1 Pass registration with generated credentials
        2 Block user via block_user API function
        3 Refresh page
        4 Open registration page and try to register with the same credentials again
        5 Open authorization page and try to authorize to the site with the same credentials
        6 Accept user via accept_user API function
        7 Refresh page
        8 Delete user via del_user API function
        9 Refresh page
        0 Open authorization page and try to authorize to the site with the same credentials
        1 Open registration page and register with same credentials again
    Expected results:
        Steps 1-2 succeed
        Step 3 redirect to authrization page
        Steps 4-5 fail, pytest.raises catch Exception
        Step 6 succeed
        Step 7 redirect to main page
        Step 8 succeed
        Step 9 redirect to authorization page
        Step 10 fail, pytest.raises catch Exception
        Step 11 succeed
    """
    username, email, password = make.auth_data()
    with allure.step("Pass registration"):
        main_page = registration_page.pass_registration(username=username,
                                                        password=password,
                                                        email=email)
        assert 'welcome' in urlparse(main_page.current_url).path
    with allure.step(f"Block user {username}"):
        response = api_client.block_user(username)
        attach_http(response)
    with allure.step("Refresh page"):
        main_page.refresh()
        assert 'welcome' not in urlparse(main_page.current_url).path
    with allure.step(
            "Open registration page and try to register with same credentials again"
    ):
        registration_page.make_request()
        with pytest.raises(RegistrationError):
            registration_page.pass_registration(username=username,
                                                email=email,
                                                password=password)
    with allure.step("Try to authorize"):
        authorization_page = registration_page.go_to_authorization_page()
        with pytest.raises(AuthorizationError):
            authorization_page.authorize(username=username, password=password)
    with allure.step("Accept user"):
        response = api_client.accept_user(username)
        attach_http(response)
    with allure.step('User was redirected to main page after refresh'):
        authorization_page.refresh()
        assert 'welcome' in urlparse(authorization_page.current_url).path
    with allure.step("Delete user"):
        api_client.del_user(username)
        attach_http(response)
    with allure.step("User was redirected from main page after refresh"):
        main_page.refresh()
        assert 'welcome' not in urlparse(authorization_page.current_url).path
    with allure.step("Try to authorize"):
        authorization_page.make_request()
        with pytest.raises(AuthorizationError):
            authorization_page.authorize(username=username, password=password)
    with allure.step("Pass registration"):
        registration_page.make_request()
        registration_page.pass_registration(username=username,
                                            email=email,
                                            password=password)
def main_page(registration_page: RegistrationPage):
    username, email, password = make.auth_data()
    return registration_page.pass_registration(username=username,
                                               email=email,
                                               password=password)
 def main_page(self, registration_page: RegistrationPage):
     """Fixture-helper to open main page of new user"""
     username, email, password = make.auth_data()
     return registration_page.pass_registration(username=username, email=email,
                                                password=password)