diff --git a/FitNesseRoot/FitNesse/ReleaseNotes/content.txt b/FitNesseRoot/FitNesse/ReleaseNotes/content.txt index 0217150e62..706c0afcf3 100644 --- a/FitNesseRoot/FitNesse/ReleaseNotes/content.txt +++ b/FitNesseRoot/FitNesse/ReleaseNotes/content.txt @@ -1,4 +1,5 @@ !2 Pending Changes + * Added functionality to include pages based on tags defined for test page ([[1368][https://github.com/unclebob/fitnesse/pull/1368]]) !2 20250223 * Upgrade Bootstrap to version 4 ([[1516][https://github.com/unclebob/fitnesse/pull/1516]]) diff --git a/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests.wiki b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests.wiki new file mode 100644 index 0000000000..0045974f82 --- /dev/null +++ b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests.wiki @@ -0,0 +1,6 @@ +--- +Test +--- +!define INCLUDE_TAG_LIBRARIES {true} + +!contents \ No newline at end of file diff --git a/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagLibrarySuite.wiki b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagLibrarySuite.wiki new file mode 100644 index 0000000000..7c8eac9700 --- /dev/null +++ b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagLibrarySuite.wiki @@ -0,0 +1,5 @@ +--- +Suite: no +Test +--- +!contents \ No newline at end of file diff --git a/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagLibrarySuite/ShouldIncludeTagLibraries.wiki b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagLibrarySuite/ShouldIncludeTagLibraries.wiki new file mode 100644 index 0000000000..b03077d998 --- /dev/null +++ b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagLibrarySuite/ShouldIncludeTagLibraries.wiki @@ -0,0 +1,9 @@ +--- +Suites: TagTwo, TagOne +Test +--- +!|script| +|one| +|two| +|check|echo|$ONE|1| +|check|echo|$TWO|2| \ No newline at end of file diff --git a/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagOne.wiki b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagOne.wiki new file mode 100644 index 0000000000..a8e2f95180 --- /dev/null +++ b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagOne.wiki @@ -0,0 +1,5 @@ +--- +Test +--- +!|scenario|one| +|$ONE=|echo|1| \ No newline at end of file diff --git a/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagTwo.wiki b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagTwo.wiki new file mode 100644 index 0000000000..ece2ccd584 --- /dev/null +++ b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/ScenarioLibraryTestSuite/TagLibraryTests/TagTwo.wiki @@ -0,0 +1,2 @@ +!|scenario|two| +|$TWO=|echo|2| \ No newline at end of file diff --git a/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/SpecialPages/content.txt b/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/SpecialPages/content.txt index 874862d7ed..8d03bac47f 100644 --- a/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/SpecialPages/content.txt +++ b/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/SpecialPages/content.txt @@ -39,6 +39,11 @@ These pages are intended for scenario tables. They are included just after the !3 !-TemplateLibrary-! These pages act as a marker to find templates to show as available for insertion when editing a page. All children of a !-TemplateLibrary-! will be shown in the drop-down list of templates available for insertion. Unlike the other special pages, ''all'' brother and uncle !-TemplateLibrary-! pages are included. The oldest (grandest uncle) is included first. The brother, if it exists, is included last. This allows younger !-TemplateLibrary-! pages to override older ones. +!3 !-TagLibrary-! +Tag library lets you find pages with the same name as tags defined for your test page and includes them as a part of !-ScenarioLibraries-! element. Including works the same way as for standard !-ScenarioLibrary-!. If page has more than one tag defined, then pages are included in order in which tags appear in page definition (all pages for first tag, then all pages for second tag and so on). + +To turn this option on, you need to define somewhere in test tree following variable: +'''!-!define INCLUDE_TAG_LIBRARIES {true}-!''' !3 Suites. A special word about suites. If the suite has a deep hierarchy, and there are !-SuiteSetUp-! and/or !-SuiteTearDown-! pages below the suite page, they will not be included (unless the tests at those lower levels will also be executed). The !-SuiteSetUp-! and !-SuiteTearDown-! that are included in a suite run are (by default) the pages that are the nearest brothers or uncles of the ''Suite'' page. diff --git a/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/TestSuites/TagsAndFilters/content.txt b/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/TestSuites/TagsAndFilters/content.txt index 481a42c720..3b6309f2bf 100644 --- a/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/TestSuites/TagsAndFilters/content.txt +++ b/FitNesseRoot/FitNesse/UserGuide/WritingAcceptanceTests/TestSuites/TagsAndFilters/content.txt @@ -34,3 +34,6 @@ Remember, that the order tests run is alphabetical. So in the above example, !- ''Please note:'' if your test run is not failing from a certain point onwards, but has a few failures that you want to rerun the 'Rerun Failed' feature is probably more appropriate than 'startTest'. It can be accessed via the button on the suite result page (top right hand corner), or directly by going to: !style_code(!-http://<host>:<port>/RerunLastFailures?suite-!) + +!3 Including pages with tags +You can include pages on current test page, by using tags. To turn this option on, you need to define variable INCLUDE_TAG_PAGES anywhere in test tree and set it's value to "yes". Turning this option on, makes FitNesse search whole parent tree for pages wchich name is excactly like tag name and includes those pages at top of tested page (see [[!-SpecialPages-!][ getScenarioLibraries() { if (scenarioLibraries == null) { scenarioLibraries = findScenarioLibraries(); + scenarioLibraries.addAll(findTagLibraries()); } return scenarioLibraries; } @@ -226,11 +231,27 @@ private List findScenarioLibraries() { if (shouldIncludeScenarioLibraries()) { uncles = findUncles(SCENARIO_LIBRARY); } else { - uncles = Collections.emptyList(); + uncles = new LinkedList<>(); } return uncles; } + private List findTagLibraries() { + List pages = new LinkedList<>(); + WikiPageProperty suitesProperty = sourcePage.getData().getProperties().getProperty(WikiPageProperty.SUITES); + if (shouldIncludeTagLibraries() && suitesProperty != null){ + String[] tags = Arrays.stream(suitesProperty.getValue().split(",")).map(e -> e.trim()).filter(e -> checkIfTagIsNotReserved(e)).toArray(String[]::new); + for(int i = 0; i < tags.length; i++){ + pages.addAll(findUncles(tags[i].trim())); + } + } + return pages; + } + + private boolean checkIfTagIsNotReserved(String s){ + return !(s.trim().equals(SET_UP) || s.trim().equals(TEAR_DOWN) || s.trim().equals(SCENARIO_LIBRARY)); + } + protected List findUncles(String uncleName) { LinkedList uncles = new LinkedList<>(); sourcePage.getPageCrawler().traverseUncles(uncleName, uncles::addFirst); diff --git a/test/fitnesse/testrunner/WikiTestPageTest.java b/test/fitnesse/testrunner/WikiTestPageTest.java index f183772694..ce80b9ce3d 100644 --- a/test/fitnesse/testrunner/WikiTestPageTest.java +++ b/test/fitnesse/testrunner/WikiTestPageTest.java @@ -3,10 +3,7 @@ package fitnesse.testrunner; import fitnesse.testsystems.TestPage; -import fitnesse.wiki.PageData; -import fitnesse.wiki.PathParser; -import fitnesse.wiki.WikiPage; -import fitnesse.wiki.WikiPageUtil; +import fitnesse.wiki.*; import fitnesse.wiki.fs.InMemoryPage; import org.junit.Before; import org.junit.Test; @@ -32,6 +29,7 @@ public void setUp() throws Exception { addPage("TearDown", "teardown"); addPage("SuiteSetUp", "suiteSetUp"); addPage("SuiteTearDown", "suiteTearDown"); + addPage("TestTag", "TestTag"); WikiPage subPage = WikiPageUtil.addPage(wikiPage, PathParser.parse("SubPage"), "sub page"); WikiPageUtil.addPage(wikiPage, PathParser.parse("ScenarioLibrary"), "scenario library 2"); @@ -205,4 +203,46 @@ public void testPathSeparatorVariable() throws Exception { assertEquals(expected, new WikiTestPage(page).getClassPath().toString()); } + @Test + public void shouldIncludeTestPagesIfIncludeTagLibrariesSetToTrue() throws Exception { + WikiPage page = addPage("ParentPage", "!define INCLUDE_TAG_LIBRARIES {true}\n"); + WikiPage testPage = WikiPageUtil.addPage(page, PathParser.parse("TestPage"), "TestPage"); + PageData data = page.getData(); + data.getProperties().set(WikiPageProperty.SUITES,"TestTag, DummyTag"); + testPage.commit(data); + + TestPage runningTestPage = new WikiTestPage(testPage); + + String html = runningTestPage.getHtml(); + assertSubString("TestTag",html); + } + + @Test + public void shouldNotIncludeTestPagesIfIncludeTagLibrariesSetToFalse() throws Exception { + WikiPage page = addPage("ParentPage", "!define INCLUDE_TAG_LIBRARIES {false}\n"); + WikiPage testPage = WikiPageUtil.addPage(page, PathParser.parse("TestPage"), "TestPage"); + PageData data = page.getData(); + data.getProperties().set(WikiPageProperty.SUITES,"TestTag, DummyTag"); + testPage.commit(data); + + TestPage runningTestPage = new WikiTestPage(testPage); + + String html = runningTestPage.getHtml(); + assertNotSubString("TestTag",html); + } + + @Test + public void shouldNotIncludeTestPagesIfIncludeTagLibrariesIsNotSet() throws Exception { + WikiPage page = addPage("ParentPage", "ParentPage"); + WikiPage testPage = WikiPageUtil.addPage(page, PathParser.parse("TestPage"), "TestPage"); + PageData data = page.getData(); + data.getProperties().set(WikiPageProperty.SUITES,"TestTag, DummyTag"); + testPage.commit(data); + + TestPage runningTestPage = new WikiTestPage(testPage); + + String html = runningTestPage.getHtml(); + assertNotSubString("TestTag",html); + } + }