小能豆

Can I host Cypress to a server?

javascript

So we’re using Cypress + Cucumber to perform E2E UI tests. Everything is running fine, whenever I trigger the script, it shows the cypress pop-up, and I trigger a few tasks manually. Now we want our QA person to use the same prompt to test a few specific scenarios as they will. I know one way to trigger the test is during the CI/CD pipeline, but I was wondering if there’s a way to host the app on some server, and a QA person can trigger a particular flow whenever they want.

So far I found cypress run –browser chrome –headed –no-exit –port 9000 command to keep the server active and run the tests when you click on it. But when I copy the URL and open it in another browser, I see an error saying that it can’t run the test because the browser was not opened by cypress.

Please let me know if there’s a way to achieve it.


阅读 66

收藏
2023-11-30

共1个答案

小能豆

The error you’re encountering is expected behavior from Cypress, as it prevents running tests in a browser instance that was not opened by Cypress itself. This is a security feature.

However, you can use a workaround to achieve something similar to what you’re looking for. You can run Cypress in “headed” mode and allow remote connections. Here’s an example:

  1. Start the Cypress Test Runner:
npx cypress open --port 9000 --config baseUrl=http://localhost:9000
  1. Make sure your application is hosted on a server, and in this example, I’m assuming it’s hosted on http://localhost:9000.
  2. Your QA person can then access Cypress remotely by visiting http://<YOUR_IP>:9000 from their browser.

Make sure to replace <YOUR_IP> with the actual IP address of the machine running the Cypress instance. Note that this solution assumes that the QA person has access to the machine running the Cypress tests.

Keep in mind that this method might not provide the exact level of separation you desire since the browser has to be opened by Cypress. For more advanced usage, you might need to consider using a CI/CD pipeline to trigger your tests or looking into cloud-based testing services that offer similar functionalities.

2023-11-30