Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/org/labkey/test/components/react/BaseReactSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public boolean hasOption(String value)
elementCache().input.sendKeys(value);
try
{
var optionElement = ReactSelect.Locators.options.containing(value);
var optionElement = Locators.option.containing(value);
optionElement.waitForElement(elementCache().selectMenu, 4000);
elementCache().input.clear();
return true;
Expand Down Expand Up @@ -374,7 +374,7 @@ public List<WebElement> getOptionElements()
// Can only get the list of items once the list has been opened.
if (!alreadyOpened)
open();
return Locators.listItems.findElements(getComponentElement());
return Locators.option.findElements(getComponentElement());
}

/**
Expand All @@ -391,7 +391,7 @@ public List<String> getOptions(Function<WebElement, String> optionMapper)
if (!alreadyOpened)
open();

List<WebElement> optionElements = Locators.listItems.findElements(getComponentElement());
List<WebElement> optionElements = Locators.option.findElements(getComponentElement());
List<String> rawItems = optionElements.stream().map(optionMapper).toList();

// If it wasn't open before close it, otherwise leave it in the open state.
Expand Down Expand Up @@ -486,13 +486,13 @@ protected class ElementCache extends WebDriverComponent<?>.ElementCache

List<WebElement> getOptions()
{
return Locators.options.findElements(selectMenu);
return Locators.option.findElements(selectMenu);
}

@NotNull
WebElement findOption(String option)
{
return Locators.options.withText(option).findElement(selectMenu);
return Locators.option.withText(option).findElement(selectMenu);
}
}

Expand All @@ -504,7 +504,6 @@ private Locators()
}

public static final Locator.XPathLocator option = Locator.tagWithClass("div", "select-input__option");
public static final Locator options = Locator.tagWithClass("div", "select-input__option");
public static final Locator placeholder = Locator.tagWithClass("div", "select-input__placeholder");
public static final Locator clear = Locator.tagWithClass("div","select-input__clear-indicator");
public static final Locator arrow = Locator.tagWithClass("div","select-input__dropdown-indicator");
Expand All @@ -514,7 +513,6 @@ private Locators()
public static final Locator.XPathLocator multiValueRemove = Locator.tagWithClass("div", "select-input__multi-value__remove");
public static final Locator.XPathLocator singleValueLabel = Locator.tagWithClass("div", "select-input__single-value");
public static final Locator loadingSpinner = Locator.tagWithClass("span", "select-input__loading-indicator");
public static final Locator listItems = Locator.tagWithClass("div", "select-input__option");
public static final Locator.XPathLocator helpBlock = Locator.tagWithClass("span", "help-block");

public static Locator.XPathLocator selectContainer()
Expand Down
64 changes: 27 additions & 37 deletions src/org/labkey/test/components/react/FilteringReactSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
*/
package org.labkey.test.components.react;

import org.jetbrains.annotations.Nullable;
import org.labkey.test.Locator;
import org.labkey.test.WebDriverWrapper;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;

import java.time.Duration;
import java.util.List;

import static org.labkey.test.BaseWebDriverTest.WAIT_FOR_JAVASCRIPT;
Expand Down Expand Up @@ -53,7 +51,7 @@ public FilteringReactSelect typeAheadSelect(String value, String optionText, Str
scrollIntoView();
open();

var elementToClick = ReactSelect.Locators.options.containing(optionText);
var elementToClick = Locators.option.containing(optionText);
var elementToWaitFor = getValueLabelLocator().containing(selectedOptionLabel);

List<WebElement> options = setFilter(value);
Expand Down Expand Up @@ -117,47 +115,39 @@ public FilteringReactSelect filterSelect(String value) // adds text for usage in

/* for use with editable instances of a reactSelect, where the options aren't shown
unless type-ahead filter information is keyed in first */
public FilteringReactSelect filterSelect(String value, Locator elementToWaitFor)
public FilteringReactSelect filterSelect(String value, @Nullable Locator elementToWaitFor)
{
waitForReady();
scrollIntoView();
WebElement success = null;
int tryCount = 0;
while (null == success && tryCount < 6)
{
tryCount++;
open();
open();

if (isMulti() || hasValue())
sleep(250);
setFilter(value);
if (isMulti() || hasValue())
sleep(250);
setFilter(value);

WebElement elemToClick = Locator.waitForAnyElement(
new FluentWait<SearchContext>(getComponentElement()).withTimeout(Duration.ofMillis(WAIT_FOR_JAVASCRIPT)),
Locators.options.containing(value));
WebElement elemToClick = Locator.waitForAnyElement(getWrapper().shortWait(),
Locators.option.withDescendant(Locator.tagWithText("strong", value)), // Exact match
Locators.option.containing(value));

log("clicking item with value [" +value+"]");
getWrapper().scrollIntoView(elemToClick);
log("clicking item with value [" + value + "]");
getWrapper().scrollIntoView(elemToClick);

WebDriverWrapper.waitFor(()-> {
try
{
if (isExpanded())
elemToClick.click();
sleep(250);
return !isExpanded();
}
catch (StaleElementReferenceException retry)
{
return false;
}
},"failed to select item "+ elemToClick.getAttribute("class") +" by clicking", WAIT_FOR_JAVASCRIPT);

success = elementToWaitFor.findElement(getComponentElement());
}
WebDriverWrapper.waitFor(() -> {
try
{
if (isExpanded())
elemToClick.click();
sleep(250);
return !isExpanded();
}
catch (StaleElementReferenceException retry)
{
return false;
}
}, "failed to select item " + elemToClick.getAttribute("class") + " by clicking", WAIT_FOR_JAVASCRIPT);

if (success == null)
log("Expected selection was not found. Selected value(s) are:" + getSelections());
if (elementToWaitFor != null)
elementToWaitFor.findElement(getComponentElement());

close();
return this;
Expand Down
3 changes: 2 additions & 1 deletion src/org/labkey/test/components/react/ReactSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class ReactSelect extends BaseReactSelect<ReactSelect>
{
private Function<String, Locator> _optionLocFactory = Locators.options::withText;
private Function<String, Locator> _optionLocFactory = Locators.option::withText;

public ReactSelect(WebElement element, WebDriver driver)
{
Expand All @@ -34,6 +34,7 @@ public ReactSelect(WebElement element, WebDriver driver)
public ReactSelect(ReactSelect wrapped)
{
this(wrapped.getComponentElement(), wrapped.getDriver());
setOptionLocator(wrapped._optionLocFactory);
}

public static ReactSelectFinder finder(WebDriver driver)
Expand Down