-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have a way to visit a local HTML file without prepending the baseUrl
#4450
Comments
You can visit a file by specifying the relative path to cy.visit('./test.html') |
When I run cy.visit('./cypress/screenshots/screenshot.html') I was expecting file://./cypress/screenshots/screenshot.html Using cypress 3.6.0 |
What's the status of this request? A response has been given that does not answer the original question. Other users have commented about the same issue:
|
baseUrl
This issue is still in the 'proposal' stage, which means no work has been done on this issue as of today, so we do not have an estimate on when this will be delivered. |
@jennifer-shehane could you clarify if visiting file relative to project root is possible or not? |
@levenleven It is possible and does work if you do not have a |
Reopening as this is still an existing issue that needs addressing. If you'd like to no longer be notified in this thread, please Unsubscribe from notifications on the right side of this issue. |
Sorry, this is actually a duplicate of #2918 😝 Forgive my comment spamming. |
The Cypress
However, what it means is: if When it says "you may also specify the relative path of an html file" it means: If This documentation is extremely unclear and leads easily to frustration if you assume that Cypress would give you some way to prevent having the It'd be an even "better" practice to never set And of course, as other users have pointed out (#2918), you can't unset the |
@wmadden the way you visit a local file when it('visits base url', () => {
cy.visit('/')
cy.contains('h1', 'Kitchen Sink')
})
it('visits local file', {baseUrl: null}, () => {
cy.visit('index.html')
cy.contains('local file')
}) PS: I would put tests that use different |
This makes using a local file pretty tedious if using You can work around it by doing something like this: // cypress.config.ts
import { defineConfig } from 'cypress';
export default defineConfig({
env: {
indexUrl: './src/pages/index-dev.html',
},
e2e: {
// due to some quirky behaviour in how Cypress handles the baseUrl environment variable
// we use a work around, check the base-page.ts file
baseUrl: null,
},
}); Then, instead of calling abstract class BasePage {
open() {
cy.visit(Cypress.env('indexUrl'));
return this;
}
}
export { BasePage }; A little janky but captures the essence of what baseUrl is supposed to do if working with local files and I can specify it on the command line to differentiate environments/CI/etc:
|
Current behavior:
If I want to open a local file for test, like:
cy.visit('file:///Users/jasonzhang/Desktop/test.html')
I got an error:
CypressError: cy.visit() failed trying to load:
file:///Users/jasonzhang/Desktop/test.html
We attempted to make an http request to this URL but the request failed without a response.
We received this error at the network level:
Desired behavior:
Support it.
Versions
3.3.1
The text was updated successfully, but these errors were encountered: