From 9bc089c0cd9ac7df0fa00fc77681117239e5dfe8 Mon Sep 17 00:00:00 2001 From: Chris Davis Date: Thu, 17 Aug 2023 21:01:13 +1000 Subject: [PATCH 1/3] Add Details, Summary, Caption element Implement more functions in table element --- .../api/common/tags/TagCaption.java | 19 +++++++++ .../api/common/tags/TagDetails.java | 17 ++++++++ .../api/common/tags/TagSummary.java | 17 ++++++++ .../api/element/grouping/HDetails.java | 15 +++++++ .../api/element/grouping/HSummary.java | 15 +++++++ .../api/element/table/HCaption.java | 14 +++++++ .../webfriends/api/element/table/HTable.java | 6 +++ .../selenium/common/tag/SeleniumTags.java | 10 ++++- .../selenium/common/tags/STagCaption.java | 18 ++++++++ .../selenium/common/tags/STagDetails.java | 18 ++++++++ .../selenium/common/tags/STagSummary.java | 18 ++++++++ .../selenium/element/grouping/SDetails.java | 23 ++++++++++ .../selenium/element/grouping/SSummary.java | 21 ++++++++++ .../selenium/element/table/SCaption.java | 18 ++++++++ .../selenium/element/table/STable.java | 42 +++++++++++++++---- .../selenium/smart/driver/SmartDriver.java | 16 ++++++- 16 files changed, 276 insertions(+), 11 deletions(-) create mode 100644 webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagCaption.java create mode 100644 webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagDetails.java create mode 100644 webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagSummary.java create mode 100644 webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/grouping/HDetails.java create mode 100644 webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/grouping/HSummary.java create mode 100644 webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HCaption.java create mode 100644 webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagCaption.java create mode 100644 webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagDetails.java create mode 100644 webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagSummary.java create mode 100644 webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/grouping/SDetails.java create mode 100644 webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/grouping/SSummary.java create mode 100644 webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/SCaption.java diff --git a/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagCaption.java b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagCaption.java new file mode 100644 index 0000000..370028a --- /dev/null +++ b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagCaption.java @@ -0,0 +1,19 @@ +package com.github.bordertech.webfriends.api.common.tags; + +import com.github.bordertech.webfriends.api.common.tag.TagType; +import com.github.bordertech.webfriends.api.element.table.HCaption; + +/** + * HTML caption tag. + * + * @param the element type + * + */ +public interface TagCaption extends TagType { + + @Override + default String getTagName() { + return "caption"; + } + +} diff --git a/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagDetails.java b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagDetails.java new file mode 100644 index 0000000..ef7fd89 --- /dev/null +++ b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagDetails.java @@ -0,0 +1,17 @@ +package com.github.bordertech.webfriends.api.common.tags; + +import com.github.bordertech.webfriends.api.common.tag.TagType; +import com.github.bordertech.webfriends.api.element.grouping.HDetails; + +/** + * HTML details tag. + * + * @param the element type + */ +public interface TagDetails extends TagType { + + @Override + default String getTagName() { + return "details"; + } +} diff --git a/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagSummary.java b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagSummary.java new file mode 100644 index 0000000..9d56f74 --- /dev/null +++ b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/common/tags/TagSummary.java @@ -0,0 +1,17 @@ +package com.github.bordertech.webfriends.api.common.tags; + +import com.github.bordertech.webfriends.api.common.tag.TagType; +import com.github.bordertech.webfriends.api.element.grouping.HSummary; + +/** + * HTML summary tag. + * + * @param the element type + */ +public interface TagSummary extends TagType { + + @Override + default String getTagName() { + return "summary"; + } +} diff --git a/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/grouping/HDetails.java b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/grouping/HDetails.java new file mode 100644 index 0000000..60da90a --- /dev/null +++ b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/grouping/HDetails.java @@ -0,0 +1,15 @@ +package com.github.bordertech.webfriends.api.element.grouping; + +import com.github.bordertech.webfriends.api.common.combo.FlowPalpableElement; +import com.github.bordertech.webfriends.api.common.model.ScriptSupportingModel; +import com.github.bordertech.webfriends.api.common.tags.TagDetails; + +/** + * Details element. + */ +public interface HDetails extends FlowPalpableElement, ScriptSupportingModel { + + @Override + TagDetails getTagType(); + +} diff --git a/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/grouping/HSummary.java b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/grouping/HSummary.java new file mode 100644 index 0000000..6aa8d24 --- /dev/null +++ b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/grouping/HSummary.java @@ -0,0 +1,15 @@ +package com.github.bordertech.webfriends.api.element.grouping; + +import com.github.bordertech.webfriends.api.common.combo.FlowPalpableElement; +import com.github.bordertech.webfriends.api.common.model.ScriptSupportingModel; +import com.github.bordertech.webfriends.api.common.tags.TagSummary; + +/** + * Summary element. + */ +public interface HSummary extends FlowPalpableElement, ScriptSupportingModel { + + @Override + TagSummary getTagType(); + +} diff --git a/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HCaption.java b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HCaption.java new file mode 100644 index 0000000..286fd0c --- /dev/null +++ b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HCaption.java @@ -0,0 +1,14 @@ +package com.github.bordertech.webfriends.api.element.table; + +import com.github.bordertech.webfriends.api.common.combo.FlowPalpableWithPhrasingElement; +import com.github.bordertech.webfriends.api.common.tags.TagCaption; + +/** + * Caption element. + */ +public interface HCaption extends FlowPalpableWithPhrasingElement { + + @Override + TagCaption getTagType(); + +} diff --git a/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HTable.java b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HTable.java index 691863a..cb58563 100644 --- a/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HTable.java +++ b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HTable.java @@ -75,6 +75,12 @@ public interface HTable extends FlowPalpableElement, ScriptSupportingModel { */ HRow getRow(final int rowIdx); + /** + * @return the list of rows + */ + List getRows(); + + /** * @return the no data message or null */ diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tag/SeleniumTags.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tag/SeleniumTags.java index dfc59cb..dab3cf0 100644 --- a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tag/SeleniumTags.java +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tag/SeleniumTags.java @@ -4,7 +4,9 @@ import com.github.bordertech.webfriends.selenium.common.tags.STagAudio; import com.github.bordertech.webfriends.selenium.common.tags.STagBody; import com.github.bordertech.webfriends.selenium.common.tags.STagButton; +import com.github.bordertech.webfriends.selenium.common.tags.STagCaption; import com.github.bordertech.webfriends.selenium.common.tags.STagDatalist; +import com.github.bordertech.webfriends.selenium.common.tags.STagDetails; import com.github.bordertech.webfriends.selenium.common.tags.STagDialog; import com.github.bordertech.webfriends.selenium.common.tags.STagDiv; import com.github.bordertech.webfriends.selenium.common.tags.STagFieldSet; @@ -50,6 +52,7 @@ import com.github.bordertech.webfriends.selenium.common.tags.STagSource; import com.github.bordertech.webfriends.selenium.common.tags.STagSpan; import com.github.bordertech.webfriends.selenium.common.tags.STagStrong; +import com.github.bordertech.webfriends.selenium.common.tags.STagSummary; import com.github.bordertech.webfriends.selenium.common.tags.STagTD; import com.github.bordertech.webfriends.selenium.common.tags.STagTH; import com.github.bordertech.webfriends.selenium.common.tags.STagTR; @@ -82,7 +85,9 @@ public final class SeleniumTags { public static final STagAudio AUDIO = new STagAudio(); public static final STagBody BODY = new STagBody(); public static final STagButton BUTTON = new STagButton(); + public static final STagCaption CAPTION = new STagCaption(); public static final STagDatalist DATALIST = new STagDatalist(); + public static final STagDetails DETAILS = new STagDetails(); public static final STagDialog DIALOG = new STagDialog(); public static final STagDiv DIV = new STagDiv(); public static final STagFieldSet FIELDSET = new STagFieldSet(); @@ -129,6 +134,7 @@ public final class SeleniumTags { public static final STagSource SOURCE = new STagSource(); public static final STagSpan SPAN = new STagSpan(); public static final STagStrong STRONG = new STagStrong(); + public static final STagSummary SUMMARY = new STagSummary(); public static final STagTable TABLE = new STagTable(); public static final STagTD TD = new STagTD(); public static final STagTextArea TEXTAREA = new STagTextArea(); @@ -141,11 +147,11 @@ public final class SeleniumTags { private static final List HEADING_TAGS = Arrays.asList(H1, H2, H3, H4, H5, H6); private static final List TAGS = Arrays.asList( - A, AUDIO, BODY, BUTTON, DATALIST, DIALOG, DIV, FIELDSET, FIGURE, FOOTER, FORM, H1, H2, H3, H4, H5, H6, + A, AUDIO, BODY, BUTTON, CAPTION, DATALIST, DETAILS, DIALOG, DIV, FIELDSET, FIGURE, FOOTER, FORM, H1, H2, H3, H4, H5, H6, HEAD, HEADER, HTML, IMG, INPUT_CHECKBOX, INPUT_COLOR, INPUT_COLOR, INPUT_DATE, INPUT_DATETIME, INPUT_EMAIL, INPUT_FILEUPLOAD, INPUT_NUMBER, INPUT_PASSWORD, INPUT_RADIO, INPUT_RADIO, INPUT_RANGE, INPUT_SEARCH, INPUT_TELEPHONE, INPUT_TEXT, INPUT_URL, - LABEL, LISTITEM, MENU, METER, NAV, OL, OPTGROUP, OPTION, P, PROGRESS, SECTION, SELECT, SOURCE, SPAN, STRONG, + LABEL, LISTITEM, MENU, METER, NAV, OL, OPTGROUP, OPTION, P, PROGRESS, SECTION, SELECT, SOURCE, SPAN, SUMMARY, STRONG, TABLE, TD, TEXTAREA, TH, TITLE, TR, TRACK, UL, VIDEO ); diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagCaption.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagCaption.java new file mode 100644 index 0000000..7006878 --- /dev/null +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagCaption.java @@ -0,0 +1,18 @@ +package com.github.bordertech.webfriends.selenium.common.tags; + +import com.github.bordertech.webfriends.api.common.tags.TagCaption; +import com.github.bordertech.webfriends.selenium.element.table.SCaption; + +/** + * HTML caption tag. + */ +public class STagCaption extends AbstractTag implements TagCaption { + + /** + * Default constructor. + */ + public STagCaption() { + super(SCaption.class); + } + +} diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagDetails.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagDetails.java new file mode 100644 index 0000000..0ed8747 --- /dev/null +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagDetails.java @@ -0,0 +1,18 @@ +package com.github.bordertech.webfriends.selenium.common.tags; + +import com.github.bordertech.webfriends.api.common.tags.TagDetails; +import com.github.bordertech.webfriends.selenium.element.grouping.SDetails; + +/** + * HTML details tag. + */ +public class STagDetails extends AbstractTag implements TagDetails { + + /** + * Default constructor. + */ + public STagDetails() { + super(SDetails.class); + } + +} diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagSummary.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagSummary.java new file mode 100644 index 0000000..0f51c24 --- /dev/null +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/common/tags/STagSummary.java @@ -0,0 +1,18 @@ +package com.github.bordertech.webfriends.selenium.common.tags; + +import com.github.bordertech.webfriends.api.common.tags.TagSummary; +import com.github.bordertech.webfriends.selenium.element.grouping.SSummary; + +/** + * HTML summary tag. + */ +public class STagSummary extends AbstractTag implements TagSummary { + + /** + * Default constructor. + */ + public STagSummary() { + super(SSummary.class); + } + +} diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/grouping/SDetails.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/grouping/SDetails.java new file mode 100644 index 0000000..31c0d97 --- /dev/null +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/grouping/SDetails.java @@ -0,0 +1,23 @@ +package com.github.bordertech.webfriends.selenium.element.grouping; + +import com.github.bordertech.webfriends.api.element.grouping.HDetails; +import com.github.bordertech.webfriends.selenium.common.feature.ContainerWithButtons; +import com.github.bordertech.webfriends.selenium.common.feature.ContainerWithChildren; +import com.github.bordertech.webfriends.selenium.common.tag.SeleniumTags; +import com.github.bordertech.webfriends.selenium.common.tags.STagDetails; +import com.github.bordertech.webfriends.selenium.element.AbstractSElement; + +/** + * Selenium details element. + */ +public class SDetails extends AbstractSElement implements HDetails, + ContainerWithChildren, ContainerWithButtons { + + @Override + public STagDetails getTagType() { + return SeleniumTags.DETAILS; + } + + + +} diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/grouping/SSummary.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/grouping/SSummary.java new file mode 100644 index 0000000..80ba0e0 --- /dev/null +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/grouping/SSummary.java @@ -0,0 +1,21 @@ +package com.github.bordertech.webfriends.selenium.element.grouping; + +import com.github.bordertech.webfriends.api.element.grouping.HSummary; +import com.github.bordertech.webfriends.selenium.common.feature.ContainerWithButtons; +import com.github.bordertech.webfriends.selenium.common.feature.ContainerWithChildren; +import com.github.bordertech.webfriends.selenium.common.tag.SeleniumTags; +import com.github.bordertech.webfriends.selenium.common.tags.STagSummary; +import com.github.bordertech.webfriends.selenium.element.AbstractSElement; + +/** + * Selenium summary element. + */ +public class SSummary extends AbstractSElement implements HSummary, + ContainerWithChildren, ContainerWithButtons { + + @Override + public STagSummary getTagType() { + return SeleniumTags.SUMMARY; + } + +} diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/SCaption.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/SCaption.java new file mode 100644 index 0000000..155fb50 --- /dev/null +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/SCaption.java @@ -0,0 +1,18 @@ +package com.github.bordertech.webfriends.selenium.element.table; + +import com.github.bordertech.webfriends.api.element.table.HCaption; +import com.github.bordertech.webfriends.selenium.common.tag.SeleniumTags; +import com.github.bordertech.webfriends.selenium.common.tags.STagCaption; +import com.github.bordertech.webfriends.selenium.element.AbstractSElement; + +/** + * Selenium Caption element. + */ +public class SCaption extends AbstractSElement implements HCaption { + + @Override + public STagCaption getTagType() { + return SeleniumTags.CAPTION; + } + +} diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java index d3a5421..197291e 100644 --- a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java @@ -2,9 +2,15 @@ import com.github.bordertech.webfriends.api.element.table.HTable; import com.github.bordertech.webfriends.selenium.common.tag.SeleniumTags; +import com.github.bordertech.webfriends.selenium.common.tags.STagTable; import com.github.bordertech.webfriends.selenium.element.AbstractSElement; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.openqa.selenium.By; + import java.util.List; -import com.github.bordertech.webfriends.selenium.common.tags.STagTable; +import java.util.function.Supplier; +import java.util.stream.IntStream; /** * Selenium table element. @@ -18,17 +24,30 @@ public STagTable getTagType() { @Override public List getColumnHeaders() { - throw new UnsupportedOperationException("Not supported yet."); + return getDriver().findWebFriends(SeleniumTags.TH, this.getWebElement(), By.tagName("th")); } @Override public SRow getRow(final int rowIdx) { - throw new UnsupportedOperationException("Not supported yet."); + List sRows = getRows(); + if (CollectionUtils.isEmpty(sRows) || CollectionUtils.size(sRows) - 1 < rowIdx) { + throw new IllegalArgumentException("Invalid row selection of " + rowIdx); + } + return sRows.get(rowIdx); + } + + @Override + public List getRows() { + return getDriver().findWebFriends(SeleniumTags.TR, this.getWebElement(), By.tagName("tr")); } @Override public SHeaderCell getColumnHeader(final int colIdx) { - throw new UnsupportedOperationException("Not supported yet."); + List columnHeaders = getColumnHeaders(); + if (CollectionUtils.isEmpty(columnHeaders) || CollectionUtils.size(columnHeaders) - 1 < colIdx) { + throw new IllegalArgumentException("Invalid column header selection of " + colIdx); + } + return columnHeaders.get(colIdx); } @Override @@ -38,17 +57,24 @@ public List getColumnDataCells(final int colIdx) @Override public String getTableCaption() { - throw new UnsupportedOperationException("Not supported yet."); + SCaption caption = getDriver().findWebFriend(SeleniumTags.CAPTION, this.getWebElement(), By.tagName("caption")); + return caption.getWebElement().getText(); } @Override public int getColumnCount() { - throw new UnsupportedOperationException("Not supported yet."); + return CollectionUtils.size(getColumnHeaders()); } @Override public int getColumnHeaderIndex(final String label) { - throw new UnsupportedOperationException("Not supported yet."); + List columnHeaders = getColumnHeaders(); + return IntStream.range(0, columnHeaders.size()) + .filter(i -> StringUtils.equals(columnHeaders.get(i).getHeaderText(), label)) + .findFirst() + .orElseThrow((Supplier) () -> { + throw new IllegalArgumentException("Invalid column header label"); + }); } @Override @@ -68,7 +94,7 @@ public int getSortedColumnIndex() { @Override public int getRowCount() { - throw new UnsupportedOperationException("Not supported yet."); + return CollectionUtils.size(getRows()); } @Override diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartDriver.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartDriver.java index f6a8852..46e8606 100644 --- a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartDriver.java +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartDriver.java @@ -290,9 +290,23 @@ public List findWebFriends(final TagTypeSelenium elem * @return the web friend wrapper for the matching element, or null if no match */ public List findWebFriends(final TagTypeSelenium elementTag, final By by) { - return getHelper().findWebFriends(this, getWebDriver(), elementTag, by); + return findWebFriends(elementTag, getWebDriver(), by); } + /** + * Find the child elements with this tag type and By. + * + * @param the web friends element type + * @param elementTag the element tag + * @param searchContext the search context to use + * @param by the BY condition + * @return the web friend wrapper for the matching element, or null if no match + */ + public List findWebFriends(final TagTypeSelenium elementTag, final SearchContext searchContext, final By by) { + return getHelper().findWebFriends(this, searchContext, elementTag, by); + } + + /** * Find the first child element for a tag type. * From d5c1ac3cca867f3db02c887542887d3c1954143c Mon Sep 17 00:00:00 2001 From: Chris Davis Date: Wed, 23 Aug 2023 17:24:07 +1000 Subject: [PATCH 2/3] Implement more functionality Add findParent start --- .../webfriends/api/element/table/HRow.java | 8 ++-- .../selenium/element/interactive/SDialog.java | 5 +- .../selenium/element/table/SRow.java | 47 ++++++++++++++---- .../selenium/element/table/STable.java | 8 ++-- .../selenium/smart/driver/SmartDriver.java | 48 +++++++++++++++++++ .../smart/driver/SmartHelperProvider.java | 28 +++++++++++ 6 files changed, 123 insertions(+), 21 deletions(-) diff --git a/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HRow.java b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HRow.java index 4f05212..de00dac 100644 --- a/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HRow.java +++ b/webfriends-api/src/main/java/com/github/bordertech/webfriends/api/element/table/HRow.java @@ -40,14 +40,14 @@ public interface HRow extends NoCategory, FlowModel, ScriptSupportingModel, Cust HDataCell getRowCellAsData(final int colIdx); /** - * @return the row header cell for this row or null + * @return true if the row has header cells */ - HHeaderCell getRowHeader(); + boolean hasRowHeaderCells(); /** - * @return true if the row has a header + * @return true if the row has data cells */ - boolean hasRowHeader(); + boolean hasRowDataCells(); /** * @return the cell elements for this row. Could be a mix of data and header elements if the row has a header. diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/interactive/SDialog.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/interactive/SDialog.java index 8a30bb8..63a0ee3 100644 --- a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/interactive/SDialog.java +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/interactive/SDialog.java @@ -5,6 +5,7 @@ import com.github.bordertech.webfriends.selenium.common.tag.SeleniumTags; import com.github.bordertech.webfriends.selenium.common.tags.STagDialog; import com.github.bordertech.webfriends.selenium.element.AbstractSElement; +import org.apache.commons.lang3.StringUtils; /** * Selenium dialog element. @@ -19,12 +20,12 @@ public STagDialog getTagType() { @Override public String getDialogTitle() { - throw new UnsupportedOperationException("Not supported yet."); + return getDriver().findWebFriend(SeleniumTags.HEADER, getWebElement()).getHeaderText(); } @Override public boolean isOpen() { - throw new UnsupportedOperationException("Not supported yet."); + return StringUtils.isNotBlank(getWebElement().getAttribute("open")); } @Override diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/SRow.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/SRow.java index 87f2624..b4732b5 100644 --- a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/SRow.java +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/SRow.java @@ -1,10 +1,15 @@ package com.github.bordertech.webfriends.selenium.element.table; +import com.github.bordertech.webfriends.api.element.table.CellElement; import com.github.bordertech.webfriends.api.element.table.HRow; import com.github.bordertech.webfriends.selenium.common.tag.SeleniumTags; +import com.github.bordertech.webfriends.selenium.common.tags.STagTR; import com.github.bordertech.webfriends.selenium.element.AbstractSElement; +import org.apache.commons.collections.CollectionUtils; + import java.util.List; -import com.github.bordertech.webfriends.selenium.common.tags.STagTR; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Selenium row of cells in a table. @@ -17,33 +22,55 @@ public STagTR getTagType() { } @Override - public List getRowCells() { - throw new UnsupportedOperationException("Not yet supported."); + public List getRowCells() { + return Stream.concat(getHeaderCells().stream(), getDataCells().stream()) + .collect(Collectors.toList()); } @Override public CellElementSelenium getRowCell(final int colIdx) { - throw new UnsupportedOperationException("Not supported yet."); + if (hasRowHeaderCells()) { + return getRowCellAsHeader(colIdx); + } else { + return getRowCellAsData(colIdx); + } } + @Override public SHeaderCell getRowCellAsHeader(final int colIdx) { - throw new UnsupportedOperationException("Not supported yet."); + List sHeaderCells = getHeaderCells(); + if (CollectionUtils.isEmpty(sHeaderCells) || CollectionUtils.size(sHeaderCells) - 1 < colIdx) { + throw new IllegalArgumentException("Invalid column selection of " + colIdx); + } + return sHeaderCells.get(colIdx); } @Override public SDataCell getRowCellAsData(int colIdx) { - throw new UnsupportedOperationException("Not supported yet."); + List sDataCells = getDataCells(); + if (CollectionUtils.isEmpty(sDataCells) || CollectionUtils.size(sDataCells) - 1 < colIdx) { + throw new IllegalArgumentException("Invalid column selection of " + colIdx); + } + return sDataCells.get(colIdx); } @Override - public SHeaderCell getRowHeader() { - throw new UnsupportedOperationException("Not supported yet."); + public boolean hasRowHeaderCells() { + return CollectionUtils.isNotEmpty(getHeaderCells()); } @Override - public boolean hasRowHeader() { - throw new UnsupportedOperationException("Not supported yet."); + public boolean hasRowDataCells() { + return CollectionUtils.isNotEmpty(getDataCells()); + } + + private List getHeaderCells() { + return getDriver().findWebFriends(SeleniumTags.TH, this.getWebElement()); + } + + private List getDataCells() { + return getDriver().findWebFriends(SeleniumTags.TD, this.getWebElement()); } } diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java index 197291e..0376340 100644 --- a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java @@ -6,7 +6,6 @@ import com.github.bordertech.webfriends.selenium.element.AbstractSElement; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.openqa.selenium.By; import java.util.List; import java.util.function.Supplier; @@ -24,7 +23,7 @@ public STagTable getTagType() { @Override public List getColumnHeaders() { - return getDriver().findWebFriends(SeleniumTags.TH, this.getWebElement(), By.tagName("th")); + return getDriver().findWebFriends(SeleniumTags.TH, this.getWebElement()); } @Override @@ -38,7 +37,7 @@ public SRow getRow(final int rowIdx) { @Override public List getRows() { - return getDriver().findWebFriends(SeleniumTags.TR, this.getWebElement(), By.tagName("tr")); + return getDriver().findWebFriends(SeleniumTags.TR, this.getWebElement()); } @Override @@ -57,8 +56,7 @@ public List getColumnDataCells(final int colIdx) @Override public String getTableCaption() { - SCaption caption = getDriver().findWebFriend(SeleniumTags.CAPTION, this.getWebElement(), By.tagName("caption")); - return caption.getWebElement().getText(); + return getDriver().findWebFriend(SeleniumTags.CAPTION, this.getWebElement()).getWebElement().getText(); } @Override diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartDriver.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartDriver.java index 46e8606..0b97c0d 100644 --- a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartDriver.java +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartDriver.java @@ -192,6 +192,18 @@ public T findWebFriend(final TagTypeSelenium elementTag) return getHelper().findWebFriend(this, getWebDriver(), elementTag); } + /** + * Find the first child element with this tag type. + * + * @param the web friends element type + * @param elementTag the element tag + * @param searchContext the search context to use + * @return the web friend wrapper for the matching element, or null if no match + */ + public T findWebFriend(final TagTypeSelenium elementTag, final SearchContext searchContext) { + return getHelper().findWebFriend(this, searchContext, elementTag); + } + /** * Find the first child element with this Tag Type and By. @@ -306,6 +318,17 @@ public List findWebFriends(final TagTypeSelenium elem return getHelper().findWebFriends(this, searchContext, elementTag, by); } + /** + * Find the child elements with this tag type and By. + * + * @param the web friends element type + * @param elementTag the element tag + * @param searchContext the search context to use + * @return the web friend wrapper for the matching element, or null if no match + */ + public List findWebFriends(final TagTypeSelenium elementTag, final SearchContext searchContext) { + return getHelper().findWebFriends(this, searchContext, elementTag); + } /** * Find the first child element for a tag type. @@ -383,6 +406,31 @@ public List findWebElements(final TagTypeSelenium elementTag, final return getHelper().findWebElements(getWebDriver(), elementTag, by); } + /** + * + * Finds the webfriend of a child elements parent + * @param childWebElement the child web element + * @param elementTag the element tag to wrap element with + * @param the web friends element type returned + * @return + */ + public T findWebFriendParent(final WebElement childWebElement, final TagTypeSelenium elementTag) { + return getHelper().findWebFriendParent(this, childWebElement, elementTag); + } + + /** + * + * Finds the webfriend of a child elements parent + * @param childElement the child element + * @param elementTag the element tag to wrap element with + * @param the web friends element type returned + * @param the web friends element type input + * @return + */ + public T findWebFriendParent(final I childElement, final TagTypeSelenium elementTag) { + return getHelper().findWebFriendParent(this, childElement, elementTag); + } + /** * @param key the access key */ diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartHelperProvider.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartHelperProvider.java index 498b9f3..4fa3073 100644 --- a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartHelperProvider.java +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/smart/driver/SmartHelperProvider.java @@ -185,6 +185,34 @@ public SElement wrapWebElement(final SmartDriver driver, final WebElement webEle return wrapWebElement(driver, webElement, tag); } + /** + * Finds the webfriend of a child elements parent + * + * @param driver the web driver + * @param childWebElement the child web element + * @param elementTag the element tag to wrap element with + * @param the web friends element type + * @return + */ + public T findWebFriendParent(final SmartDriver driver, final WebElement childWebElement, final TagTypeSelenium elementTag) { + return wrapWebElement(driver, childWebElement.findElement(By.xpath("parent::*")), elementTag); + } + + /** + * + * Finds the webfriend of a child elements parent + * @param driver the web driver + * @param childElement the child web element + * @param elementTag the element tag to wrap element with + * @param the web friends element type returned + * @param the web friends element type input + * @return + */ + public T findWebFriendParent(final SmartDriver driver, final I childElement, final TagTypeSelenium elementTag) { + return findWebFriendParent(driver, childElement.getWebElement(), elementTag); + } + + /** * Filter and wrap web elements with this tag type. * From efd4911bc65a3d4540a497ebf834d2d96e31a716 Mon Sep 17 00:00:00 2001 From: Chris Davis Date: Mon, 4 Sep 2023 12:08:28 +1000 Subject: [PATCH 3/3] Fix Sonar issue --- .../bordertech/webfriends/selenium/element/table/STable.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java index 0376340..438d046 100644 --- a/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java +++ b/webfriends-selenium-elements/src/main/java/com/github/bordertech/webfriends/selenium/element/table/STable.java @@ -28,7 +28,7 @@ public List getColumnHeaders() { @Override public SRow getRow(final int rowIdx) { - List sRows = getRows(); + List sRows = getRows(); if (CollectionUtils.isEmpty(sRows) || CollectionUtils.size(sRows) - 1 < rowIdx) { throw new IllegalArgumentException("Invalid row selection of " + rowIdx); } @@ -36,7 +36,7 @@ public SRow getRow(final int rowIdx) { } @Override - public List getRows() { + public List getRows() { return getDriver().findWebFriends(SeleniumTags.TR, this.getWebElement()); }