0

Implemented A Thucydides(SERENITY) BDD Environment for automated testing of version 0.9.269. I have seen that the runner of test cases picks up the random test stories. Is there any way so that the stories can be queued? The code for PortalTestSuit is as

public class PortalTestSuite extends ThucydidesJUnitStories {

private static final Logger LOGGER = LoggerFactory.getLogger(PortalTestSuite.class.getName());

/**
 * Instantiates a new Portal test suite.
 */
public PortalTestSuite() {

    /*Some Code to check the server is working or not*/

    /* Do all stories */
    findStoriesCalled("*.story");

}}

Here, the findStories will pick up the random stories from the directory and executes relative code... but please let me know the way to queue the Stories. Thanks.

UtkarshBhavsar
  • 249
  • 3
  • 23

1 Answers1

1

Yes, we can maintain the order of story by overriding storyPaths() method of ThucydidesJUnitStories class.

@Override
public List<String> storyPaths() {
    try {
        File file = new File(System.getProperty("user.dir").concat("/src/test/resources/StoryContextTest.script"));
        try (FileReader reader = new FileReader(file)) {
            char[] buffer = new char[(int) file.length()];
            reader.read(buffer);
            String[] lines = new String(buffer).split("\n");
            List<String> storiesList = new ArrayList<>(lines.length);
            StoryFinder storyFinder = new StoryFinder();
            for (String line : lines) {
                if (!line.equals("") && !line.startsWith("#")) {
                    if (line.endsWith("*")) {
                        for (URL classpathRootUrl : allClasspathRoots()) {
                            storiesList.addAll(storyFinder.findPaths(classpathRootUrl, line.concat("*/*.story"), ""));
                        }
                    } else {
                        storiesList.add(line);
                    }
                }
            }
            return storiesList;
        }
    } catch (Throwable e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
private List<URL> allClasspathRoots() {
    try {
        return Collections.list(getClassLoader().getResources("."));
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not load the classpath roots when looking for story files",e);
    }
}

The stories are being loaded from StoryContextTest.script as

################# Stories goes here #################
stories/authentication/authentication/authentication.story
stories/authentication/authentication/authentication1.story 
(Or)
    */authentication/* (will get stories randomly)

This way you can serialize your stories as in Thucydides.

UtkarshBhavsar
  • 249
  • 3
  • 23