Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to include pages based on tags defined for test page. #1368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
Test
---
!define INCLUDE_TAG_LIBRARIES {true}

!contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
Suite: no
Test
---
!contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
Suites: TagTwo, TagOne
Test
---
!|script|
|one|
|two|
|check|echo|$ONE|1|
|check|echo|$TWO|2|
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
Test
---
!|scenario|one|
|$ONE=|echo|1|
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!|scenario|two|
|$TWO=|echo|2|
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-!][<FitNesse.FullReferenceGuide.UserGuide.WritingAcceptanceTests.SpecialPages]]).
35 changes: 25 additions & 10 deletions src/fitnesse/testrunner/WikiTestPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

import fitnesse.testsystems.ClassPath;
import fitnesse.testsystems.TestPage;
import fitnesse.wiki.BaseWikitextPage;
import fitnesse.wiki.PageData;
import fitnesse.wiki.PathParser;
import fitnesse.wiki.SymbolicPage;
import fitnesse.wiki.WikiPage;
import fitnesse.wiki.WikiPagePath;
import fitnesse.wiki.*;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do explicit imports instead of .*? (Also for test class)

import fitnesse.wikitext.MarkUpSystem;
import fitnesse.wikitext.parser.Include;

import java.io.File;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.function.BiConsumer;

// TODO: need 2 implementations, one for wiki text pages (Fit, Slim) and one for non-wiki text pages. See PagesByTestSystem
Expand Down Expand Up @@ -192,9 +185,15 @@ public boolean shouldIncludeScenarioLibraries() {
return includeScenarios || (!notIncludeScenarios && isSlim);
}

public boolean shouldIncludeTagLibraries() {
String includeVar = sourcePage.getVariable("INCLUDE_TAG_LIBRARIES");
return includeVar != null && "true".equalsIgnoreCase(includeVar);
}

public List<WikiPage> getScenarioLibraries() {
if (scenarioLibraries == null) {
scenarioLibraries = findScenarioLibraries();
scenarioLibraries.addAll(findTagLibraries());
}
return scenarioLibraries;
}
Expand Down Expand Up @@ -226,11 +225,27 @@ private List<WikiPage> findScenarioLibraries() {
if (shouldIncludeScenarioLibraries()) {
uncles = findUncles(SCENARIO_LIBRARY);
} else {
uncles = Collections.emptyList();
uncles = new LinkedList<>();
}
return uncles;
}

private List<WikiPage> findTagLibraries() {
List<WikiPage> pages = new LinkedList<>();
WikiPageProperty suitesProperty = sourcePage.getData().getProperties().getProperty(WikiPageProperty.SUITES);
if (shouldIncludeTagLibraries() && suitesProperty != null){
String[] tags1 = Arrays.stream(suitesProperty.getValue().split(",")).map(e -> e.trim()).filter(e -> checkIfTagIsNotReserved(e)).toArray(String[]::new);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this just be tags?

for(int i=0;i<tags1.length;i++){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for(int i=0;i<tags1.length;i++){
for(int i = 0; i < tags1.length; i++){

pages.addAll(findUncles(tags1[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<WikiPage> findUncles(String uncleName) {
LinkedList<WikiPage> uncles = new LinkedList<>();
sourcePage.getPageCrawler().traverseUncles(uncleName, uncles::addFirst);
Expand Down
48 changes: 44 additions & 4 deletions test/fitnesse/testrunner/WikiTestPageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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);
}

}