Tutorial: Create new executable example - iks-gmbh-tools/SysNat GitHub Wiki
A new Executable Example is created when a new requirement must be described or an existing feature which is not yet tested is going to be tested.
Note: Running SysNat means starting two separate JVMs one after another. The first creates Java code and the second compiles and executes this code by calling Maven. If you change code executed by the second JVM (i.e. the LanguageTemplateContainer) you must rebuild your code base by maven (clean+install) to have the jar files in your local Maven repository updated. Otherwise your changed code will not execute. If the following instructions say Rebuild, it means a clean and install by Maven (best done on the parent project).
-
Create a new text file "./sysnat.natural.language.executable.examples/ExecutableExamples/InternetSearch/SearchForSysNat.nlxx".
-
Give this nlxx-file the following content:
XX: Search for SysNat with DuckDuckGo
Enter search text "SysNat IKS".
-
Start SysNat and read the message in the error report. A non-developer needs help now. Alternatively, there is another language template that can be used for the same purpose. A non-developer may have a look in the file '/sysnat.natural.language.executable.examples/help/ExistingNLInstructions_InternetSearch.html' or call a developer for help.
-
As developer, have a look into the console output. The messages there contain information how the problem can be solved: by creating a new java method. A suggestion what the new method is supposed to look like is available. Copy the suggestion for the new method from the console into the clipboard. It should look like that:
@LanguageTemplate(value = "Enter search text ^^.")
public void replaceByAnExpressiveMethodName(String SysNat)
{
// Implement here code that corresponds to the Language Template's promise.
// And don't forget to create a report message entry!
}
-
Paste the suggestion into the file "./sysnat.test.runtime.environment/src/main/java/com/iksgmbh/sysnat/language_templates/internetsearch/LanguageTemplatesInternetSearchBasics.java". Rebuild the code, restart the test execution and check the test report. It is successful but shows no details, because the step defined does nothing.
-
Make the method look like that:
@LanguageTemplate(value = "Enter search text ^^.")
public void enterSearchText(String searchString)
{
executableExample.inputText("search_button_homepage", searchString);
executableExample.addReportMessage("Search text <b>" + searchString + "</b> entered.");
}
-
Make the code compile, rebuild, restart the test execution und check the test report. It tells that the first step has been executed.
-
Add the following lines to the nlxx-file:
Start search. Search results contain "iks-gmbh-tools/SysNat - GitHub".
-
Repeat step 4 and 5.
-
Give the first new method the name startSearch and the following body:
executableExample.getActiveGuiController().pressEnter(); executableExample.addReportMessage("Search started.");
-
Enter the following import instruction:
import static com.iksgmbh.sysnat.common.utils.SysNatConstants.QUESTION_IDENTIFIER;
-
Give the second new method the name checkSearchResult and the following body:
executableExample.sleep(2500); // give browser enough time to finish loading the result boolean ok = executableExample.isTextCurrentlyDisplayed(possibleMatch); String question = "Is text <b>" + searchText + "</b> displayed" + QUESTION_IDENTIFIER; executableExample.answerQuestion(question, ok);
-
Make the code compile, rebuild the code and restart SysNat. It will run without problem.
-
Check the test report. It contains the three executed steps.