DevExpress / testcafe-browser-provider-electron

This is the Electron browser provider plugin for TestCafe.
https://testcafe.io
MIT License
49 stars 30 forks source link

Mocking HTTP Request not working in Electron App #78

Closed ynnelson closed 3 years ago

ynnelson commented 3 years ago

I am having issues when trying to Mock HTTP Request in my Electron App using TestCafe

I placed a console log in a mock request to see all the calls that were coming through but none of my http requests originated from my React Component or the main process came through.

const mock = RequestMock()
  .onRequestTo(request => {
    console.log('REQUEST', request); // The full request object

    return request.url.indexOf('/account/beta/verify') > -1; // Here you can set your own rule
  })
  .respond((req, res) => {
    console.log('RESULTS', res);
    return res.setBody('<html><body><h1>OK</h1></body></html>');
  });

The only thing that came through were resources request like this one but none of the calls I make in my component using axios.

{
  requestId: '08iNSTIWG',
  userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.130 Electron/7.1.13 Safari/537.36',
  url: 'file:///Users/myprofile/myapp/app-desktop/app/dist/login.css',
  method: 'get',
  isAjax: false,
  headers: {
    host: '',
    connection: 'keep-alive',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.130 Electron/7.1.13 Safari/537.36',
    accept: 'text/css,*/*;q=0.1',
    referer: 'file:///Users/myprofile/myapp/app-desktop/app/login_window/index.html',
    'accept-encoding': 'gzip, deflate',
    'accept-language': 'en-US'
  },
  body: <Buffer >,
  sessionId: 'TLNqYvUeS'
}

Has anyone successfully setup a Mock Request using TestCafe in an Electron app? if so what am i missing?

here are some of the versions I am running, I can paste the whole file is useful.

"electron": "7.1.13",
"electron-builder": "^22.3.6",
"electron-devtools-installer": "^2.2.4",
"electron-rebuild": "^1.10.0"
"testcafe": "^1.8.0",
"testcafe-browser-provider-electron": "^0.0.14"
ynnelson commented 3 years ago

I should add that the window that is firing off those calls is a secondary window and not the main window. Not sure if it matters, need to further test to see if the multiple windows is the cause...any input would be appreciated.

ynnelson commented 3 years ago

test.zip

I tried to make a bare bones simple sample Electron app, but in this sample app I run up against CORS issue I am unsure how to resolve because I don't control the API server, I used https://jsonplaceholder.typicode.com/ for a dummy API. So I can't demonstrate the behavior I am seeing in my actual app.

Any guidance here would be helpful.

felis2803 commented 3 years ago

I didn't manage to reproduce the error you mentioned. Also, I could not install the application you sent. When trying to install the dependencies, I got an error: изображение

Could you please describe the steps I need to follow to install and run your example so that I can get to the error you mentioned?

no-response[bot] commented 3 years ago

This issue was automatically closed because there was no response to our request for more information from the original author. Currently, we don't have enough information to take action. Please reach out to us if you find the necessary information and are able to share it. We are also eager to know if you resolved the issue on your own and can share your findings with everyone.