Skip to content

Commit

Permalink
Added selenium tests for the view manage proposals feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Sanders committed Jun 3, 2014
1 parent e1e2253 commit d0077c3
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h2 id="headerText">Manage Concept Proposals</h2>
<tr><td colspan="4" align="center" class="loading"><img ng-src="{{contextPath}}/images/loading.gif"/> Loading...</td></tr>
</tbody>
<tbody ng-show="responseReceived && proposals.length == 0">
<tr><td colspan="4" align="center"><em>No proposals found</em></td></tr>
<tr><td colspan="4" align="center"><em>No proposals have been created</em></td></tr>
</tbody>
<tbody class="results">
<tr ng-repeat="proposal in proposals" ng-click="editProposal(proposal.id)" style="cursor: pointer;">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public AdminPage login() throws IOException {
p.load(new InputStreamReader(is));
username = p.getProperty("username");
password = p.getProperty("password");
adminPageUrl = p.getProperty("adminPageUrl");
adminPageUrl = p.getProperty("openmrsUrl") + "/admin";
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.openmrs.module.conceptpropose.functionaltest.steps;

import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.openmrs.module.conceptpropose.pagemodel.AdminPage;
import org.openmrs.module.conceptpropose.pagemodel.CreateProposalPage;
import org.openmrs.module.conceptpropose.pagemodel.ManageProposalsPage;
import org.openmrs.module.conceptpropose.pagemodel.QueryBrowserPage;

import java.io.IOException;
import java.util.UUID;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class ManageProposalsStepDefs {

private Login login;
private AdminPage adminPage;
private ManageProposalsPage manageProposalsPage;
private String currName;

@Given("that I am logged in as a Local Admin")
public void login() throws IOException {
login = new Login();
adminPage = login.login();
}

@And("that at least one proposal has been submitted")
public void submittedProposalPrecondition() {
final CreateProposalPage createProposalLink = adminPage.navigateToCreateProposalPage();
currName = UUID.randomUUID().toString();
createProposalLink.enterNewProposal(currName, "[email protected]", "What's up doc?");
createProposalLink.navigateToAddConceptDialog();
createProposalLink.enterNewConcept("X-RAY, ARM", 1);
createProposalLink.submitProposal();
}

@When("I open the Manage Proposal page")
public void navigateToManageProposalPage() {
adminPage.navigateToAdminPage();
manageProposalsPage = adminPage.navigateToManageProposals();
}

@Then("all proposals that have been submitted are displayed")
public void checkAllSubmittedProposalsAreDisplayed() {
final boolean b = manageProposalsPage.checkIfProposalIsSubmitted(currName);
assertThat(b, is(true));
}

@And("that at least one proposal has been saved as a draft")
public void draftProposalPrecondition() {
final CreateProposalPage createProposalLink = adminPage.navigateToCreateProposalPage();
currName = UUID.randomUUID().toString();
createProposalLink.enterNewProposal(currName, "[email protected]", "What's up doc?");
createProposalLink.navigateToAddConceptDialog();
createProposalLink.enterNewConcept("X-RAY, ARM", 1);
createProposalLink.saveNewProposal();
}

@Then("all proposals that have been saved as a draft are displayed")
public void checkAllDraftProposalsAreDisplayed() {
manageProposalsPage.checkIfProposalIsSaved(currName);
}

@And("there are no saved drafts and no submitted proposals")
public void noProposalsPrecondition() throws IOException {
final QueryBrowserPage queryBrowserPage = new QueryBrowserPage();
queryBrowserPage.removeAllProposals();
}

@Then("there are no proposals displayed")
public void checkNoProposalsDisplayed() {
final int proposalCount = manageProposalsPage.getProposalCount();

assertThat(proposalCount, is(0));
}

@Then("a message is displayed \"No proposals have been created\"")
public void checkNoProposalMsg() {
final boolean msgDisplayed = manageProposalsPage.checkNoProposalsMessageIs("No proposals have been created");

assertThat(msgDisplayed, is(true));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.openmrs.module.conceptpropose.pagemodel;

import org.apache.commons.lang.StringUtils;
import org.openmrs.module.conceptpropose.functionaltest.steps.SeleniumDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

public class QueryBrowserPage {

private final String queryBrowserPageUrl;
private WebDriver driver;
private String openmrsUrl;

public QueryBrowserPage() throws IOException {
this.driver = SeleniumDriver.getDriver(); // request current driver every time new page constructed

if (StringUtils.isNotBlank(System.getenv("openmrs_username"))) {
// username = System.getenv("openmrs_username");
// password = System.getenv("openmrs_password");

if (StringUtils.isNotBlank(System.getenv("openmrs_url"))) {
openmrsUrl = System.getenv("openmrs_url");
}

queryBrowserPageUrl = String.format("http://%s/%s/module/querybrowser/manage.form", System.getenv("openmrs_server"), openmrsUrl);
} else {
final Properties p = new Properties();
final InputStream is = getClass().getResourceAsStream("/config.properties");

p.load(new InputStreamReader(is));
// username = p.getProperty("username");
// password = p.getProperty("password");
queryBrowserPageUrl = p.getProperty("openmrsUrl") + "/module/querybrowser/manage.form";
}
}

public void removeAllProposals() {
driver.get(queryBrowserPageUrl);

final WebElement queryEl = driver.findElement(By.cssSelector("textarea[ng-model=\"query\"]"));
queryEl.sendKeys("delete from conceptpropose_proposed_concept_package");
driver.findElement(By.xpath("//button[contains(text(),'Submit Query')]")).click();
}

}
2 changes: 1 addition & 1 deletion functional-tests/src/test/resources/config.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
username = admin
password = Admin123
adminPageUrl = http://192.168.33.10:8080/openmrs/admin
openmrsUrl = http://192.168.33.10:8080/openmrs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
Feature: Local Admin access to all proposals
As a Local Admin
I want to see all proposals in the Manage Proposals page
I want to see all proposals in the Manage Proposals page
So that I can navigate and view the proposals I worked with

Scenario: Local Admin opens the Manage Proposals page
Given that I am logged in as a Local Admin
@Selenium
Scenario: Local Admin opens the Manage Proposals page to find submitted proposals
Given that I am logged in as a Local Admin
And that at least one proposal has been submitted
When I open the Manage Proposal page
Then all proposals that have been submitted are displayed

Scenario: Local Admin opens the Manage Proposals page
Then all proposals that have been submitted are displayed

@Selenium
Scenario: Local Admin opens the Manage Proposals page to find draft proposals
Given that I am logged in as a Local Admin
And that at least one proposal has been saved as a draft
When I open the Manage Proposal page
Then all proposals that have been saved as a draft are displayed

Then all proposals that have been saved as a draft are displayed

@Selenium
Scenario: Local Admin opens the Manage Proposals page with no proposals
Given that I am logged in as a Local Admin
And there are no saved drafts and no submitted proposals
Expand Down

0 comments on commit d0077c3

Please sign in to comment.