org.openmrs.steps.CreateConceptDrugSteps.java Source code

Java tutorial

Introduction

Here is the source code for org.openmrs.steps.CreateConceptDrugSteps.java

Source

/**
 * This Source Code Form is subject to the terms of the Mozilla Public License,
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
 *
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
 * graphic logo is a trademark of OpenMRS Inc.
 */
package org.openmrs.steps;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.containsString;
import static org.openqa.selenium.lift.Finders.button;
import static org.openqa.selenium.lift.Finders.div;
import static org.openqa.selenium.lift.Finders.link;
import static org.openqa.selenium.lift.Finders.radioButton;
import static org.openqa.selenium.lift.Finders.textbox;
import static org.openqa.selenium.lift.Matchers.attribute;
import static org.openqa.selenium.lift.Matchers.text;

import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.openmrs.Steps;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class CreateConceptDrugSteps extends Steps {

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

    @Given("I login to the openmrs application")
    public void logIn() {
        assertPresenceOf(link().with(text(equalTo("Log out"))));
    }

    @Given("I navigate to the the administration page")
    public void navigateToAdminUrl() {
        clickOn(link().with(text(equalTo("Administration"))));
    }

    @When("I mention $name, $concept, $doseStrength, $units, $maximumDose and $minimumDose")
    public void addDrugDetails(String name, String concept, String doseStrength, String units, String maximumDose,
            String minimumDose) throws InterruptedException {
        type(name, into(textbox().with(attribute("name", equalTo("name")))));
        //editing the concept
        type(concept, into(textbox().with(attribute("id", equalTo("concept_selection")))));
        Thread.sleep(1000);
        WebElement conceptSelection = driver.findElement(By.id("concept_selection"));
        conceptSelection.sendKeys(Keys.TAB);
        //editing the combination
        clickOn(checkbox().with(attribute("name", equalTo("combination"))));

        //editing dose strength
        type(doseStrength, into(textbox().with(attribute("name", equalTo("doseStrength")))));

        //editing unit
        type(units, into(textbox().with(attribute("name", equalTo("units")))));

        //editing maximum dose
        type(maximumDose, into(textbox().with(attribute("name", equalTo("maximumDailyDose")))));

        //editing minimum dose
        type(minimumDose, into(textbox().with(attribute("name", equalTo("minimumDailyDose")))));
    }

    @When("I save the concept drug")
    public void saveConceptDrug() {
        clickOn(button().with(attribute("value", equalTo("Save Concept Drug"))));
    }

    @Then("the new drug should get saved")
    public void verifyConceptDrug() {
        waitAndAssertFor(div().with(text(equalTo("Concept Drug saved"))));
    }
}