Skip to content
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

websocket testing #26190

Closed
ivanhara opened this issue Mar 23, 2023 · 4 comments
Closed

websocket testing #26190

ivanhara opened this issue Mar 23, 2023 · 4 comments
Assignees

Comments

@ivanhara
Copy link

ivanhara commented Mar 23, 2023

Current behavior

cypress is not working with websocket
image

Desired behavior

cypress to work with that or update your documentation here
https://docs.cypress.io/faq/questions/general-questions-faq#We-use-WebSockets-will-Cypress-work-with-that

Test code to reproduce

  it('websocket test', () => {
    cy.intercept({ resourceType: /websocket/ }).as('ws')
    cy.visit('https://www.twitch.tv/')
    cy.wait('@ws')

  });

Cypress Version

12.8.1

Node version

v16.15.1

Operating System

Windows 10 Pro Version 10.0.19044 Build 19044

Debug Logs

No response

Other

No response

@lmiller1990
Copy link
Contributor

Hi. My understanding of that part of the docs is that you can use Cypress to test applications using websockets in a seamless manner. When testing applications using websockets, the general strategy is either test against the result of the websocket call (eg, did something change on the page) or if you need fine grained control, either

  1. set up your database/application in the way you want and test against that or
  2. set up a websocket server and use something like cy.task to push events to manipulate what it does (this will make your test more deterministic)
  3. stub/mock the window.WebSocket constructor's onmessage to stream whatever you like over it.

In general, Cypress assumes you control the application you are testing. If you can explain your use case, I can make some recommendations.

I will double check if this should be working, but my understand is it you won't be able to listen in for the websocket stream using cy.intercept(). The documentation for cy.intercept() doesn't make this clear, though, so let me clarify. Related: #2492

@ivanhar
Copy link

ivanhar commented Mar 25, 2023

image
i will use https://websocketstest.com/ as an example.
I need to verify there are messages send/received from this 3rd party server, containing the word 'time'
I don't have to mock the server, I don't need to connect explicitly via Cypress. Only check the messages.

@lmiller1990
Copy link
Contributor

I don't think we support intercepting ws yet - just http requests.

I don't have to mock the server, I don't need to connect explicitly via Cypress. Only check the messages

If you just need to watch a third party web socket, and not make any assertions against the actual page or even use a web browser, perhaps a simple script using something like Node.js or Python would be a better option?

We generally don't recommending testing third parties, unless the behavior is essential to your app, in which case we'd generally recommend asserting the impact of the web socket on your page.

@lmiller1990 lmiller1990 assigned astone123 and unassigned lmiller1990 Mar 28, 2023
@astone123
Copy link
Contributor

Unfortunately we have to close this issue due to inactivity. Please comment if there is new information to provide concerning the original issue and we can reopen.

@astone123 astone123 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants