package com.seleniumtests.webpage;

import com.seleniumtests.dataobject.User;
import com.seleniumtests.driver.web.WebUXDriver;
import com.seleniumtests.driver.web.element.Button;
import com.seleniumtests.driver.web.element.Link;
import com.seleniumtests.driver.web.element.TextField;
import com.seleniumtests.driver.web.element.WebPage;
import org.openqa.selenium.By;

/**
 * User: tbhadauria
 * Date: 10/2/13
 * Time: 6:15 PM
 */
public class TestLinkLoginPage extends WebPage {

    private static final String PAGE_URL = "http://www.seleniumtests.com/2013/08/demo-test-link-site.html";

    // Page identifier field is set to seleniumtests.com as TestLink appears in iframe
    private static Link seleniumTrainingLink = new Link("Selenium Training Link", By.linkText("Free Selenium Training"));
    private static TextField loginTextBox = new TextField("Login Text Box", By.id("login"));


    public TestLinkLoginPage() throws Exception {
        // verifies that loginTextBox appears on login page else test would not make sense
        super(loginTextBox);
    }

    /**
     * Opens log in page
     * @param openPageUrl
     * @throws Exception
     */
    public TestLinkLoginPage (boolean openPageUrl) throws Exception {
        super(seleniumTrainingLink, openPageUrl ? PAGE_URL : null, true);
        getDriver().switchTo().frame(getDriver().findElement(By.id("testlink"))); // Switch to test link frame
    }

    private TextField passwordTextBox = new TextField("Password Te  xt Box", By.name("tl_password"));
    private Button loginButton = new Button("Login Button", By.name("login_submit"));


    public AdminHomePage login(User user) throws Exception {
        loginTextBox.clear();
        loginTextBox.sendKeys(user.getUserID());
        passwordTextBox.clear();
        passwordTextBox.sendKeys(user.getPassword());
        loginButton.submit();
        return new AdminHomePage();
    }
}
@@ -29,16 +29,63 @@
 bpage;%0A%0A
+import com.seleniumtests.controller.Assertion;%0A
 import c
@@ -1038,16 +1038,27 @@
 on login
+AsValidUser
  page el
@@ -1661,24 +1661,171 @@
 submit%22));%0A%0A
+    /**%0A     * Logging in with valid credentials direct user to home page%0A     *%0A     * @param user%0A     * @return%0A     * @throws Exception%0A     */
 %0A    public 
@@ -1843,16 +1843,27 @@
 ge login
+AsValidUser
 (User us
@@ -2122,10 +2122,754 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Logging in with invalid credentials keeps user on login page%0A     *%0A     * @param user%0A     * @return%0A     * @throws Exception%0A     */%0A    public TestLinkLoginPage loginAsInvalidUser(User user) throws Exception %7B%0A        loginTextBox.clear();%0A        loginTextBox.sendKeys(user.getUserID());%0A        passwordTextBox.clear();%0A        passwordTextBox.sendKeys(user.getPassword());%0A        loginButton.submit();%0A        return this;%0A    %7D%0A%0A    public TestLinkLoginPage verifyLoginBoxPresence() %7B%0A        getDriver().switchTo().frame(getDriver().findElement(By.id(%22testlink%22)));%0A        Assertion.assertTrue(isElementPresent(loginTextBox.getBy()), %22Invalid credentials don't block user from logging in%22);%0A        return this;%0A    %7D
 %0A%7D

switch to frame