/
Text.java
40 lines (31 loc) · 1.19 KB
/
Text.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.codeborne.selenide.conditions;
import com.codeborne.selenide.Driver;
import com.codeborne.selenide.commands.GetSelectedOptionText;
import org.openqa.selenium.WebElement;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import static org.apache.commons.lang3.StringUtils.isEmpty;
@ParametersAreNonnullByDefault
public class Text extends CaseInsensitiveTextCondition {
private final GetSelectedOptionText getSelectedOptionsTexts;
public Text(String text) {
this(text, new GetSelectedOptionText());
}
Text(final String text, GetSelectedOptionText getSelectedOptionsTexts) {
super("text", text);
if (isEmpty(text)) {
throw new IllegalArgumentException("Argument must not be null or empty string. " +
"Use $.shouldBe(empty) or $.shouldHave(exactText(\"\").");
}
this.getSelectedOptionsTexts = getSelectedOptionsTexts;
}
@Nullable
@CheckReturnValue
@Override
protected String getText(Driver driver, WebElement element) {
return "select".equalsIgnoreCase(element.getTagName()) ?
getSelectedOptionsTexts.execute(driver, element) :
element.getText();
}
}