Skip to content

Commit a355dbc

Browse files
Issue 1135: More changes for accessibility (#3011)
1 parent cedecd6 commit a355dbc

10 files changed

Lines changed: 49 additions & 34 deletions

src/org/labkey/test/LabKeySiteWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public void attemptSignIn(String email, String password)
409409
assertElementPresent(Locator.tagWithName("form", "login"));
410410
setFormElement(Locator.id("email"), email);
411411
setFormElement(Locator.id("password"), password);
412-
WebElement signInButton = Locator.lkButton("Sign In").findElement(getDriver());
412+
WebElement signInButton = Locator.button("Sign In").findElement(getDriver());
413413
doAndMaybeWaitForPageToLoad(10_000, () -> {
414414
signInButton.click();
415415
shortWait().until(ExpectedConditions.invisibilityOfElementLocated(Locator.byClass("signing-in-msg")));

src/org/labkey/test/components/react/BaseReactSelect.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -612,21 +612,16 @@ public BaseReactSelectFinder<Select> withLabelForNamedInput(String label)
612612
return this;
613613
}
614614

615-
/* use this to find a reactSelect when the label text is contained within a label/span*/
616-
public BaseReactSelectFinder<Select> withLabelwithSpan(String labelSpanText)
615+
/* use this to find a reactSelect when the label text is contained within a span/span*/
616+
public BaseReactSelectFinder<Select> withSpanLabel(String spanText)
617617
{
618-
return followingLabelWithSpan(labelSpanText);
619-
}
620-
621-
public BaseReactSelectFinder<Select> followingLabelWithSpan(String labelText)
622-
{
623-
_locator = Locators.containerWithDescendant(Locator.tag("label").withChild(Locator.tagWithText("span", labelText)));
618+
_locator = Locators.containerWithDescendant(Locator.tagWithClassContaining("span", "control-label").withDescendant(Locator.tag("span").withText(spanText)));
624619
return this;
625620
}
626621

627-
public BaseReactSelectFinder<Select> followingLabelWithClass(String cls)
622+
public BaseReactSelectFinder<Select> followingSpanWithClass(String cls)
628623
{
629-
_locator = Locators.containerWithDescendant(Locator.tagWithClass("label", cls));
624+
_locator = Locators.containerWithDescendant(Locator.tagWithClass("span", cls));
630625
return this;
631626
}
632627

@@ -639,15 +634,15 @@ public BaseReactSelectFinder<Select> followingLabelWithClass(String cls)
639634
public BaseReactSelectFinder<Select> withinFormGroup(String labelText)
640635
{
641636
_locator = Locator.tagWithClass("div", "form-group")
642-
.withChild(Locator.tag("label").withPredicate("text() = " + Locator.xq(labelText)))
637+
.withChild(Locator.byClass("control-label").withPredicate("text() = " + Locator.xq(labelText)))
643638
.descendant(Locators.selectContainer());
644639
return this;
645640
}
646641

647642
public BaseReactSelectFinder<Select> withinFormGroupSkipSelect(String labelText)
648643
{
649644
_locator = Locator.tagWithClass("div", "form-group")
650-
.withChild(Locator.tag("label").withChild(Locator.tagWithText("span", labelText)));
645+
.withChild(Locator.byClass("control-label").withChild(Locator.tagWithText("span", labelText)));
651646
return this;
652647
}
653648

src/org/labkey/test/components/ui/entities/EntityBulkDialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ protected abstract class ElementCache extends ModalDialog.ElementCache
175175
*/
176176
public abstract WebElement formRow(CharSequence fieldIdentifier);
177177

178-
// For composite fields (e.g. StoredAmount + Units) that render a <div> label instead of <label for="...">,
178+
// For composite fields (e.g. StoredAmount + Units) that render a <span> label instead of <label for="...">,
179179
private WebElement formRowByControlLabel(String fieldLabel)
180180
{
181181
return _rows.computeIfAbsent(fieldLabel, k ->
182182
Locator.tagWithClass("div", "row")
183-
.withChild(Locator.tagWithClass("div", "control-label").withText(fieldLabel))
183+
.withChild(Locator.tagWithClass("span", "control-label").withText(fieldLabel))
184184
.waitForElement(this, WAIT_FOR_JAVASCRIPT));
185185
}
186186

src/org/labkey/test/components/ui/entities/EntityBulkInsertDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public WebElement formRow(CharSequence fieldIdentifier)
428428
return _rows.computeIfAbsent(fieldKey, fk ->
429429
Locator.tagWithClass("div", "row")
430430
// TODO: Shouldn't need to be case-insensitive. Parent/source lookups have weird casing
431-
.withDescendant(Locator.tagWithAttributeIgnoreCase("label", "for", fieldKey))
431+
.withDescendant(Locator.tagWithAttributeIgnoreCase("span", "data-fieldkey", fieldKey))
432432
.findElement(this));
433433
}
434434

src/org/labkey/test/components/ui/entities/EntityBulkUpdateDialog.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.labkey.test.params.FieldDefinition;
1919
import org.labkey.test.params.FieldKey;
2020
import org.labkey.test.util.AuditLogHelper;
21+
import org.openqa.selenium.NoSuchElementException;
2122
import org.openqa.selenium.WebDriver;
2223
import org.openqa.selenium.WebElement;
2324
import org.openqa.selenium.support.ui.ExpectedConditions;
@@ -26,6 +27,7 @@
2627
import java.io.File;
2728
import java.io.IOException;
2829
import java.time.Duration;
30+
import java.util.ArrayList;
2931
import java.util.List;
3032

3133
/**
@@ -325,15 +327,29 @@ public String getWarningAlertText()
325327

326328
public List<String> getFieldNames()
327329
{
328-
List<WebElement> labels = Locator.tagWithClass("label", "control-label").withAttribute("for")
329-
.waitForElements(elementCache(), 2_000);
330+
List<WebElement> controlLabels = Locator.byClass("control-label").waitForElements(elementCache(), 2_000);
331+
List<String> names = new ArrayList<>();
332+
for (WebElement label : controlLabels)
333+
{
334+
if (label.getAttribute("data-fieldkey") == null)
335+
try
336+
{
337+
label = label.findElement(Locator.tagWithAttribute("span", "data-fieldkey"));
338+
}
339+
catch (NoSuchElementException e)
340+
{
341+
throw new RuntimeException("Could not find field key for label: " + label.getText(), e);
342+
}
343+
String attribute = label.getAttribute("data-fieldkey");
344+
names.add(FieldKey.fromFieldKey(attribute).getFullName());
345+
}
330346

331347
// Amount and Units is an example that has a "hide-label" for StoredAmount
332348
List<WebElement> hiddenLabels = Locator.tagWithClass("label", "hide-label").withAttribute("for")
333349
.findElements(elementCache());
334-
labels.addAll(hiddenLabels);
350+
names.addAll(hiddenLabels.stream().map(a -> FieldKey.fromFieldKey(a.getDomAttribute("for")).getFullName()).toList());
335351

336-
return labels.stream().map(a -> FieldKey.fromFieldKey(a.getDomAttribute("for")).getFullName()).toList();
352+
return names;
337353
}
338354

339355
public EntityBulkUpdateDialog waitForFieldsToBe(List<String> expectedFieldNames, int waitMilliseconds)
@@ -425,7 +441,7 @@ public WebElement formRow(CharSequence fieldIdentifier)
425441
{
426442
String fieldKey = FieldKey.fromName(fieldIdentifier).toString();
427443
return Locator.tagWithClass("div", "row")
428-
.withDescendant(Locator.tagWithAttribute("label", "for", fieldKey))
444+
.withDescendant(Locator.tagWithAttribute("span", "data-fieldkey", fieldKey))
429445
.waitForElement(this, WAIT_TIMEOUT);
430446
}
431447

src/org/labkey/test/components/ui/entities/ParentEntityEditPanel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public ReactSelect getEntityTypeByPosition(int index)
277277
public ReactSelect getDisabledEntityTypeByLabel(String typeName)
278278
{
279279
return ReactSelect.finder(getDriver())
280-
.followingLabelWithSpan(typeName)
280+
.withSpanLabel(typeName)
281281
.waitFor(elementCache());
282282
}
283283

@@ -300,7 +300,7 @@ public ReactSelect getEntityType(String entityName)
300300
*/
301301
public List<String> getEntityTypeNames()
302302
{
303-
List<WebElement> labels = Locator.tagWithClass("label", "entity-insert--type-select").findElements(elementCache());
303+
List<WebElement> labels = Locator.tagWithClass("span", "entity-insert--type-select").findElements(elementCache());
304304
return labels.stream().map(WebElement::getText).toList();
305305
}
306306

@@ -312,7 +312,7 @@ public List<String> getEntityTypeNames()
312312
public List<ReactSelect> getAllEntityTypes()
313313
{
314314
return ReactSelect.finder(getDriver())
315-
.followingLabelWithClass("entity-insert--type-select")
315+
.followingSpanWithClass("entity-insert--type-select")
316316
.findAll(elementCache());
317317
}
318318

@@ -340,7 +340,7 @@ public FilteringReactSelect getParent(String typeName)
340340
public List<FilteringReactSelect> getAllParents()
341341
{
342342
return FilteringReactSelect.finder(getDriver())
343-
.followingLabelWithClass("entity-insert--parent-select")
343+
.followingSpanWithClass("entity-insert--parent-select")
344344
.findAll(elementCache());
345345
}
346346

src/org/labkey/test/components/ui/grids/DetailDataPanel.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public WebDriver getDriver()
4444
public String getTitle()
4545
{
4646
if (_title == null)
47-
_title = elementCache().heading.getText();
47+
_title = elementCache().headingText.getText();
4848
return _title;
4949
}
5050

@@ -160,12 +160,15 @@ protected ElementCache newElementCache()
160160

161161
protected class ElementCache extends Component<?>.ElementCache
162162
{
163-
final WebElement heading = Locator.tagWithClass("span", "detail__edit--heading").parent().findWhenNeeded(this);
163+
final Locator.XPathLocator editHeadingLocator = Locator.tagWithClass("span", "detail__edit--heading");
164+
final Locator.XPathLocator headingLocator = editHeadingLocator.parent();
165+
final WebElement editHeading = editHeadingLocator.findWhenNeeded(this);
166+
final WebElement headingText = headingLocator.childTag("span").findWhenNeeded(this);
164167

165168
public Optional<WebElement> editButton()
166169
{
167170
return Locator.byClass("detail__edit-button")
168-
.findOptionalElement(heading);
171+
.findOptionalElement(editHeading);
169172
}
170173

171174
// If this panel is for an aliquot sample there will be more than one table present.
@@ -223,7 +226,7 @@ protected Locator locator()
223226
return _baseLocatorAsTooltip;
224227
else if (_title != null)
225228
return _baseLocator.withChild(Locator.byClass("panel-heading")
226-
.withText(_title));
229+
.withText().containing(_title));
227230
else
228231
return _baseLocator;
229232
}

