You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having a similar issue to #106. Our test suite uses the ws package to spin up a web socket server which our AUT connects to when under test.
Everything works fine locally, and I have followed the advice on that thread, but still get the following error inside BrowserStack logs:
ERROR: WebSocket connection to 'wss://bs-local.com:12516/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
ERROR: CloseEvent
Here is the web socket and server implementation:
import{Page}from'@playwright/test';importfsfrom'fs';importhttpsfrom'https';import{Mockmock}from'mockmock';importWebSocket,{WebSocketServer}from'ws';import{ClientData}from'../test-data';import{isBrowserStack}from'./browserstack';constMM=Mockmock.instance;/** * Sets up a dummy WebSocket server that responds with web socket data */constsetUpWebSocketServer=(port: number,socketId: string)=>{constserver=https.createServer({cert: fs.readFileSync('playwright/support/certs/cert.pem'),key: fs.readFileSync('playwright/support/certs/key.pem'),});server.listen(port,()=>{console.log(`HTTPS server listening on port ${port}`);});constwss=newWebSocketServer({ server,verifyClient: ()=>true});// replays mocked data every 250mswss.on('connection',(ws: WebSocket)=>{// recursively replays mocked data until we run out of msgsconstrecursivelySendData=()=>{constframe=MM.replay(socketId,'data');if(typeofframe==='undefined'){return;}ws.send(JSON.stringify(frame.mock));setTimeout(recursivelySendData,250);};recursivelySendData();ws.on('error',(err)=>{console.error(`Connetion error: ${err.message} with name ${err.name}:${err.stack}`);});});};/** * Here we link PlayWright logic and MockMock by intercepting all WebSocket requests. * This is called by the setUp() method. * * @param page the page instance * @param port defaults to 3030 * @param url defaults to appropriate environment websocket Url */exportconstinterceptWebSocketRequests=async(page: Page,port=3030,url=ClientData.websocketUrl)=>{constsocketId='wsData';consthost=isBrowserStack() ? 'bs-local.com' : 'localhost';constwssUrl=MM.isReplaying ? `wss://${host}:${port}` : url;// if Mockmock is recording sniff all websocket frames and save themif(MM.isRecording){page.on('websocket',(ws)=>{ws.on('framereceived',(data)=>{MM.record(socketId,JSON.parse(data.payload.toString()));});});}// if Mockmock replaying we set up a local webwocket server and route traffic to itif(MM.isReplaying){// intercept the payments form, replace the wss url, and relax CS policiesawaitpage.route(`${ClientData.paymentsUrl}/**`,async(route)=>{console.log(`Intercepted payments URL request to ${route.request().url()}`);constresponse=awaitroute.fetch();constframeHtml=awaitresponse.text();constbody=frameHtml.replace(ClientData.websocketUrl,wssUrl);constheaders=response.headers();constcsp=headers['content-security-policy'];// make csp more permissiveheaders['content-security-policy']=csp.replace("connect-src 'self'","connect-src 'self' localhost:* wss://localhost:* bs-local.com:* wss://bs-local.com:*");console.log(`Fulfilling with wss url: ${wssUrl} edited body has wss url: ${body.includes(wssUrl)} headers: ${JSON.stringify(headers)} `);awaitroute.fulfill({ response, body, headers });});setUpWebSocketServer(port,socketId);}};
Expected Behavior
The AUT, when it submits the payment form, should connect to the local secure web socket server and work the same way it does when running the tests locally.
Actual Behavior
The web socket server errors when a connection attempt is made.
ERROR: WebSocket connection to 'wss://bs-local.com:46300/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
ERROR: CloseEvent
Steps to Reproduce the Problem
Create a test file that acts as an AUT that connects to the secure web socket server - I can't share our application code as it's IP, but that part shouldn't be too hard.
Write a test that triggers the AUT connecting to your ws secure web socket server.
Platform details
playwright version: 1.33.0
node version: 18.9.1
os type and version: Ubuuntu 22.04.2 LTS
The text was updated successfully, but these errors were encountered:
Details
There is no documented
wsLocalSuport
capability on the PlayWright page: https://www.browserstack.com/docs/automate/playwright/playwright-capabilitiesI am having a similar issue to #106. Our test suite uses the
ws
package to spin up a web socket server which our AUT connects to when under test.Everything works fine locally, and I have followed the advice on that thread, but still get the following error inside BrowserStack logs:
Here is the web socket and server implementation:
Expected Behavior
The AUT, when it submits the payment form, should connect to the local secure web socket server and work the same way it does when running the tests locally.
Actual Behavior
The web socket server errors when a connection attempt is made.
Steps to Reproduce the Problem
Create a test file that acts as an AUT that connects to the secure web socket server - I can't share our application code as it's IP, but that part shouldn't be too hard.
Write a test that triggers the AUT connecting to your ws secure web socket server.
Platform details
The text was updated successfully, but these errors were encountered: