Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

338
Views
How to import file from general path in cypress?

I have a file called 'contents' in cypress. in my test file I want to import this file.

I do the following :

import contents from 'C:/Users/asus/cypress/support/contents';

But I want to make it more general path (not contain my own path). I tried to import it inside the index file in cypress.

As follow:

import './contents'

But it is not working by this way. Cypress will throw an error that contents is not defined.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Not knowing the data type and assuming that the exact location of the file doesn't matter, I would recommend moving the file to the /fixtures folder and importing it as recommended in the Cypress docs here. So you can use a relative path for the import in your test like:

import contents from '../fixtures/contents';

You can also find an example for importing a JSON file in this answer.

about 4 years ago · Juan Pablo Isaza Report

0

First, you have to export that file

const contents = {
    // Your data
}
export { contents };

You can import files like this way

import { contents } from '../support/contents.js'

If ../support/contents.js is not working Please use ../../ to get the root directory of your system like ../../support/contents.js. Please replace your file extension with .js.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!