/**
 * Created with IntelliJ IDEA.
 * User: jhasmanyquiroz
 * Date: 11/11/15
 * Time: 11:22 AM
 * To change this template use File | Settings | File Templates.
 */
package ui.pages;

import framework.BrowserManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import ui.BasePageObject;

public class LoginPage extends BasePageObject {
    private BrowserManager browser;
    private WebElement element;

    public LoginPage() {
        super();
        browser = BrowserManager.getInstance();
        //PageFactory.initElements(driver, this);
        //waitUntilPageObjectIsLoaded();
    }

    private void enterEmail(String email) {
        element = browser.getDriver().findElement(By.name("email"));
        element.clear();
        element.sendKeys(email);
    }

    private void enterPassword(String pass) {
        element = browser.getDriver().findElement(By.name("password"));
        element.clear();
        element.sendKeys(pass);
    }

    private void clickLogInButton() {
        element = browser.getDriver().findElement(By.xpath("//button[contains(@data-js,'submit')]"));
        //element = browser.getDriver().findElement(By);
        element.click();
    }

    public HomePage loginAs(String email, String pass) {
        enterEmail(email);
        enterPassword(pass);
        clickLogInButton();
        HomePage page = new HomePage();

        return page;
    }

    public void waitUntilPageObjectIsLoaded() {
        //To change body of implemented methods use File | Settings | File Templates.
        //wait.until();
    }
}
@@ -187,32 +187,86 @@
 ort 
-framework.BrowserManager
+org.openqa.selenium.WebElement;%0Aimport org.openqa.selenium.support.CacheLookup
 ;%0Aim
@@ -290,16 +290,28 @@
 elenium.
+support.Find
 By;%0Aimpo
@@ -329,34 +329,101 @@
 qa.selenium.
-WebElement
+support.PageFactory;%0Aimport org.openqa.selenium.support.ui.ExpectedConditions
 ;%0Aimport ui.
@@ -491,166 +491,300 @@
 t %7B%0A
+%0A
     
-private BrowserManager browser;%0A    private WebElement element;%0A%0A    public LoginPage() %7B%0A        super();%0A        browser = BrowserManager.getInstance();
+@FindBy(name = %22email%22)%0A    @CacheLookup%0A    private WebElement emailInput;%0A%0A    @FindBy(name = %22password%22)%0A    @CacheLookup%0A    private WebElement passwordInput;%0A%0A    @FindBy(xpath = %22//button%5Bcontains(@data-js,'submit')%5D%22)%0A    private  WebElement loginButton;%0A%0A    public LoginPage() %7B
 %0A   
@@ -788,18 +788,16 @@
         
-//
 PageFact
@@ -832,26 +832,24 @@
 s);%0A        
-//
 waitUntilPag
@@ -882,28 +882,33 @@
     private 
-void
+LoginPage
  enterEmail(
@@ -936,82 +936,16 @@
    e
-lement = browser.getDriver().findElement(By.name(%22email%22));%0A        elemen
+mailInpu
 t.cl
@@ -952,37 +952,40 @@
 ear();%0A        e
-lemen
+mailInpu
 t.sendKeys(email
@@ -983,24 +983,45 @@
 eys(email);%0A
+        return this;%0A
     %7D%0A%0A    p
@@ -1027,20 +1027,25 @@
 private 
-void
+LoginPage
  enterPa
@@ -1078,86 +1078,20 @@
     
-element = browser.getDriver().findElement(By.name(%22password%22));%0A        elemen
+passwordInpu
 t.cl
@@ -1105,22 +1105,28 @@
         
-elemen
+passwordInpu
 t.sendKe
@@ -1131,24 +1131,45 @@
 Keys(pass);%0A
+        return this;%0A
     %7D%0A%0A    p
@@ -1175,20 +1175,24 @@
 private 
-void
+HomePage
  clickLo
@@ -1192,24 +1192,34 @@
 clickLog
-I
+i
 nButton
+Successful
 () %7B%0A   
@@ -1227,218 +1227,195 @@
     
-element = browser.getDriver().findElement(By.xpath(%22//button%5Bcontains(@data-js,'submit')%5D%22));%0A        //element = browser.getDriver().findElement(By);%0A        element.click();%0A    %7D%0A%0A    public HomePage
+loginButton.click();%0A        return new HomePage();%0A    %7D%0A%0A    private LoginPage clickLoginButtonFailed() %7B%0A        loginButton.click();%0A        return this;%0A    %7D%0A%0A    private void
  login
-As
 (Str
@@ -1504,20 +1504,135 @@
     
+%7D%0A%0A
     
+public HomePage loginSuccessful(String email, String password) %7B%0A        login(email, password);%0A        return 
 clickLog
 InBu
@@ -1631,24 +1631,34 @@
 kLog
-I
+i
 nButton
+Successful
 ();%0A    
     
@@ -1657,45 +1657,109 @@
     
+%7D%0A%0A
     
-HomePage page = new HomePage(
+public LoginPage loginFailed(String email, String password) %7B%0A        login(email, password
 );%0A
-%0A
     
@@ -1769,20 +1769,40 @@
  return 
-page
+clickLoginButtonFailed()
 ;%0A    %7D%0A
@@ -1862,107 +1862,63 @@
     
-//To change body of implemented methods use File %7C Settings %7C File Templates.%0A        //wait.until(
+wait.until(ExpectedConditions.visibilityOf(loginButton)
 );%0A 

Implement the Page Factory Pattern and methods for login