All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.serenitybdd.screenplay.actions.SendKeysIntoBy Maven / Gradle / Ivy

There is a newer version: 4.2.8
Show newest version
package net.serenitybdd.screenplay.actions;

import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.annotations.Step;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.List;

public class SendKeysIntoBy extends EnterValue {

    private final List locators;
    private final String locatorNames;

    protected WebElement resolveFor(Actor theUser) {
        return WebElementLocator.forLocators(locators).andActor(theUser);
    }

    public SendKeysIntoBy(List locators, CharSequence... theText) {
        super(theText);
        this.locators = locators;
        this.locatorNames = (locators.size() == 1) ? locators.get(0).toString() : locators.toString();
    }

    @Step("{0} enters #theTextAsAString into #locatorNames")
    public  void performAs(T theUser) {
        textValue().ifPresent(
                text -> resolveFor(theUser).sendKeys(theText)
        );
        if (getFollowedByKeys().length > 0) {
            resolveFor(theUser).sendKeys(getFollowedByKeys());
        } 
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy