From ecaf6ea3fadb6c8af6760892f13f1332f1e08c62 Mon Sep 17 00:00:00 2001 From: "pzurawski@soldevelo.com" Date: Thu, 21 Apr 2016 17:18:29 +0200 Subject: [PATCH 1/2] MOTECH-2181: Check If Save Button Is Disable With No Config Selenium Test --- .../uitest/page/CommcarePage.java | 44 +++++++++++++++++++ .../motechproject/uitest/page/MotechPage.java | 38 +++++++++++++++- .../uitest/page/RestApiPage.java | 2 +- .../uifunctionaltests/CommcareUIFT.java | 38 ++++++++++++++++ 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 framework/src/main/java/org/motechproject/uitest/page/CommcarePage.java create mode 100644 tests/src/test/java/org/motechproject/testing/uifunctionaltests/CommcareUIFT.java diff --git a/framework/src/main/java/org/motechproject/uitest/page/CommcarePage.java b/framework/src/main/java/org/motechproject/uitest/page/CommcarePage.java new file mode 100644 index 0000000..a74f3f5 --- /dev/null +++ b/framework/src/main/java/org/motechproject/uitest/page/CommcarePage.java @@ -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.cssSelector("#main-content > div > div > div > div.btn-group.form-group > a"); + public static final By SAVE_CONFIGURATION_BUTTON = By.cssSelector("#main-content > div > div > div > div.btn-group.form-group > a.btn.btn-primary.ng-binding.ng-scope"); + + 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; + } +} diff --git a/framework/src/main/java/org/motechproject/uitest/page/MotechPage.java b/framework/src/main/java/org/motechproject/uitest/page/MotechPage.java index 0bb173c..a569daa 100644 --- a/framework/src/main/java/org/motechproject/uitest/page/MotechPage.java +++ b/framework/src/main/java/org/motechproject/uitest/page/MotechPage.java @@ -2,15 +2,29 @@ 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("modulelink_data-services"); + /**TOP MENU*/ public static final By REST_API_MENU_LINK = By.linkText("REST API"); + public static final By ADMIN_MENU_LINK = By.linkText("Admin"); + public static final By MODULES_MENU_LINK = By.linkText("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("modulelink_commcare"); + 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*/ + private int sleepDuringInstall = 150000; public MotechPage(WebDriver driver) { super(driver); @@ -31,7 +45,13 @@ 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 { + getLogger().debug("Logging Out"); waitForElementToBeGone(BLOCK_UI_DIV); waitForElement(By.cssSelector("span.ng-binding")); clickWhenVisible(By.cssSelector("span.ng-binding")); @@ -42,4 +62,20 @@ public LoginPage logOut() throws InterruptedException { public void waitUntilBlockUiIsGone() { waitForElementToBeGone(BLOCK_UI_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(sleepDuringInstall); + String newModuleUrl = "http://localhost:8080/motech-platform-server/module/server/#/" + moduleName; + getDriver().navigate().to(newModuleUrl); + return new MotechPage(getDriver()); + } + } diff --git a/framework/src/main/java/org/motechproject/uitest/page/RestApiPage.java b/framework/src/main/java/org/motechproject/uitest/page/RestApiPage.java index d364e12..0538511 100644 --- a/framework/src/main/java/org/motechproject/uitest/page/RestApiPage.java +++ b/framework/src/main/java/org/motechproject/uitest/page/RestApiPage.java @@ -34,4 +34,4 @@ public String getApiDocumentationTitle() throws InterruptedException { public String expectedUrlPath() { return HOME_PATH; } -} \ No newline at end of file +} diff --git a/tests/src/test/java/org/motechproject/testing/uifunctionaltests/CommcareUIFT.java b/tests/src/test/java/org/motechproject/testing/uifunctionaltests/CommcareUIFT.java new file mode 100644 index 0000000..10419f5 --- /dev/null +++ b/tests/src/test/java/org/motechproject/testing/uifunctionaltests/CommcareUIFT.java @@ -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()); + } + +} \ No newline at end of file From e7c4dc70452e3efb0a6a377bca3935f80fd02f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20=C5=BBurawski?= Date: Tue, 31 May 2016 16:13:20 +0200 Subject: [PATCH 2/2] MOTECH-2181: Check If Save Button Is Disable With No Config Selenium TestMOTECH-2181: Check If Save Button Is Disable With No Config Selenium Test --- .../main/java/org/motechproject/uitest/page/CommcarePage.java | 4 ++-- .../motechproject/testing/uifunctionaltests/CommcareUIFT.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/src/main/java/org/motechproject/uitest/page/CommcarePage.java b/framework/src/main/java/org/motechproject/uitest/page/CommcarePage.java index a74f3f5..8d8166f 100644 --- a/framework/src/main/java/org/motechproject/uitest/page/CommcarePage.java +++ b/framework/src/main/java/org/motechproject/uitest/page/CommcarePage.java @@ -10,8 +10,8 @@ public class CommcarePage extends MotechPage { private static final String HOME_PATH = "/module/server/home#"; - public static final By ADD_CONFIGURATION_BUTTON = By.cssSelector("#main-content > div > div > div > div.btn-group.form-group > a"); - public static final By SAVE_CONFIGURATION_BUTTON = By.cssSelector("#main-content > div > div > div > div.btn-group.form-group > a.btn.btn-primary.ng-binding.ng-scope"); + 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); diff --git a/tests/src/test/java/org/motechproject/testing/uifunctionaltests/CommcareUIFT.java b/tests/src/test/java/org/motechproject/testing/uifunctionaltests/CommcareUIFT.java index 10419f5..3e62cb7 100644 --- a/tests/src/test/java/org/motechproject/testing/uifunctionaltests/CommcareUIFT.java +++ b/tests/src/test/java/org/motechproject/testing/uifunctionaltests/CommcareUIFT.java @@ -30,7 +30,7 @@ public void cleanUp() throws InterruptedException { //MOTECH 2181 @Test public void shouldCheckIfSaveButtonIsDisabledWithoutConfiguration() throws InterruptedException { - assertEquals(true,commcarePage.checkIfAddConfigurationButtonIsVisible()); + assertEquals(true, commcarePage.checkIfAddConfigurationButtonIsVisible()); commcarePage.createNewConfiguration(); assertEquals(false, commcarePage.checkIfSaveButtonIsDisabled()); }