001/*
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package edu.samplu.common;
017
018import org.junit.Assert;
019import org.junit.runner.RunWith;
020
021/**
022 * SmokeTests should extend this Base class or have it in their class hierarchy.
023 *
024 * The abstract method getBookmarkUrl should be implemented to return the Bookmark URL
025 * of the page under test.  The abstract method navigate should be implemented to Navigate
026 * through the UI to the page under test.
027 */
028@RunWith(SmokeTestRunner.class)
029public abstract class SmokeTestBase extends WebDriverLegacyITBase {
030
031    protected String testUrl = ITUtil.KRAD_PORTAL;
032
033    protected boolean shouldNavigate = false;
034
035    protected abstract String getBookmarkUrl();
036
037    protected abstract void navigate() throws Exception;
038
039    @Override
040    public String getTestUrl() {
041//        if (this.getClass().toString().contains("krad.demo") ||
042//            this.getClass().toString().contains("krad.labs")) {
043            return testUrl;
044//        } else {
045//            return ITUtil.PORTAL;
046//        }
047    }
048
049    protected void enableBookmarkMode() {
050        this.testUrl = getBookmarkUrl();
051    }
052
053    protected void enableNavigationMode() {
054        this.shouldNavigate = true;
055        String classString = this.getClass().toString();
056        if (classString.contains("krad.demo") || classString.contains("library")) {
057            this.testUrl = ITUtil.KRAD_PORTAL;
058        } else if (classString.contains("krad.library")) {
059            this.testUrl = ITUtil.KRAD_PORTAL;
060        } else if (classString.contains("krad.labs")) {
061            this.testUrl = ITUtil.LABS;
062        } else {
063            this.testUrl = ITUtil.PORTAL;
064        }
065    }
066
067    @Override
068    public void fail(String message) {
069        passed = false;
070        Assert.fail(message);
071    }
072
073    @Override
074    protected void navigateInternal() throws Exception {
075        if (this.shouldNavigate) {
076            navigate();
077        }
078    }
079}