<commit_before>/**
 * Copyright (C) 2011 JTalks.org Team
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

package org.jtalks.tests.jcommune.webdriver.action;


import org.jtalks.tests.jcommune.mail.pochta.PochtaMail;
import org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig;
import org.jtalks.tests.jcommune.webdriver.entity.user.User;
import org.jtalks.tests.jcommune.webdriver.entity.user.UserForRegistration;
import org.jtalks.tests.jcommune.webdriver.exceptions.CouldNotOpenPageException;
import org.jtalks.tests.jcommune.webdriver.exceptions.ValidationException;
import org.jtalks.tests.jcommune.webdriver.page.MainPage;
import org.jtalks.tests.jcommune.webdriver.page.SignUpPage;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.yandex.qatools.allure.annotations.Step;

import java.util.List;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.jtalks.tests.jcommune.utils.ReportNgLogger.info;
import static org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig.driver;
import static org.jtalks.tests.jcommune.webdriver.page.Pages.*;

/**
 * Contain user actions like sign in, sign out etc.
 *
 * @author <NAME>
 */
public class Users {
    private static final Logger LOGGER = LoggerFactory.getLogger(Users.class);

    /**
     * Sign in user by dialog. Action can by started from any page of JCommune.
     *
     * @param user the {@code User} instance with sign in form data
     * @throws ValidationException
     */
    @Step
    public static void signIn(User user) throws ValidationException {
        info("Sign in a User: " + user);
        openAndFillSignInDialog(user);
        signInPage.clickSubmitButton();
        checkFormValidation(signInPage.getErrorFormElements());
        try {
            signInPage.waitSignInDialogToClose();
        } catch (TimeoutException e) {
            info("WARNING: Sign in dialog is still opened. Might be laggy. Check validation once again.");
            checkFormValidation(signInPage.getErrorFormElements());
            signInPage.waitSignInDialogToClose();
        }
        // Check that link to the user profile present on the page
        if (!mainPage.userIsLoggedIn()) {
            LOGGER.error("Could not find username in top right corner: {}", driver.getPageSource());
            throw new CouldNotOpenPageException("User does not appear to be logged on: " + user.getUsername());
        }
    }

    @Step
    public static void logOutAndSignIn(User user) throws ValidationException {
        logout();
        signIn(user);
    }

    @Step
    public static void logout() {
        mainPage.clickLogout();<commit_msg>#JC-1739 add Steps  for User - possibility to clear all cookies after logout; - chain for logout, signup and signin;<commit_after>/**
 * Copyright (C) 2011 JTalks.org Team
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

package org.jtalks.tests.jcommune.webdriver.action;


import org.jtalks.tests.jcommune.mail.pochta.PochtaMail;
import org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig;
import org.jtalks.tests.jcommune.webdriver.entity.user.User;
import org.jtalks.tests.jcommune.webdriver.entity.user.UserForRegistration;
import org.jtalks.tests.jcommune.webdriver.exceptions.CouldNotOpenPageException;
import org.jtalks.tests.jcommune.webdriver.exceptions.ValidationException;
import org.jtalks.tests.jcommune.webdriver.page.MainPage;
import org.jtalks.tests.jcommune.webdriver.page.SignUpPage;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.yandex.qatools.allure.annotations.Step;

import java.util.List;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.jtalks.tests.jcommune.utils.ReportNgLogger.info;
import static org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig.driver;
import static org.jtalks.tests.jcommune.webdriver.page.Pages.mainPage;
import static org.jtalks.tests.jcommune.webdriver.page.Pages.profilePage;
import static org.jtalks.tests.jcommune.webdriver.page.Pages.signInPage;
import static org.jtalks.tests.jcommune.webdriver.page.Pages.signUpPage;

/**
 * Contain user actions like sign in, sign out etc.
 *
 * @author <NAME>
 */
public class Users {
    private static final Logger LOGGER = LoggerFactory.getLogger(Users.class);

    /**
     * Sign in user by dialog. Action can by started from any page of JCommune.
     *
     * @param user the {@code User} instance with sign in form data
     * @throws ValidationException
     */
    @Step
    public static void signIn(User user) throws ValidationException {
        info("Sign in a User: " + user);
        openAndFillSignInDialog(user);
        signInPage.clickSubmitButton();
        checkFormValidation(signInPage.getErrorFormElements());
        try {
            signInPage.waitSignInDialogToClose();
        } catch (TimeoutException e) {
            info("WARNING: Sign in dialog is still opened. Might be laggy. Check validation once again.");
            checkFormValidation(signInPage.getErrorFormElements());
            signInPage.waitSignInDialogToClose();
        }
        // Check that link to the user profile present on the page
        if (!mainPage.userIsLoggedIn()) {
            LOGGER.error("Could not find username in top right corner: {}", driver.getPageSource());
            throw new CouldNotOpenPageException("User does not appear to be logged on: " + user.getUsername());
        }
    }

    @Step
    public static void logOutAndSignIn(User user) throws ValidationException {
        logout();
        signIn(user);
    }

    @Step
    public static void logout() {
        mainPage.clickLogout();
    }

    @Step
    public static void logoutSignUpAndSignIn() {
        logout();
        signUpAndSignIn();
    }

    @Step
    public static void logoutAndDeleteAllCookies() {
        mainPage.clickLogout();
        driver.manage().deleteAllCookies();
{'fraction_non_alphanumeric': 0.08842297174111212, 'fraction_numerical': 0.0054694621695533276, 'mean_word_length': 3.7087676272225627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5741687', 'n_tokens_mistral': 2244, 'n_tokens_neox': 2191, 'n_words': 647}