private List<SelenideElement> getDisplayedElementsByCss(String cssSelector) { return $$(cssSelector).stream() .filter(SelenideElement::isDisplayed) .collect(Collectors.toList()); }
public void clickByCssSelector(String cssSelector, int i) { $$(cssSelector).get(i).click(); try { Thread.sleep(SLEEP); } catch (InterruptedException e) { e.printStackTrace(); } }
/** * Get a Selenide collection locator. * * @param key locator key * @param platform platform * @param params locator key parameters * @return {@link ElementsCollection} */ public ElementsCollection getCollectionLocator(String key, String platform, Object... params) { Map<String, String> platformKey = map.get(key).get(platform); String type = platformKey.get("type"); String rawValue = platformKey.get("value"); if (type.equalsIgnoreCase(CSS)) { return $$(By.cssSelector(formatValue(rawValue, params))); } else if (type.equalsIgnoreCase(XPATH)) { return $$(By.xpath(formatValue(rawValue, params))); } else if (type.equalsIgnoreCase(ID)) { return $$(By.id(formatValue(rawValue, params))); } else if (type.equalsIgnoreCase(ACCESIBILITY_ID)) { return $$(ByAccessibilityId.AccessibilityId(formatValue(rawValue, params))); } else if (type.equalsIgnoreCase(UIAUTOMATOR)) { return $$(ByAndroidUIAutomator.AccessibilityId(formatValue(rawValue, params))); } else if (type.equalsIgnoreCase(IMAGE)) { return $$(MobileBy.image(new ImageUtils().getImageAsBase64String(rawValue))); } else { return $$(formatValue(rawValue, params)); } }
ElementsCollection detailBoxes = $$(Schrodinger.byDataId("div", MODAL_FEEDBACK_BOX_ID));
public boolean isTestFailure() { boolean isFailure = false; $(Schrodinger.byDataId("div", "messagesPanel")).waitUntil(Condition.appears, MidPoint.TIMEOUT_LONG_1_M); ElementsCollection detailBoxes = $$(Schrodinger.byDataId("div", MODAL_FEEDBACK_BOX_ID)); for (SelenideElement element : detailBoxes) { element.waitUntil(Condition.appears, MidPoint.TIMEOUT_LONG_1_M); String attr = element.attr("class"); if (attr != null && !attr.isEmpty()) { if (attr.contains("box-danger")) { isFailure = true; break; } } } clickOk(); // Not sure if this is good practice return isFailure; }
@Test public void userCanChooseLanguage() { $(By.linkText("EST")).click(); $("#topic").shouldHave(text("maja")); $("#wordInWork").shouldHave(text("____")); $$("#alphabet .letter").shouldHave(size(27)); $(By.linkText("RUS")).click(); $("#topic").shouldHave(text("дом")); $("#wordInWork").shouldHave(text("______")); $$("#alphabet .letter").shouldHave(size(33)); $(By.linkText("ENG")).click(); $("#topic").shouldHave(text("house")); $("#wordInWork").shouldHave(text("____")); $$("#alphabet .letter").shouldHave(size(26)); }
public ElementsCollection getResults() { return $$("#ires .g"); } public SelenideElement getResult(int index) {
public String getTextByCssSelector(String cssSelector, int i) { return $$(cssSelector).get(i).getText(); }
public ElementsCollection alphabet() { return $$("#alphabet .letter"); } }
@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 NewTaskPage clickCreateNew() { ElementsCollection elements = $$(Schrodinger.byElementValue("a", "data-s-id", "menuItemLink", "Create new")); for (SelenideElement element : elements) { if (element.isDisplayed()) { element.click(); break; } } return new NewTaskPage(); }
/** * Selenide style collection locator. * * @param locatorKey locator key (can include placeholders) * @param params parameters to replace the placeholders * @return {@link ElementsCollection} */ protected ElementsCollection $$(String locatorKey, Object... params) { return Selenide.$$( locators.getCollectionLocator(locatorKey, configuration.getPlatform(), params)); }
public ResourceTaskQuickAccessDropDown<ResourceAccountsTab<T>> liveSyncTask() { $(Schrodinger.byElementValue("label", "data-s-id", "label", "Live Sync")) .waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT_2_S).click(); ElementsCollection dropDownElement = $$(By.cssSelector(".dropdown-menu.pull-right")); SelenideElement concretElement = null; for (SelenideElement element : dropDownElement) { if (element.isDisplayed()) { concretElement = element; break; } } return new ResourceTaskQuickAccessDropDown<>(this, concretElement); }