/*
 * Copyright (c) 2005-2010 Grameen Foundation USA
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * See also http://www.apache.org/licenses/LICENSE-2.0.html for an
 * explanation of the license and how it is applied.
 */

package org.mifos.test.acceptance.framework;

import com.thoughtworks.selenium.Selenium;

/**
 * Base class for all Page objects - There should be a Page object for each page referenced in an Selenium-based
 * acceptance test. Page objects should be the place that all verification and navigation is done, to keep this activity
 * in one place. If the web page changes, then only one class needs to change to make all the tests that reference it
 * work.
 */
public class AbstractPage {

    private static final String MAX_WAIT_FOR_PAGE_TO_LOAD_IN_MILLISECONDS = "30000";
    protected Selenium selenium;

    public AbstractPage() {
        // do nothing
    }

    public AbstractPage(Selenium selenium) {
        this.selenium = selenium;
    }

    protected void waitForPageToLoad() {
        selenium.waitForPageToLoad(MAX_WAIT_FOR_PAGE_TO_LOAD_IN_MILLISECONDS);
    }

    final public void setSelenium(Selenium selenium) {
        this.selenium = selenium;
    }

    public Selenium getSelenium() {
        return this.selenium;
    }

    public void openUri(String uri) {
        selenium.open(uri);
        waitForPageToLoad();
    }

    public void verifyPage(String pageName) {
        if (!selenium.getAttribute("page.id@title").equals(pageName)) {
            System.err.println("We are on " + selenium.getAttribute("page.id@title") + " instead!");
            throw new AssertionError("page id not found");
        }

    }

}

@@ -844,16 +844,42 @@
 elenium;
+%0Aimport org.testng.Assert;
 %0A%0A/**%0A *
@@ -912,16 +912,19 @@
 bjects -
+%0A *
  There s
@@ -991,19 +991,16 @@
 um-based
-%0A *
  accepta
@@ -1008,16 +1008,19 @@
 ce test.
+%0A *
  Page ob
@@ -1090,16 +1090,19 @@
 is done,
+%0A *
  to keep
@@ -1115,19 +1115,16 @@
 activity
-%0A *
  in one 
@@ -1174,16 +1174,19 @@
 ne class
+%0A *
  needs t
@@ -1233,19 +1233,16 @@
 rence it
-%0A *
  work.%0A 
@@ -1991,242 +1991,78 @@
     
-if (!selenium.getAttribute(%22page.id@title%22).equals(pageName)) %7B%0A            System.err.println(%22We are on %22 + selenium.getAttribute(%22page.id@title%22) + %22 instead!%22);%0A            throw new AssertionError(%22page id not found%22);%0A        %7D%0A
+Assert.assertEquals(selenium.getAttribute(%22page.id@title%22), pageName);
 %0A   

Revert "FIXED MIFOS-3883: Show current page in console when the expected page is not reached in acceptance tests"