Advertisement
Guest User

Untitled

a guest
Mar 15th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. package com.tonicforhealth.test.core.page.web.logIn;
  2.  
  3. import com.tonicforhealth.test.core.api.mailcatcher.MailCatcherApiClient;
  4. import com.tonicforhealth.test.core.extension.selenide.AopLoggingFactory;
  5. import com.tonicforhealth.test.core.page.web.HomePage;
  6. import com.tonicforhealth.test.core.page.web.adminaccount.AdminHomePage;
  7. import com.tonicforhealth.test.core.page.web.mytonic.AbstractWebPage;
  8.  
  9. import org.springframework.stereotype.Component;
  10.  
  11. import java.util.regex.Matcher;
  12. import java.util.regex.Pattern;
  13.  
  14. import static com.codeborne.selenide.Selenide.$;
  15. import static com.tonicforhealth.test.core.extension.selenide.AopLoggingFactory.page;
  16.  
  17. /**
  18.  * @author Created by Vladimir Seleznov <v.e.seleznov@gmail.com> on 6/21/16.
  19.  */
  20. @Component
  21. public class LoginPage extends AbstractWebPage<LoginPage> {
  22.  
  23.     private static final String USERNAME = "#username";
  24.     private static final String PASSWORD = "#password";
  25.     private static final String FORGOT_PASSWORD_LINK = "strong";
  26.  
  27.     private static final String ALREADY_A_MEMBER_LINK = ".widget-login-form__reset_password strong";
  28.     private static final String RESET_PASSWORD_BUTTON = "#_submit";
  29.  
  30.     private static final String RESET_PASSWORD_NEW = "#fos_user_resetting_form_password";
  31.     private static final String RESET_PASSWORD_CONFIRM = "#fos_user_resetting_form_confirmPassword";
  32.  
  33.     public HomePage builderLogIn(String username, String password) {
  34.         $(USERNAME).setValue(username);
  35.         $(PASSWORD).click();
  36.         $(PASSWORD).setValue(password).pressEnter();
  37.  
  38.         return page(HomePage.class);
  39.     }
  40.  
  41.     public AdminHomePage adminAccountLogIn(String username, String password) {
  42.         $(USERNAME).setValue(username);
  43.         $(PASSWORD).click();
  44.         $(PASSWORD).setValue(password).pressEnter();
  45.  
  46.         return page(AdminHomePage.class);
  47.     }
  48.  
  49.     public LoginPage open() {
  50.         AopLoggingFactory.open("/builder/login");
  51.  
  52.         return this;
  53.     }
  54.  
  55.     public LoginPage clickForgotPasswordLink() {
  56.         $(FORGOT_PASSWORD_LINK).click();
  57.  
  58.         return this;
  59.     }
  60.  
  61.     public LoginPage clickAlreadyAMemberLink() {
  62.         $(ALREADY_A_MEMBER_LINK).click();
  63.  
  64.         return this;
  65.     }
  66.  
  67.     public LoginPage clickResetPasswordButton() {
  68.         $(RESET_PASSWORD_BUTTON).click();
  69.  
  70.         return this;
  71.     }
  72.  
  73.     public LoginPage setEmail(String email) {
  74.         $(USERNAME).setValue(email);
  75.  
  76.         return this;
  77.     }
  78.  
  79.     public LoginPage setNewPassword(String password) {
  80.         $(RESET_PASSWORD_NEW).setValue(password);
  81.  
  82.         return this;
  83.     }
  84.  
  85.     public LoginPage setConfirmPassword(String password) {
  86.         $(RESET_PASSWORD_CONFIRM).setValue(password);
  87.  
  88.         return this;
  89.     }
  90.  
  91.     public LoginPage clickChangePasswordButton() {
  92.         $(RESET_PASSWORD_BUTTON).click();
  93.  
  94.         return this;
  95.     }
  96.  
  97.     public LoginPage openResetPasswordPageByLinkFromLastEmail() {
  98.         MailCatcherApiClient api = new MailCatcherApiClient();
  99.  
  100.         String email = api.getEmailContent(api.getIdOfLastEmail());
  101.  
  102.         Pattern p = Pattern.compile("\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]",
  103.                 Pattern.CASE_INSENSITIVE);
  104.         Matcher m = p.matcher(email);
  105.         String s = null;
  106.         while (m.find()) {
  107.             s = m.group(0);
  108.         }
  109.  
  110.         AopLoggingFactory.open(s);
  111.  
  112.         return this;
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement