com.sdl.selenium.web.Editor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Testy Show documentation
Show all versions of Testy Show documentation
Automated Acceptance Testing. Selenium and Selenium WebDriver test framework for web applications.
(optimized for dynamic html, ExtJS, Bootstrap, complex UI, simple web applications/sites)
The newest version!
package com.sdl.selenium.web;
import com.sdl.selenium.extjs6.form.*;
import com.sdl.selenium.web.form.Field;
import com.sdl.selenium.web.utils.RetryUtils;
import org.slf4j.Logger;
import java.time.Duration;
import java.util.List;
public interface Editor {
Logger log = org.slf4j.LoggerFactory.getLogger(Editor.class);
WebLocator getView();
default T getEditor(WebLocator cell) {
return RetryUtils.retry(3, () -> {
cell.click();
return getEditor();
});
}
@SuppressWarnings("unchecked")
default T getEditor() {
return getDoEditor(getView());
}
default T getDoEditor(WebLocator parent) {
Field editor;
WebLocator container = new WebLocator(parent).setClasses("x-editor");
WebLocator input = new WebLocator(container).setTag("input").setResultIdx(Position.LAST);
if (!input.isPresent()) {
input = new WebLocator(container).setTag("textarea");
}
if (((WebLocator) new WebLocator(container).setTag("iframe")).isPresent()) {
input = new WebLocator(container).setTag("iframe");
}
WebLocator finalInput = input;
String type = RetryUtils.retry(2, () -> finalInput.getAttribute("data-componentid", true));
if (type == null) {
log.error("active editor type: 'null'");
return null;
} else {
if (type.contains("combo")) {
editor = new ComboBox();
} else if (type.contains("textarea")) {
editor = new TextArea();
} else if (type.contains("datefield")) {
editor = new DateField();
} else if (type.contains("tag")) {
editor = new TagField();
} else if (type.contains("checkbox") || type.contains("checkcolumn")) {
editor = new CheckBox();
} else if (type.contains("numberfield") || type.contains("textfield")) {
editor = new TextField();
} else if (type.contains("crossreferenceeditor")) {
editor = new HtmlEditor();
} else {
log.warn("active editor type: {}", type);
return null;
}
}
editor.setContainer(parent).setRender(Duration.ofSeconds(1)).setInfoMessage("active editor");
if (!(editor instanceof CheckBox)) {
editor.setClasses("x-form-focus");
}
return (T) editor;
}
default boolean edit(WebLocator cell, List values) {
String value = values.get(0);
Field editor = getEditor(cell);
boolean edited = false;
if (editor instanceof TextField || editor instanceof HtmlEditor) {
edited = RetryUtils.retry(2, () -> {
editor.setValue(value);
return editor.getValue().equals(value);
});
} else if (editor instanceof ComboBox) {
ComboBox comboBox = (ComboBox) editor;
edited = RetryUtils.retry(2, () -> {
comboBox.select(value);
return comboBox.getValue().equals(value);
});
} else if (editor instanceof TagField) {
edited = ((TagField) editor).select(values.toArray(new String[0]));
} else {
log.error("Is not suported!");
}
return edited;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy