rhythmic-dress-50185
09/25/2021, 5:02 PMdescribe('My First Test', () => {
it('Visits the app root url', () => {
cy.visit('/')
cy.contains('h1', 'Welcome to Your Vue.js App')
})
})
It works great when ran in the UI, but when ran with npx cypress run --headless
, the pass fails with a "404 not found" on the /
path.
I'm running in headless because eventually I would like to run this in CI/CD, and I assume (maybe wrongly) that this is how that will happen, so I just wanted to see that work.wonderful-match-15836
09/25/2021, 6:00 PM/
is relative to the baseUrl
is set to in your cypress.json
file. So I'd check if that is set and looks correct there (it probably should be http://localhost:8080
but I think it's not added by default). And make sure the app is running. Open vs Run mode should not make a difference for cy.visit behavior as far as I know.rhythmic-dress-50185
09/25/2021, 7:44 PM"baseUrl": "http://localhost:8080",
"port": 8080
"chromeWebSecurity": false
rhythmic-dress-50185
09/25/2021, 7:51 PMrhythmic-dress-50185
09/25/2021, 7:55 PMwonderful-match-15836
09/25/2021, 9:06 PMport
key in your cypress.json does not need to be set for this. Your baseUrl contains the port that your app is running on. This other port
key itself is identifying the port that Cypress runs on (I'm looking here for the info on the config options: https://docs.cypress.io/guides/references/configuration#Global). I've ever manually put a port in there so not sure what the effect is. I'd suggest just removing it, did the baseUrl alone not work?wonderful-match-15836
09/25/2021, 9:22 PMchromeWebSecurity: false
.
When I remove the port, everything is good again and my test can visit the app just fine. (I'm also in a recently-scaffolded Vue 3 app)rhythmic-dress-50185
09/25/2021, 9:50 PMrhythmic-dress-50185
09/25/2021, 10:11 PMstartDevServer
), and that I didn't have to have it running myself...wonderful-match-15836
09/25/2021, 10:46 PMcy.visit
and test things, so in theory you can point to an externally deployed instance of your app, or even production, and make all the same actions/assertions.
In E2E Cypress doesn't know or care anything about how your app is built or served, it just works with whatever it finds at the page you tell it to visit. Same thing in CI, you'll need to build and serve the app, then have cypress visit it once it is running. There are specific guides/examples for most CI providers you might be using.
Component testing is a different story though. In a component test, Cypress is serving up an empty web page for you and mounting an individual component there. So that's where that startDevServer stuff comes in -- Cypress isn't running your whole app, but it does need to get set up to mount your components and configure webpack correctly. It's explained a little here: https://docs.cypress.io/guides/component-testing/framework-configuration#Vue-2-Vue-CLIrhythmic-dress-50185
09/25/2021, 11:05 PMrhythmic-dress-50185
09/25/2021, 11:05 PMrhythmic-dress-50185
09/25/2021, 11:06 PMwonderful-match-15836
09/25/2021, 11:22 PMrhythmic-dress-50185
09/25/2021, 11:44 PM