0

I am running a store() method in which I have to create a project using playwright tests. My playwright index.spec.ts file where I am calling create project is:

import { test } from '@playwright/test';
import { createProject } from './actions/create';
test.describe.serial('Project Module', () => {
     let createdProjectId: string | null = null;
test('Create Project', async ({ page }) => {
        test.setTimeout(60000);
        process.env.RUNNING_AUTOMATION_TESTS = 'true';
        console.log('RUNNING_AUTOMATION_TESTS set to ',process.env.RUNNING_AUTOMATION_TESTS);
        createdProjectId = await createProject(page);
        process.env.RUNNING_AUTOMATION_TESTS = 'false';
        console.log('RUNNING_AUTOMATION_TESTS set to',process.env.RUNNING_AUTOMATION_TESTS);
    });
});

My controller method where i want the RUNNING_AUTOMATION_TESTS = 'true'; is

if (!config('general.running_automation_tests')) {
            $customDomain = $this->cloudflareCustomDomainService->createCustomDomain($input['domain_url'] ?? '');

            if (isset($customDomain['error']))
                return redirect()->back()->withInput($request->all())->with('custom_domain_error', $customDomain['error']);
            else
                $input['custom_domain_result'] = $customDomain;
        }

But each time i get false getting in test failure. How to fix this issue?

3
  • Do you mean you want to dynamically change your env based from the request? Commented Oct 28 at 5:35
  • yes dynamically Commented Oct 29 at 12:13
  • Does your createProject send RUNNING_AUTOMATION_TESTS in the request payload? Commented Oct 30 at 4:38

1 Answer 1

0

Assuming that you want to change the backend side (laravel)'s ENV, you save it as a variable and reasssign from your request.

public function createProject(Request $request)
{
    $automation_test = config('general.running_automation_tests');

    if ($request->has('running_automation_tests')) {
        $automation_test = $request->running_automation_tests;
    }

    .... your normal process


    if (!$automation_test) {
        $customDomain = $this->cloudflareCustomDomainService->createCustomDomain($input['domain_url'] ?? '');

        if (isset($customDomain['error'])) {
            return redirect()->back()->withInput($request->all())->with('custom_domain_error', $customDomain['error']);
        else {
            $input['custom_domain_result'] = $customDomain;
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.