com.github.mkolisnyk.sirius.cucumber.steps.ControlSteps Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sirius-java-client Show documentation
Show all versions of sirius-java-client Show documentation
Common client library for automated GUI testing
The newest version!
package com.github.mkolisnyk.sirius.cucumber.steps;
import java.math.RoundingMode;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import com.github.mkolisnyk.sirius.client.Context;
import com.github.mkolisnyk.sirius.client.ui.Page;
import com.github.mkolisnyk.sirius.client.ui.controls.Control;
import com.github.mkolisnyk.sirius.client.ui.controls.Edit;
import com.udojava.evalex.Expression;
import cucumber.api.DataTable;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class ControlSteps {
@When("^(?:I |)(?:click|tap) on the \"(.*)\" (?:button|element|control)$")
public void clickOnTheButton(String name) throws Exception {
Control control = Page.getCurrent().onPage(name);
Assert.assertNotNull("Unable to find the '" + name + "' element on current page.", control);
control.click();
}
@Then("^(?:I should see |)the \"(.*)\" field is available$")
public Control verifyElementExists(String fieldName) throws Exception {
Control control = Page.getCurrent().onPage(fieldName);
Assert.assertNotNull("Unable to find the '" + fieldName + "' element on current page.", control);
return control;
}
@When("^(?:I |)enter \"(.*)\" text into the \"(.*)\" field$")
public void enterValue(String text, String fieldName) throws Exception {
Edit control = (Edit) verifyElementExists(fieldName);
control.setText(text);
}
@Then("^(?:I should see |)the \"(.*)\" field contains the \"(.*)\" text$")
public void verifyFieldText(String fieldName, String text) throws Exception {
Control control = (Control) verifyElementExists(fieldName);
String actualText = control.getText();
Assert.assertTrue(
String.format("The '%s' field has unexpected text. Expected: '%s', Actual: '%s'",
fieldName,
text,
actualText
),
text.equals(actualText) || actualText.contains(text));
}
@Then("^(?:I should see |)the following fields are shown:$")
public void verifyMultipleFieldsAvailability(List elements) throws Exception {
for (String element : elements) {
verifyElementExists(element);
}
}
@Then("^(?:I should see |)the (?:elements|buttons|controls) with the following visibility:$")
public void verifyElementsWithVisibility(DataTable criteria)
throws Throwable {
List