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

web.WebTestCase Maven / Gradle / Ivy

package web;

import core.annotations.AnnotationsHandler;
import org.openqa.selenium.WebElement;

import static web.Assert.*;
import static web.WebDriverInitializer.webDriver;
import static web.WebActions.goBack;
import static web.WebActions.goToURL;
import static web.WebActions.navigateTo;

/**
 * Created by Ismail on 12/28/2017.
 * This class for Web Actions Section
 */
public class WebTestCase extends TestNGMethods {

    /*************** Class Variables Section ***************/

    /*************** WebActions Class Methods Section Start ***************/
    // This method Apply visitUrl action that implemented in WebActions
    protected void visitURL(String urlString) {
        // Call goToURL Method from WebActions class to execute visitUrl action
        goToURL(webDriver, urlString);
    }

    // This method Apply visitUrl action that implemented in WebActions
    // This method get URL from Method Data File
    @Deprecated
    protected void visitURL() {
        // Define urlString and retrieve it's data from data file
        String urlString = AnnotationsHandler.getValueOfDataRow();
        // Call navigateTo Method from WebActions class to execute visitUrl action
        navigateTo(webDriver, urlString);
    }

    // This method to back one page on the browser
    protected void back() {
        goBack(webDriver);
    }

    // This method returns current URL
    protected String getCurrentURL() {
        return WebActions.getCurrentURL(webDriver);
    }

    // This method returns current Title
    protected String getCurrentTitle() {
        return WebActions.getCurrentTitle(webDriver);
    }

    // This method to apply Send text for String parameter
    protected void sendText(String webElement, String valueString) {
        WebActions.sendText(webElement, valueString);
    }

    // This method to apply Send text for WebElement parameter
    protected void sendText(WebElement webElement, String valueString) {
        WebActions.sendText(webElement, valueString);
    }

    // This method to apply Send text from test data file for String parameter
    protected void sendText(String webElement) {
        // Extract first value from test case dataRow
        String value = AnnotationsHandler.getValueOfDataRow();
        // Apply sendText method
        WebActions.sendText(webElement, value);
    }

    // This method to apply Send text from test data file for WebElement parameter
    protected void sendText(WebElement webElement) {
        // Extract first value from test case dataRow
        String value = AnnotationsHandler.getValueOfDataRow();
        // Apply sendText method
        WebActions.sendText(webElement, value);
    }

    // This method to apply Send Keyboard Keys for String parameter
    protected void sendKeys(String webElement, CharSequence... keyboardKeys) {
        WebActions.sendKeys(webElement, keyboardKeys);
    }

    // This method to apply Send Keyboard Keys for WebElement parameter
    protected void sendKeys(WebElement webElement, CharSequence... keyboardKeys) {
        WebActions.sendKeys(webElement, keyboardKeys);
    }

    // This method to apply get Text for String parameter
    protected String getText(String webElement) {
        return WebActions.getText(webElement);
    }

    // This method to apply get Text for WebElement parameter
    protected String getText(WebElement webElement) {
        return WebActions.getText(webElement);
    }

    // This method to apply Click buttons, Radios, Checkboxes and any element accept click action for String parameter
    protected void click(String webElement) {
        WebActions.click(webElement);
    }

    // This method to apply Click buttons, Radios, Checkboxes and any element accept click action for WebElement parameter
    protected void click(WebElement webElement) {
        WebActions.click(webElement);
    }

    //This method to apply Wait For time in seconds action
    protected void waitFor(int timeInSeconds) {
        WebActions.waitFor(timeInSeconds);
    }

    // This method to apply wait until element be ready for String parameter
    protected void waitUntil(String webElement) {
        WebActions.waitUntil(webElement);
    }

    // This method to apply wait until element be ready for WebElement parameter
    protected void waitUntil(WebElement webElement) {
        WebActions.waitUntil(webElement);
    }

    // This method to apply clear for String parameter
    protected void clear(String webElement) {
        WebActions.clear(webElement);
    }

    // This method to apply clear for WebElement parameter
    protected void clear(WebElement webElement) {
        WebActions.clear(webElement);
    }

    // This method to apply submit for String parameter
    protected void submit(String webElement) {
        WebActions.submit(webElement);
    }

    // This method to apply submit for WebElement parameter
    protected void submit(WebElement webElement) {
        WebActions.submit(webElement);
    }

    // This method to apply getTagName for String parameter
    protected String getTagName(String webElement) {
        return WebActions.getTagName(webElement);
    }

    // This method to apply getTagName for WebElement parameter
    protected String getTagName(WebElement webElement) {
        return WebActions.getTagName(webElement);
    }
    /***************** WebActions class methods Section ends *****************/

    /***************** Assert class methods Section start *****************/
    // This method check if condition is true or not
    protected void assertIsTrue(Boolean condition, String errMessage) {
        isTrue(condition, errMessage);
    }

    // This method check if condition is false
    protected void assertIsFalse(Boolean condition, String errMessage) {
        isFalse(condition, errMessage);
    }

    // This method to apply Assert current title assertion
    protected void assertTitleIs(String expectedTitle, String errMessage) {
        titleIs(expectedTitle, errMessage);
    }

    // This method check if title contains partial String
    protected void assertTitleContains(String partialTitle, String errMessage) {
        titleContains(webDriver, partialTitle, errMessage);
    }

    // This method to apply Assert current URL assertion
    protected void assertURLIs(String expectedURL, String errMessage) {
        urlIs(expectedURL, errMessage);
    }

    // This method check if URL contains partial String
    protected void assertURLContains(String partialURL, String errMessage) {
        urlContains(webDriver, partialURL, errMessage);
    }

    // This method to apply Assert Text assertion
    protected void assertTextEquals(String actualText, String expectedText, String errMessage) {
        Assert.stringsEqual(actualText, expectedText, errMessage);
    }

    // This method to apply Assert Text assertion but the Expected Value from dataFile
    protected void assertTextEquals(String actualText, String errMessage) {
        // Get Expected Text from Data File
        String expectedText = AnnotationsHandler.getValueOfDataRow();
        assertTextEquals(actualText, expectedText, errMessage);
    }

    // This method check if WebElement is displayed for String parameter
    protected void assertIsDisplayed(String webElement, String errMessage) {
        isDisplayed(webElement, errMessage);
    }

    // This method check if WebElement is displayed for WebElement parameter
    protected void assertIsDisplayed(WebElement webElement, String errMessage) {
        isDisplayed(webElement, errMessage);
    }

    // This method check if WebElement exists or not
    protected void assertIsExists(String webElement, String errMessage) {
        isExists(webDriver, webElement, errMessage);
    }

    // This method check if Alert is present or not
    protected void assertAlertIsPresented(String errMessage) {
        alertIsPresent(webDriver, errMessage);
    }

    // This method check if WebElement attribute value is valid for String parameter
    protected void assertWebElementAttribute(String webElement, String attributeName, String expectedAttributeValue, String errMessage) {
        webElementAttributeIs(webDriver, webElement, attributeName, expectedAttributeValue, errMessage);
    }

    // This method check if WebElement attribute value is valid for WebElement parameter
    protected void assertWebElementAttribute(WebElement webElement, String attributeName, String expectedAttributeValue, String errMessage) {
        webElementAttributeIs(webDriver, webElement, attributeName, expectedAttributeValue, errMessage);
    }

    // This method check if WebElement attribute value contains a text for String parameter
    protected void assertWebElementAttributeContains(String webElement, String attributeName, String expectedAttributeValueContains, String errMessage) {
        webElementAttributeContains(webDriver, webElement, attributeName, expectedAttributeValueContains, errMessage);
    }

    // This method check if WebElement attribute value contains a text for WebElement parameter
    protected void assertWebElementAttributeContains(WebElement webElement, String attributeName, String expectedAttributeValueContains, String errMessage) {
        webElementAttributeContains(webDriver, webElement, attributeName, expectedAttributeValueContains, errMessage);
    }

    // This method check if WebElement attribute value not empty for String parameter
    protected void assertWebElementAttributeNotEmpty(String webElement, String attributeName, String errMessage) {
        webElementAttributeNotEmpty(webDriver, webElement, attributeName, errMessage);
    }

    // This method check if WebElement attribute value not empty for WebElement parameter
    protected void assertWebElementAttributeNotEmpty(WebElement webElement, String attributeName, String errMessage) {
        webElementAttributeNotEmpty(webDriver, webElement, attributeName, errMessage);
    }

    // This method check if WebElement attribute value not empty for String parameter
    protected void assertWebElementTextContains(String webElement, String expectedText, String errMessage) {
        webElementContainsText(webDriver, webElement, expectedText, errMessage);
    }

    // This method check if WebElement attribute value not empty for WebElement parameter
    protected void assertWebElementTextContains(WebElement webElement, String expectedText, String errMessage) {
        webElementContainsText(webDriver, webElement, expectedText, errMessage);
    }

    // This method rewrite assert methods functionality but with just a different name
    protected void assertThat(Boolean condition, String errMessage){
        assertIsTrue(condition, errMessage);
    }
    protected void assertThat(String actualText, String expectedText, String errMessage){
        assertTextEquals(actualText, expectedText, errMessage);
    }
    protected void assertThat(String actualText, String errMessage){
        assertTextEquals(actualText, errMessage);
    }
    /***************** Assert class methods Section ends *****************/
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy