33import { test as base } from '@playwright/test' ;
44import fs from 'fs' ;
55import path from 'path' ;
6- import { toggles , inputValues } from 'config' ;
6+ import { inputValues } from 'config' ;
7+ import { requireEnv } from './utils/env.utils' ;
78
89import MagentoAdminPage from './poms/adminhtml/magentoAdmin.page' ;
910import RegisterPage from './poms/frontend/register.page' ;
10- import { requireEnv } from './utils/env.utils' ;
11-
12- /**
13- * NOTE:
14- * The first if-statement checks if we are running in CI.
15- * If so, we always run the setup.
16- * Else, we check if the 'setup' test toggle in test-toggles.json has been set to true.
17- */
1811
19- const runSetupTests = ( describeFn : typeof base . describe | typeof base . describe . only ) => {
20- describeFn ( 'Setting up the testing environment' , ( ) => {
21- base ( 'Enable_multiple_admin_logins' , { tag : '@setup' } , async ( { page, browserName } , testInfo ) => {
22- const magentoAdminUsername = requireEnv ( 'MAGENTO_ADMIN_USERNAME' ) ;
23- const magentoAdminPassword = requireEnv ( 'MAGENTO_ADMIN_PASSWORD' ) ;
12+ const magentoAdminUsername = requireEnv ( 'MAGENTO_ADMIN_USERNAME' ) ;
13+ const magentoAdminPassword = requireEnv ( 'MAGENTO_ADMIN_PASSWORD' ) ;
2414
25- const browserEngine = browserName ?. toUpperCase ( ) || "UNKNOWN" ;
15+ base . describe ( 'Setting up the testing environment' , ( ) => {
16+ base ( 'Enable_multiple_admin_logins' , { tag : '@setup' } , async ( { page, browserName } , testInfo ) => {
17+ const browserEngine = browserName ?. toUpperCase ( ) || "UNKNOWN" ;
2618
27- if ( browserEngine === "CHROMIUM" ) {
28- const magentoAdminPage = new MagentoAdminPage ( page ) ;
29- await magentoAdminPage . login ( magentoAdminUsername , magentoAdminPassword ) ;
30- await magentoAdminPage . enableMultipleAdminLogins ( ) ;
31- } else {
32- testInfo . skip ( true , `Skipping because configuration is only needed once.` ) ;
33- }
34- } ) ;
19+ if ( browserEngine === "CHROMIUM" ) {
20+ const magentoAdminPage = new MagentoAdminPage ( page ) ;
21+ await magentoAdminPage . login ( magentoAdminUsername , magentoAdminPassword ) ;
22+ await magentoAdminPage . enableMultipleAdminLogins ( ) ;
23+ } else {
24+ testInfo . skip ( true , `Skipping because configuration is only needed once.` ) ;
25+ }
26+ } ) ;
3527
36- base ( 'Disable_login_captcha' , { tag : '@setup' } , async ( { page, browserName } , testInfo ) => {
37- const magentoAdminUsername = requireEnv ( 'MAGENTO_ADMIN_USERNAME' ) ;
38- const magentoAdminPassword = requireEnv ( 'MAGENTO_ADMIN_PASSWORD' ) ;
28+ base ( 'Disable_login_captcha' , { tag : '@setup' } , async ( { page, browserName } , testInfo ) => {
29+ const browserEngine = browserName ?. toUpperCase ( ) || "UNKNOWN" ;
3930
40- const browserEngine = browserName ?. toUpperCase ( ) || "UNKNOWN" ;
31+ if ( browserEngine === "CHROMIUM" ) {
32+ const magentoAdminPage = new MagentoAdminPage ( page ) ;
33+ await magentoAdminPage . login ( magentoAdminUsername , magentoAdminPassword ) ;
34+ await magentoAdminPage . disableLoginCaptcha ( ) ;
35+ } else {
36+ testInfo . skip ( true , `Skipping because configuration is only needed once.` ) ;
37+ }
38+ } ) ;
4139
42- if ( browserEngine === "CHROMIUM" ) {
43- const magentoAdminPage = new MagentoAdminPage ( page ) ;
44- await magentoAdminPage . login ( magentoAdminUsername , magentoAdminPassword ) ;
45- await magentoAdminPage . disableLoginCaptcha ( ) ;
46- } else {
47- testInfo . skip ( true , `Skipping because configuration is only needed once.` ) ;
48- }
40+ base ( 'Setup_environment_for_tests' , { tag : '@setup' } , async ( { page, browserName } , testInfo ) => {
41+ const browserEngine = browserName ?. toUpperCase ( ) || "UNKNOWN" ;
42+ const setupCompleteVar = `SETUP_COMPLETE_${ browserEngine } ` ;
43+ const isSetupComplete = process . env [ setupCompleteVar ] ;
44+
45+ if ( isSetupComplete === 'DONE' ) {
46+ testInfo . skip ( true , `Skipping because configuration is only needed once.` ) ;
47+ }
48+
49+ await base . step ( `Step 1: Perform actions` , async ( ) => {
50+ const magentoAdminPage = new MagentoAdminPage ( page ) ;
51+ await magentoAdminPage . login ( magentoAdminUsername , magentoAdminPassword ) ;
52+
53+ const couponCode = requireEnv ( `MAGENTO_COUPON_CODE_${ browserEngine } ` ) ;
54+ await magentoAdminPage . addCartPriceRule ( couponCode ) ;
55+
56+ const registerPage = new RegisterPage ( page ) ;
57+ const accountEmail = requireEnv ( `MAGENTO_EXISTING_ACCOUNT_EMAIL_${ browserEngine } ` ) ;
58+ const accountPassword = requireEnv ( 'MAGENTO_EXISTING_ACCOUNT_PASSWORD' ) ;
59+
60+ await registerPage . createNewAccount (
61+ inputValues . accountCreation . firstNameValue ,
62+ inputValues . accountCreation . lastNameValue ,
63+ accountEmail ,
64+ accountPassword ,
65+ true
66+ ) ;
4967 } ) ;
5068
51- base ( 'Setup_environment_for_tests' , { tag : '@setup' } , async ( { page, browserName } , testInfo ) => {
52- const browserEngine = browserName ?. toUpperCase ( ) || "UNKNOWN" ;
53- const setupCompleteVar = `SETUP_COMPLETE_${ browserEngine } ` ;
54- const isSetupComplete = process . env [ setupCompleteVar ] ;
55-
56- if ( isSetupComplete === 'DONE' ) {
57- testInfo . skip ( true , `Skipping because configuration is only needed once.` ) ;
69+ await base . step ( `Step 2: (optional) Update env file` , async ( ) => {
70+ console . log ( process . env . CI ) ;
71+ if ( process . env . CI === 'true' ) {
72+ console . log ( "Running in CI environment. Skipping .env update." ) ;
73+ base . skip ( ) ;
5874 }
5975
60- await base . step ( `Step 1: Perform actions` , async ( ) => {
61- const magentoAdminUsername = requireEnv ( 'MAGENTO_ADMIN_USERNAME' ) ;
62- const magentoAdminPassword = requireEnv ( 'MAGENTO_ADMIN_PASSWORD' ) ;
63-
64- const magentoAdminPage = new MagentoAdminPage ( page ) ;
65- await magentoAdminPage . login ( magentoAdminUsername , magentoAdminPassword ) ;
66-
67- const couponCode = requireEnv ( `MAGENTO_COUPON_CODE_${ browserEngine } ` ) ;
68- await magentoAdminPage . addCartPriceRule ( couponCode ) ;
69-
70- const registerPage = new RegisterPage ( page ) ;
71- const accountEmail = requireEnv ( `MAGENTO_EXISTING_ACCOUNT_EMAIL_${ browserEngine } ` ) ;
72- const accountPassword = requireEnv ( 'MAGENTO_EXISTING_ACCOUNT_PASSWORD' ) ;
73-
74- await registerPage . createNewAccount (
75- inputValues . accountCreation . firstNameValue ,
76- inputValues . accountCreation . lastNameValue ,
77- accountEmail ,
78- accountPassword ,
79- true
80- ) ;
81- } ) ;
82-
83- await base . step ( `Step 2: (optional) Update env file` , async ( ) => {
84- if ( process . env . CI === 'true' ) {
85- console . log ( "Running in CI environment. Skipping .env update." ) ;
86- base . skip ( ) ;
87- }
88-
89- const envPath = path . resolve ( __dirname , '../.env' ) ;
90- try {
91- if ( fs . existsSync ( envPath ) ) {
92- const envContent = fs . readFileSync ( envPath , 'utf-8' ) ;
93- if ( ! envContent . includes ( `SETUP_COMPLETE_${ browserEngine } ='DONE'` ) ) {
94- fs . appendFileSync ( envPath , `\nSETUP_COMPLETE_${ browserEngine } ='DONE'` ) ;
95- console . log ( `Environment setup completed. Added SETUP_COMPLETE_${ browserEngine } ='DONE' to .env` ) ;
96- }
97- } else {
98- throw new Error ( '.env file not found. Please ensure it exists in the root directory.' ) ;
76+ const envPath = path . resolve ( __dirname , '../.env' ) ;
77+ try {
78+ if ( fs . existsSync ( envPath ) ) {
79+ const envContent = fs . readFileSync ( envPath , 'utf-8' ) ;
80+ if ( ! envContent . includes ( `SETUP_COMPLETE_${ browserEngine } ='DONE'` ) ) {
81+ fs . appendFileSync ( envPath , `\nSETUP_COMPLETE_${ browserEngine } ='DONE'` ) ;
82+ console . log ( `Environment setup completed. Added SETUP_COMPLETE_${ browserEngine } ='DONE' to .env` ) ;
9983 }
100- } catch ( error ) {
101- const err = error as Error ;
102- throw new Error ( `Failed to update .env file: ${ err . message } ` ) ;
84+ } else {
85+ throw new Error ( '.env file not found. Please ensure it exists in the root directory.' ) ;
10386 }
104- } ) ;
87+ } catch ( error ) {
88+ const err = error as Error ;
89+ throw new Error ( `Failed to update .env file: ${ err . message } ` ) ;
90+ }
10591 } ) ;
10692 } ) ;
107- } ;
108-
109- if ( process . env . CI ) {
110- runSetupTests ( base . describe ) ;
111- } else if ( toggles . general . setup ) {
112- runSetupTests ( base . describe . only ) ;
113- }
93+ } ) ;
0 commit comments