diff --git a/src/org/labkey/test/components/html/Table.java b/src/org/labkey/test/components/html/Table.java index ddfc74e2f8..b7dfdfaf3c 100644 --- a/src/org/labkey/test/components/html/Table.java +++ b/src/org/labkey/test/components/html/Table.java @@ -26,7 +26,9 @@ import org.openqa.selenium.WebElement; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; public class Table extends WebDriverComponent { @@ -62,7 +64,7 @@ protected Elements newElementCache() return new Elements(); } - protected class Elements extends Component.ElementCache + protected class Elements extends Component.ElementCache { List rows; @@ -86,7 +88,7 @@ public int getRowCount() */ public List getTableHeaderTexts() { - List headerEls = Locator.xpath("//thead//th").findElements(this); + List headerEls = Locator.xpath("./thead/tr[1]/th").findElements(this); List columnHeaders = new ArrayList<>(); for(WebElement headerEl : headerEls){columnHeaders.add(headerEl.getText());} return columnHeaders; @@ -94,7 +96,7 @@ public List getTableHeaderTexts() public int getTableHeaderIndex(String headerText) { - List headerEls = Locator.xpath("//thead//th").findElements(this); + List headerEls = Locator.xpath("./thead/tr[1]/th").findElements(this); int counter = 1; for(WebElement headerEl : headerEls) { @@ -105,6 +107,36 @@ public int getTableHeaderIndex(String headerText) throw new RuntimeException( headerText + " column not found"); } + /** + * Get table data as a list of maps. Each map represents a row.
+ * Assumes a simple table with a single header row with no colspans and unique header labels + * @return table data + */ + public List> getTableData() + { + List> data = new ArrayList<>(); + + List headerTexts = getTableHeaderTexts(); + List rows = elementCache().getRows(); + + for (WebElement row : rows) + { + List dataTexts = getWrapper().getTexts(Locator.tag("td").findElements(row)); + if (headerTexts.size() != dataTexts.size()) + { + throw new IllegalStateException("Size of row %s doesn't match table header %s".formatted(dataTexts, headerTexts)); + } + Map rowMap = new LinkedHashMap<>(); + for (int i = 0; i < headerTexts.size(); i++) + { + rowMap.put(headerTexts.get(i), dataTexts.get(i)); + } + data.add(rowMap); + } + + return data; + } + public List getTableHeaderColumnData(String headerText) { List columnData = new ArrayList<>(); diff --git a/src/org/labkey/test/tests/MessagesLongTest.java b/src/org/labkey/test/tests/MessagesLongTest.java index cf780b2f74..9bdbc372fd 100644 --- a/src/org/labkey/test/tests/MessagesLongTest.java +++ b/src/org/labkey/test/tests/MessagesLongTest.java @@ -74,8 +74,11 @@ public class MessagesLongTest extends BaseWebDriverTest private static final String USER3 = "messageslong_user3@messages.test"; private static final String NOT_A_USER = "Squirrel"; private static final String RESPONDER = "responder@messages.test"; + private static final String MACRO_WEBPART = "${labkey.webPart(partName='Lists')}"; private static final String HTML_BODY = "1 x\n" + - "${labkey.webPart(partName='Lists')}\n"; + "" + + MACRO_WEBPART + + "\n"; private static final String HTML_BODY_WEBPART_TEST = "manage lists"; private static final String MEMBER_LIST = "memberListInput"; private static final String TEMPLATE_TEXT = "***Please do not reply to this email notification. Replies to this email are routed to an unmonitored mailbox. Instead, please use the link below.***"; @@ -224,15 +227,19 @@ public void testSteps() InsertPage markdownPage = new InsertPage(getDriver()); assertEquals("default selection should be 'Markdown'",markdownPage.getRenderAs(), WikiHelper.WikiRendererType.MARKDOWN); markdownPage.setTitle("Markdown is a thing now") - .setBody("# Holy Header, Batman!\n" + - "**bold as bold can possibly be**\n" + - "\n" + - "```var foo = bar.fooValue;```\n" + - "\n" + - "## List of things I don't like \n" + - "+ hair clogs\n" + - "+ stinky feet\n" + - "+ internet trolls"); + .setBody(""" + # Holy Header, Batman! + **bold as bold can possibly be** + + ```var foo = bar.fooValue;``` + + ## List of things I don't like\s + + hair clogs + + stinky feet + + internet trolls + + escaped""" + + "\n" + MACRO_WEBPART); // now look at the preview pane markdownPage.selectPreviewTab(); @@ -240,6 +247,9 @@ public void testSteps() assertElementPresent(Locator.tagWithText("li", "hair clogs")); assertElementPresent(Locator.tagWithText("li", "stinky feet")); assertElementPresent(Locator.tagWithText("li", "internet trolls")); + assertElementPresent(Locator.tagWithText("p", "escaped")); + assertElementPresent(PortalHelper.Locators.webPart("Lists")); + assertElementPresent(Locator.linkWithText("manage lists")); clickButton("Submit"); assertElementPresent(Locator.tagWithText("h1", "Holy Header, Batman!")); assertElementPresent(Locator.tagWithText("strong", "bold as bold can possibly be")); diff --git a/src/org/labkey/test/tests/wiki/WikiLongTest.java b/src/org/labkey/test/tests/wiki/WikiLongTest.java index 2129fcbd53..da9c119ebd 100644 --- a/src/org/labkey/test/tests/wiki/WikiLongTest.java +++ b/src/org/labkey/test/tests/wiki/WikiLongTest.java @@ -26,6 +26,7 @@ import org.labkey.test.categories.Daily; import org.labkey.test.categories.Wiki; import org.labkey.test.util.OptionalFeatureHelper; +import org.labkey.test.util.DataRegionTable; import org.labkey.test.util.PortalHelper; import org.labkey.test.util.WikiHelper; import org.openqa.selenium.WebElement; @@ -122,6 +123,10 @@ public class WikiLongTest extends BaseWebDriverTest # Title MD ## Subtitle MD *italic text MD* + + escaped + + ${labkey.webPart(partName='Query', title='WebPart Macro', schemaName='core', queryName='containers', allowChooseQuery='true', allowChooseView='true')} """; private static final String SAFE_LINK_HTML = "Safe link"; @@ -226,13 +231,18 @@ public void testSteps() _wikiHelper.setWikiBody(WIKI_PAGE7_CONTENT); _wikiHelper.saveWikiPage(); // verify that after saving the markdown that it is rendered as html that does not include the markdown symbols - assertTextPresent("Title MD"); + assertElementPresent(Locator.tagWithText("h1", "Title MD")); + assertElementPresent(Locator.tagWithText("p", "escaped")); + assertElementPresent(PortalHelper.Locators.webPart("WebPart Macro")); + assertElementPresent(DataRegionTable.Locators.dataRegionTable().descendant(Locator.linkWithText(getProjectName()))); assertTextNotPresent("# Title MD"); clickAndWait(Locator.linkWithText("Edit")); _wikiHelper.convertWikiFormat("HTML"); // verify that after converting the markdown to html that it is rendered as html that does not include the markdown symbols _wikiHelper.saveWikiPage(); - assertTextPresent("Title MD"); + assertElementPresent(Locator.tagWithText("h1", "Title MD")); + assertElementPresent(Locator.tagWithText("p", "escaped")); + // Webpart macro assertTextNotPresent("# Title MD"); searchFor(PROJECT_NAME, "italic text MD", 1, WIKI_PAGE7_TITLE);