Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOTECH-2181: Check If Save Button Is Disable With No Config Selenium Test #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.motechproject.uitest.page;

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

/**
* A class that represents Cpmmcare page. Has methods which check functionality of
* Settings, Import Forms, Forms and Cases.
*/
public class CommcarePage extends MotechPage {

private static final String HOME_PATH = "/module/server/home#";
public static final By ADD_CONFIGURATION_BUTTON = By.xpath("(//a[@ng-click='addConfig()'])");
public static final By SAVE_CONFIGURATION_BUTTON = By.xpath("(//a[@ng-click='saveAllowed() && saveConfig()'])");

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

public void createNewConfiguration() throws InterruptedException {
clickWhenVisible(ADD_CONFIGURATION_BUTTON);
}

public boolean checkIfAddConfigurationButtonIsVisible() {
return findElement(ADD_CONFIGURATION_BUTTON).isEnabled();
}

public boolean checkIfSaveButtonIsDisabled() {
boolean check = false;
try {
if (findElement(SAVE_CONFIGURATION_BUTTON).getAttribute("disabled").equals("disabled")) {
check = false;
}
} catch (Exception e) {
check = true;
}
return check;
}

@Override
public String expectedUrlPath() {
return HOME_PATH;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,31 @@

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;

import static java.lang.Thread.sleep;

/**
* A page in the MOTECH UI - with menu on the left and the top header.
*/
public class MotechPage extends AbstractBasePage {

public static final By DATA_SERVICES_MENU_LINK = By.id("module-nav-mds-dataBrowser");
public static final By REST_API_MENU_LINK = By.linkText("REST API");
/**public static final By DATA_SERVICES_MENU_LINK = By.id("module-nav-mds-dataBrowser");*/
public static final By DIALOG_DIV = By.className("bootstrap-dialog");
/**TOP MENU*/
public static final By REST_API_MENU_LINK = By.id("section-nav-server-rest-documentation");
public static final By ADMIN_MENU_LINK = By.id("section-nav-admin-module");
public static final By MODULES_MENU_LINK = By.id("section-nav-server-modules");
/**Left side MENU*/
public static final By DATA_SERVICES_MENU_LINK = By.id("modulelink_data-services");
public static final By COMMCARE_MENU_LINK = By.id("module-nav-commcare-settings");
public static final By MANAGE_MODULES_MENU_LINK = By.id("modulelink_admin");
/**Inside modules*/
public static final By BLOCK_UI_DIV = By.className("blockUI");
public static final By SELECT_MODULE_DROPDOWN = By.name("moduleId");
public static final By INSTALL_OR_UPDATE_BUTTON = By.xpath("//*[@id=\"bundleUploadForm\"]/div/div/div[6]/span");
/**Other*/
public static final int SLEEP_DURING_INSTALL = 150000;

public MotechPage(WebDriver driver) {
super(driver);
Expand All @@ -31,8 +47,15 @@ public RestApiPage goToRestApi() throws InterruptedException {
return new RestApiPage(getDriver());
}

public CommcarePage goToCommcare() throws InterruptedException {
clickWhenVisible(COMMCARE_MENU_LINK);
return new CommcarePage(getDriver());
}

public LoginPage logOut() throws InterruptedException {
waitForElementToBeGone(DIALOG_DIV);
getLogger().debug("Logging Out");
waitForElementToBeGone(BLOCK_UI_DIV);
waitForElement(By.cssSelector("span.ng-binding"));
clickWhenVisible(By.cssSelector("span.ng-binding"));
clickOn(By.xpath("//a[@href='j_spring_security_logout']"));
Expand All @@ -42,4 +65,20 @@ public LoginPage logOut() throws InterruptedException {
public void waitUntilDialogIsGone() {
waitForElementToBeGone(DIALOG_DIV);
}
/**
* Methods to install modules of MOTECH application
**/
public MotechPage installModule(String moduleName) throws InterruptedException {
clickWhenVisible(ADMIN_MENU_LINK);
clickWhenVisible(MANAGE_MODULES_MENU_LINK);
Select dropdown = new Select(findElement(SELECT_MODULE_DROPDOWN));
dropdown.selectByVisibleText(moduleName);
clickWhenVisible(INSTALL_OR_UPDATE_BUTTON);
getLogger().debug("Installing module: " + moduleName);
sleep(SLEEP_DURING_INSTALL);
String newModuleUrl = "http://localhost:8080/motech-platform-server/module/server/#/" + moduleName;
getDriver().navigate().to(newModuleUrl);
return new MotechPage(getDriver());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ public String getApiDocumentationTitle() throws InterruptedException {
public String expectedUrlPath() {
return HOME_PATH;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.motechproject.testing.uifunctionaltests;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.motechproject.uitest.TestBase;
import org.motechproject.uitest.page.CommcarePage;
import org.motechproject.uitest.page.MotechPage;

import static java.lang.Thread.sleep;
import static org.junit.Assert.assertEquals;

public class CommcareUIFT extends TestBase {

private CommcarePage commcarePage;
private static int SLEEP_500 = 500;

@Before
public void initialize() throws InterruptedException {
MotechPage home = login();
sleep(SLEEP_500);
commcarePage = home.goToCommcare();
sleep(SLEEP_500);
}

@After
public void cleanUp() throws InterruptedException {
logout();
}
//MOTECH 2181
@Test
public void shouldCheckIfSaveButtonIsDisabledWithoutConfiguration() throws InterruptedException {
assertEquals(true, commcarePage.checkIfAddConfigurationButtonIsVisible());
commcarePage.createNewConfiguration();
assertEquals(false, commcarePage.checkIfSaveButtonIsDisabled());
}

}