/** * Получение текста элемента, как редактируемого поля, так и статичного элемента по значению элемента */ public String getAnyElementText(SelenideElement element) { if (element.getTagName().equals("input")) { return element.getValue(); } else { return element.getText(); } }
public String getTabBadgeText(String resourceKey) { SelenideElement element = getParentElement().$(Schrodinger.bySchrodingerDataResourceKey(resourceKey)); element.shouldBe(Condition.visible); SelenideElement badge = element.$(Schrodinger.byDataId("small", "count")); badge.shouldBe(Condition.visible); return badge.getValue(); }
private void clickMenuItem(String topLevelMenuKey, String mainMenuKey, String menuItemKey) { SelenideElement topLevelMenu = $(Schrodinger.byDataResourceKey(topLevelMenuKey)); topLevelMenu.shouldBe(Condition.visible); SelenideElement topLevelMenuChevron = topLevelMenu.parent().$(By.tagName("i")); if (!topLevelMenuChevron.has(Condition.cssClass("fa-chevron-down"))) { topLevelMenu.click(); topLevelMenuChevron.shouldHave(Condition.cssClass("fa-chevron-down")).waitUntil(Condition.cssClass("fa-chevron-down"), MidPoint.TIMEOUT_DEFAULT_2_S); } SelenideElement mainMenu = topLevelMenu.$(Schrodinger.byDataResourceKey(mainMenuKey)); mainMenu.shouldBe(Condition.visible); if (menuItemKey == null) { mainMenu.click(); return; } SelenideElement mainMenuLi = mainMenu.parent().parent(); if (!mainMenuLi.has(Condition.cssClass("active"))) { mainMenu.click(); mainMenuLi.waitUntil(Condition.cssClass("active"),MidPoint.TIMEOUT_DEFAULT_2_S).shouldHave(Condition.cssClass("active")); } SelenideElement menuItem = mainMenu.$(Schrodinger.byDataResourceKey(menuItemKey)); menuItem.shouldBe(Condition.visible); menuItem.click(); } }
public InputBox<Search<T>> byFullText() { SelenideElement linksContainer = getParentElement().$(Schrodinger.byDataId("div", "linksContainer")).waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S); try { linksContainer.$(Schrodinger.byDataId("a", "fullText")).waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S).click(); } catch (Throwable t) { // all is ok, fullText search is already selected option, TODO: Schrodinger should provide easy method to check component existence } // we assume fulltext is enabled in systemconfig, else error is thrown here: SelenideElement fullTextField = getParentElement().$(Schrodinger.byDataId("input", "fullTextField")).waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S); return new InputBox<> (this, fullTextField); } }
public FocusSetAssignmentsModal<T> selectType(String option) { SelenideElement tabElement = $(Schrodinger.byElementValue("a", "class", "tab-label", option)) .waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S); String classActive = tabElement.attr("class"); tabElement.click(); if (!classActive.contains("active")) { $(Schrodinger.byElementValue("a", "class", "tab-label", option)) .waitUntil(Condition.attribute("class", classActive + " active"), MidPoint.TIMEOUT_DEFAULT_2_S).exists(); } return this; }
@Test public void userCanGuessLetters() { letter("S").click(); $("#wordInWork").shouldHave(text("s___")); letter("S").shouldHave(cssClass("used")); }
/** * Выбор из списка со страницы элемента, который содержит заданный текст * (в приоритете: из property, из переменной сценария, значение аргумента) * Не чувствителен к регистру */ @Когда("^в списке \"([^\"]*)\" выбран элемент содержащий текст \"([^\"]*)\"$") public void selectElementInListIfFoundByText(String listName, String expectedValue) { final String value = getPropertyOrStringVariableOrValue(expectedValue); List<SelenideElement> listOfElementsFromPage = akitaScenario.getCurrentPage().getElementsList(listName); List<String> elementsListText = listOfElementsFromPage.stream() .map(element -> element.getText().trim().toLowerCase()) .collect(toList()); listOfElementsFromPage.stream() .filter(element -> element.getText().trim().toLowerCase().contains(value.toLowerCase())) .findFirst() .orElseThrow(() -> new IllegalArgumentException(String.format("Элемент [%s] не найден в списке %s: [%s] ", value, listName, elementsListText))) .click(); }
@Override public SelenideElement execute(SelenideElement proxy, WebElementSource locator, Object[] args) { SelenideElement target; if (args[0] instanceof String) { target = ElementFinder.wrap(locator.driver(), By.cssSelector((String) args[0])); } else if (args[0] instanceof WebElement) { target = WebElementWrapper.wrap(locator.driver(), (WebElement) args[0]); } else { throw new IllegalArgumentException("Unknown target type: " + args[0] + " (only String or WebElement are supported)"); } target.shouldBe(visible); new Actions(locator.driver().getWebDriver()).dragAndDrop(locator.getWebElement(), target).perform(); return proxy; } }
@Test public void search_selenide_in_google() { open("https://google.com/ncr"); $(By.name("q")).val("selenide").pressEnter(); $$("#ires .g").shouldHave(sizeGreaterThan(1)); $("#ires .g").shouldBe(visible).shouldHave( text("Selenide: concise UI tests in Java"), text("selenide.org")); } }
/** * На странице происходит клик по заданному элементу */ @И("^выполнено нажатие на (?:кнопку|поле|блок) \"([^\"]*)\"$") public void clickOnElement(String elementName) { akitaScenario.getCurrentPage().getElement(elementName).click(); }
public JList shouldHave(Condition... conditions) { Selenide.$(getWebElement()).shouldHave(conditions); return this; }
/** * Добавление строки (в приоритете: из property, из переменной сценария, значение аргумента) в поле к уже заполненой строке */ @Когда("^в элемент \"([^\"]*)\" дописывается значение \"(.*)\"$") public void addValue(String elementName, String value) { value = getPropertyOrStringVariableOrValue(value); SelenideElement field = akitaScenario.getCurrentPage().getElement(elementName); String oldValue = field.getValue(); if (oldValue.isEmpty()) { oldValue = field.getText(); } field.setValue(""); field.setValue(oldValue + value); }