All Downloads are FREE. Search and download functionalities are using the official Maven repository.

automated.platforms.web.WebActions Maven / Gradle / Ivy

The newest version!
package automated.platforms.web;

import automated.process.strings.StringProcess;
import automated.reporting.TestReporter;
import automated.test_manage.actions.Actions;
import automated.test_manage.config.Platform;
import automated.test_manage.run.TestCaseFiles;
import automated.process.strings.StringProcess;
import automated.reporting.TestReporter;
import automated.test_manage.actions.Actions;
import automated.test_manage.config.Platform;
import automated.test_manage.run.TestCaseFiles;

/**
 * Created by Ismail on 12/27/2017.
 * This Class contains all related methods and their implementation
 * for Web application actions
 */
public class WebActions {

    /*************** Class Methods Section ***************/
    // This method return current Title for current active browser tab
    public static String getCurrentTitle() {
        return Platform.driver.getTitle();
    }

    // This method do action navigateTo
    public static void navigateTo(String url) {
        // Check if URL Provided from TestCase File
        if (!TestCaseFiles.getTestCaseProperty(url).isEmpty())
            url = TestCaseFiles.getTestCaseProperty(url);

        // Check if baseUrl provided then concat with Url string
        if (!Platform.baseUrl.isEmpty())
            url = Platform.baseUrl + url;

        // Check if THe Provided is one of navigateTo actions or URL
        // and execute the action
        switch (url.toLowerCase()) {
            case "back": {
                Platform.driver.navigate().back();
                TestReporter.pass("Navigation to Back action applied");
                break;
            }
            case "forward":
            case "next": {
                Platform.driver.navigate().forward();
                TestReporter.pass("Navigation to Forward action applied");
                break;
            }
            case "refresh":
            case "reload":
            case "load": {
                Platform.driver.navigate().refresh();
                TestReporter.pass("Page Reload action applied");
                break;
            }
            default: {
                if (StringProcess.validateURL(url))
                    Platform.driver.navigate().to(url);
                else {// If fail to read navigateTo action then will report a fail
                    // step and fail test case
                    TestReporter.fail("The Provided URL is wrong, Please check URL: " + url, true);
                }// If action executed then will pass step in report
                TestReporter.pass("Navigated to URL: " + url);
            }
        }
    }

    // This method return current URL for current active browser tab
    public static String getCurrentURL() {
        // Wait in case driver still no previous page
        Actions.waitFor(1);
        return Platform.driver.getCurrentUrl();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy