package org.motechproject.uitest.page;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class DataServicesPage extends AbstractBasePage {

    public static final By ENTITY_NAME_FIELD = By.name("inputEntityName");
    public static final By NEW_ENTITY_BUTTON = By.id("newEntityButton");
    public static final By SAVE_ENTITY_BUTTON = By.id("saveNewEntityButton");
    public static final By DATA_SERVICES_BUTTON = By.id("data-services");
    public static final By SCHEMA_EDITOR_BUTTON = By.id("schemaEditor");
    public static final By BROWSE_INSTANCES_BUTTON = By.id("browseInstancesButton");
    public static final By ADD_NEW_INSTANCE_BUTTON = By.id("addNewInstanceButton");

    public static final String HOME_PATH = "/module/server/home#";

    public DataServicesPage(WebDriver driver) {
        super(driver);
    }

    public void createNewEntity(String entityName) throws InterruptedException {
        waitForElement(DATA_SERVICES_BUTTON);
        clickWhenVisible(DATA_SERVICES_BUTTON);
        waitForElement(SCHEMA_EDITOR_BUTTON);
        clickWhenVisible(SCHEMA_EDITOR_BUTTON);
        waitForElement(NEW_ENTITY_BUTTON);
        clickWhenVisible(NEW_ENTITY_BUTTON);
        waitForElement(ENTITY_NAME_FIELD);
        setTextToFieldNoEnter(ENTITY_NAME_FIELD, entityName);
        waitForElement(SAVE_ENTITY_BUTTON);
        clickOn(SAVE_ENTITY_BUTTON);
        waitForElement(BROWSE_INSTANCES_BUTTON);
    }

    public void goToEntityTable(String entityName) throws InterruptedException {
        waitForElement(DATA_SERVICES_BUTTON);
        clickWhenVisible(DATA_SERVICES_BUTTON);
        waitForElement(By.id(String.format("entity_%s", entityName)));
        clickWhenVisible(By.id(String.format("entity_%s", entityName)));
        waitForElement(ADD_NEW_INSTANCE_BUTTON);
    }

    @Override
    public String expectedUrlPath() {
        return HOME_PATH;
    }

    @Override
    public void goToPage() {
        getDriver().get(getMotechUrl() + HOME_PATH);
    }
}

Add selenium test for adding a new entity in MDS
MOTECH-2033: Add selenium test for adding a new entity in MDS
