Creating a Macro File
Test Scenario
Write your first macro file using the test scenario below:
You would like to test that your name does not appear on any learn.liferay.com article. The steps you would take are the following. Follow along manually on a separate browser to test the steps.
-
Navigate to the Liferay Learn site.
-
Click on the Search input field.
-
Type in your name as the search term.
-
Press the enter key to enter the search term.
-
Assert that there are no search results. If searching for your name returns results, please pick a different name.
-
Assert that a message appears saying there are no articles available.
Building the Macro File
-
Create an empty file in your
poshi-standalone/poshi-tests/macros
directory and name itLiferayLearnSearch.macro
. -
Macro files start with the definition block. Add this to your
LiferayLearnSearch.macro
file.definition { }
-
Within the definition block of the .macro file, macro blocks are used to define individual macros. To do so, use the macro keyword, followed by a string identifier name. These macro names must be unique and descriptive of the intended interaction. See Macros for more information. In the given scenario, the macro to search for a term can simply be called
searchForTerm
. -
Steps 2 to 4 from the test scenario are actions that together make a single Search interaction. These three steps will be included within the
searchForTerm
macro block. These actions can be scripted by using Functions with the locators created in the Creating A Path file article. For more information on using functions can be found in Functions.The resulting macro is as follows:
macro searchForTerm { Default.Click( locator1 = "LiferayLearn#SEARCH_BAR"); Default.Type( locator1 = "LiferayLearn#SEARCH_BAR", value1 = "${searchTerm}"); Default.KeyPress( locator1 = "LiferayLearn#SEARCH_BAR", value1 = "\ENTER"); }
-
Apart from the
searchForTerm
macro, the test scenario calls for a second macro to assert the results. Though steps 5 and 6 are separate assertions, together they form a single user interaction of asserting that there are no search results. This macro can be namedassertNoResults
.macro assertNoResults { Default.AssertElementNotPresent(locator1 = "LiferayLearn#SEARCH_RESULTS", value1 = "${searchTerm}"); Default.AssertElementPresent.assertVisible(locator1 = "LiferayLearn#NO_RESULTS_MESSAGE"); }
-
The resulting macro file should look like the following:
definition { macro assertNoResults { Default.AssertElementNotPresent(locator1 = "LiferayLearn#SEARCH_RESULTS", value1 = "${searchTerm}"); Default.AssertElementPresent.assertVisible(locator1 = "LiferayLearn#NO_RESULTS_MESSAGE"); } macro searchForTerm { Default.Click( locator1 = "LiferayLearn#SEARCH_BAR"); Default.Type( locator1 = "LiferayLearn#SEARCH_BAR", value1 = "${searchTerm}"); Default.KeyPress( locator1 = "LiferayLearn#SEARCH_BAR", value1 = "\ENTER"); } }