src/org/labkey/test/components/ui/grids/DetailTableEdit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ public DetailTableEditFinder(WebDriver driver)
667667
public DetailTableEditFinder withTitle(String title)
668668
{
669669
_locator = _baseLocator.withDescendant(Locator.tagWithClass("span", "detail__edit--heading")
670-
.parent().withText(title));
670+
.parent().childTag("span").withText(title));
671671
return this;
672672
}
673673

src/org/labkey/test/components/ui/grids/ParentDetailPanel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ public ResponsiveGrid<?> responsiveGridFor(String type)
200200
public static class ParentDetailPanelFinder extends WebDriverComponentFinder<ParentDetailPanel, ParentDetailPanelFinder>
201201
{
202202
private final Locator.XPathLocator _baseLocator = Locator.tagWithClass("div", "panel-default")
203-
.withChild(Locator.byClass("panel-heading")
204-
.withChild(Locator.tagWithClass("span", "detail__edit--heading")));
203+
.withChild(
204+
Locator.byClass("panel-heading").withChild(Locator.tagWithClass("span", "detail__edit--heading"))
205+
);
205206
private String _title = null;
206207

207208
public ParentDetailPanelFinder(WebDriver driver)

src/org/labkey/test/tests/SecurityTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ public void loginSelfRegistrationEnabledTest()
514514
}
515515
assertTitleContains(SIGN_IN_TEXT);
516516
assertElementPresent(Locator.tagWithName("form", "login"));
517-
clickAndWait(Locator.lkButton("Register"));
517+
clickAndWait(Locator.linkWithText("Register"));
518518

519519
assertTitleContains("Register");
520520
assertElementPresent(Locator.tagWithName("form", "register"));
@@ -542,7 +542,7 @@ public void loginSelfRegistrationDisabledTest()
542542
clickAndWait(Locator.linkWithText(SIGN_IN_TEXT));
543543
}
544544
assertTitleContains(SIGN_IN_TEXT);
545-
WebElement link = Locator.button("Register").findElementOrNull(getDriver());
545+
WebElement link = Locator.linkWithText("Register").findElementOrNull(getDriver());
546546
assertFalse("Self-registration button is visible", link != null && link.isDisplayed());
547547

548548
beginAt(buildURL("login", "register"));

0 commit comments

Comments
 (0)