11// @ts -check
22
33import { test } from '@playwright/test' ;
4- import { UIReference , slugs } from '@config' ;
4+ import { UIReference , slugs , inputValues } from '@config' ;
55
66import LoginPage from '@poms/frontend/login.page' ;
77import MainMenuPage from '@poms/frontend/mainmenu.page' ;
@@ -10,42 +10,179 @@ import { requireEnv } from '@utils/env.utils';
1010
1111// no resetting storageState, mainmenu has more functionalities when logged in.
1212
13- // Before each test, log in
14- test . beforeEach ( async ( { page, browserName } ) => {
15- const browserEngine = browserName ?. toUpperCase ( ) || "UNKNOWN" ;
16- const emailInputValue = requireEnv ( `MAGENTO_EXISTING_ACCOUNT_EMAIL_${ browserEngine } ` ) ;
17- const passwordInputValue = requireEnv ( 'MAGENTO_EXISTING_ACCOUNT_PASSWORD' ) ;
13+ test . describe ( 'Guest tests (not logged in)' , ( ) => {
14+ /**
15+ * @feature Navigate to login page
16+ * @scenario user clicks 'log in' button in main menu
17+ * @given I am not logged in
18+ * @and I am on any Magento 2 page
19+ * @when I click on the user icon in the main menu
20+ * @and I click the 'sign in' button
21+ * @then I should navigate to the login page
22+ */
23+ test ( 'User_navigates_to_login' , { tag : [ '@mainmenu' , '@cold' ] } , async ( { page} ) => {
24+ const mainMenu = new MainMenuPage ( page ) ;
25+ await mainMenu . goToLoginPage ( ) ;
26+ } ) ;
1827
19- const loginPage = new LoginPage ( page ) ;
20- await loginPage . login ( emailInputValue , passwordInputValue ) ;
21- } ) ;
28+ /**
29+ * @feature Navigate to create account page
30+ * @scenario user clicks 'create an account' button in main menu
31+ * @given I am not logged in
32+ * @and I am on any Magento 2 page
33+ * @when I click on the user icon in the main menu
34+ * @and I click the 'create an account' button
35+ * @then I should navigate to the create account page
36+ */
37+ test ( 'User_navigates_to_create_account' , { tag : [ '@mainmenu' , '@cold' ] } , async ( { page} ) => {
38+ const mainMenu = new MainMenuPage ( page ) ;
39+ await mainMenu . goToCreateAccountPage ( ) ;
40+ } ) ;
2241
23- /**
24- * @feature Logout
25- * @scenario The user can log out
26- * @given I am logged in
27- * @and I am on any Magento 2 page
28- * @when I open the account menu
29- * @and I click the Logout option
30- * @then I should see a message confirming I am logged out
31- */
32- test ( 'User_logs_out' , { tag : [ '@mainmenu' , '@hot' ] } , async ( { page} ) => {
33- const mainMenu = new MainMenuPage ( page ) ;
34- await mainMenu . logout ( ) ;
35- } ) ;
42+ /**
43+ * @feature Navigate to subcategory page
44+ * @scenario User hover over menu link to navigate to category page
45+ * @given I am not logged in
46+ * @and I am on any Magento 2 page
47+ * @when I hover over an item in the main menu
48+ * @then A dropdown menu should appear
49+ * @when I click an item
50+ * @then I should navigate to the page
51+ */
52+ test ( 'Navigate_to_category_page' , { tag : [ '@mainmenu' , '@cold' ] } , async ( { page} ) => {
53+ const mainMenu = new MainMenuPage ( page ) ;
54+ await mainMenu . goToCategoryPage ( ) ;
55+ } ) ;
56+
57+ /**
58+ * @feature Navigate to category page
59+ * @scenario User hover over menu link to navigate to category page
60+ * @given I am not logged in
61+ * @and I am on any Magento 2 page
62+ * @when I hover over an item in the main menu
63+ * @then A dropdown menu should appear
64+ * @when I click an item
65+ * @then I should navigate to the page
66+ */
67+ test ( 'Navigate_to_subcategory_page' , { tag : [ '@mainmenu' , '@cold' ] } , async ( { page} ) => {
68+ const mainMenu = new MainMenuPage ( page ) ;
69+ await mainMenu . goToSubCategoryPage ( ) ;
70+ } ) ;
3671
72+ /**
73+ * @feature open the minicart
74+ * @scenario guest opens the minicart
75+ * @given I am on any page
76+ * @when I click the minicart button
77+ * @then the minicart should show up
78+ */
79+ test ( 'Open_the_minicart' , { tag : [ '@mainmenu' , '@cold' ] } , async ( { page} ) => {
80+ const mainMenu = new MainMenuPage ( page ) ;
81+ await mainMenu . openMiniCart ( ) ;
82+ } ) ;
3783
38- test ( 'Navigate_to_account_page' , { tag : [ '@mainmenu' , '@hot' ] } , async ( { page} ) => {
39- const mainMenu = new MainMenuPage ( page ) ;
40- await mainMenu . gotoMyAccount ( ) ;
84+ /**
85+ * @feature Search Field
86+ * @scenario guest uses the search field
87+ * @given I am on any page
88+ * @when I click the search button
89+ * @then a search field should show up
90+ * @when I type in a search term
91+ * @and I click search
92+ * @then I should be navigated to a results page
93+ * @and I should see my search term in the title of the page
94+ */
95+ test ( 'User_searches_for_product' , { tag : [ '@mainmenu' , '@cold' ] } , async ( { page} ) => {
96+ const mainMenu = new MainMenuPage ( page ) ;
97+ await mainMenu . searchForProduct ( inputValues . search . queryMultipleResults ) ;
98+ } ) ;
4199} ) ;
42100
43- test ( 'Open_the_minicart' , { tag : [ '@mainmenu' , '@cold' ] } , async ( { page} , testInfo ) => {
44- testInfo . annotations . push ( { type : 'WARNING (FIREFOX)' , description : `The minicart icon does not lose its aria-disabled=true flag when the first product is added. This prevents Playwright from clicking it. A fix will be added in the future.` } ) ;
101+ test . describe ( 'User tests (logged in)' , ( ) => {
102+ // Before each test, log in
103+ test . beforeEach ( async ( { page, browserName } ) => {
104+ const browserEngine = browserName ?. toUpperCase ( ) || "UNKNOWN" ;
105+ const emailInputValue = requireEnv ( `MAGENTO_EXISTING_ACCOUNT_EMAIL_${ browserEngine } ` ) ;
106+ const passwordInputValue = requireEnv ( 'MAGENTO_EXISTING_ACCOUNT_PASSWORD' ) ;
107+
108+ const loginPage = new LoginPage ( page ) ;
109+ await loginPage . login ( emailInputValue , passwordInputValue ) ;
110+ } ) ;
111+
112+ /**
113+ * @feature Logout
114+ * @scenario The user can log out
115+ * @given I am logged in
116+ * @and I am on any Magento 2 page
117+ * @when I open the account menu
118+ * @and I click the Logout option
119+ * @then I should see a message confirming I am logged out
120+ */
121+ test ( 'User_logs_out' , { tag : [ '@mainmenu' , '@hot' ] } , async ( { page} ) => {
122+ const mainMenu = new MainMenuPage ( page ) ;
123+ await mainMenu . logout ( ) ;
124+ } ) ;
125+
126+ /**
127+ * @feature Navigate to account page
128+ * @scenario user navigates to account page
129+ * @given I am logged in
130+ * @and I am on any magento 2 page
131+ * @when I open the account menu
132+ * @and I click the account button
133+ * @and I click the 'my account' button
134+ * @then I should be navigated to my account
135+ */
136+ test ( 'Navigate_to_account_page' , { tag : [ '@mainmenu' , '@hot' ] } , async ( { page} ) => {
137+ const mainMenu = new MainMenuPage ( page ) ;
138+ await mainMenu . gotoMyAccount ( ) ;
139+ } ) ;
45140
46- const mainMenu = new MainMenuPage ( page ) ;
47- const productPage = new ProductPage ( page ) ;
141+ /**
142+ * @feature Navigate to wishlist
143+ * @scenario user navigates to their wishlist
144+ * @given I am logged in
145+ * @and I am on any magento 2 page
146+ * @when I open the account menu
147+ * @and I click on the wishlist button
148+ * @then I should be navigated to the wishlist page
149+ */
150+ test ( 'Navigate_to_wishlist' , { tag : [ '@mainmenu' , '@hot' ] } , async ( { page} ) => {
151+ const mainMenu = new MainMenuPage ( page ) ;
152+ await mainMenu . goToWishList ( ) ;
153+ } ) ;
48154
49- await productPage . addSimpleProductToCart ( UIReference . productPage . simpleProductTitle , slugs . productPage . simpleProductSlug ) ;
50- await mainMenu . openMiniCart ( ) ;
155+ /**
156+ * @feature Navigate to orders overview
157+ * @scenario user navigates to their order history
158+ * @given I am logged in
159+ * @and I am on any magento 2 page
160+ * @when I open the account menu
161+ * @and I click on the 'My orders' button
162+ * @then I should be navigated to the page with my order history
163+ */
164+ test ( 'Navigate_to_orders' , { tag : [ '@mainmenu' , '@hot' ] } , async ( { page} ) => {
165+ const mainMenu = new MainMenuPage ( page ) ;
166+ await mainMenu . goToOrders ( ) ;
167+ } ) ;
168+
169+ /**
170+ * @feature Navigate to address book
171+ * @scenario user navigates to their address book
172+ * @given I am logged in
173+ * @and I am on any Magento 2 page
174+ * @when I open the account menu
175+ * @and I click on the 'Address book' button
176+ * @then I should be navigated to the page with my order history
177+ * @and I should see an appropriate title based on whether an address has been added
178+ */
179+ test ( 'Navigate_to_address_book' , { tag : [ '@mainmenu' , '@hot' ] } , async ( { page} ) => {
180+ const mainMenu = new MainMenuPage ( page ) ;
181+ await mainMenu . goToAddressBook ( ) ;
182+ } ) ;
51183} ) ;
184+
185+
186+
187+
188+
0 commit comments