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

mockRequest with Puppeteer is not intercepting HTTP requests #2845

Closed
sunny-goel opened this issue Mar 23, 2021 · 1 comment
Closed

mockRequest with Puppeteer is not intercepting HTTP requests #2845

sunny-goel opened this issue Mar 23, 2021 · 1 comment

Comments

@sunny-goel
Copy link

sunny-goel commented Mar 23, 2021

What are you trying to achieve?

I am using I.mockRequest with puppeteer.
Post authenticating the user, Application requests some data from the backend by requesting HTTPS GET request to this endpoint: /api/v1/b2c/zones?limit=9007199254740991.
After start mocking, this API request should be intercepted and custom response should be returned according to my settings:

I.amOnPage('/');
I.click('Log In');
I.fillField('email', '[email protected]');
I.fillField('password', secret('****'));
I.click('Log In');
I.mockRequest('GET', '/api/v1/b2c/zones?limit=9007199254740991', 200, { "data": []});
I.see('List currently active routes')
I.pause();

What do you get instead?

I always get response from the server and my custom response is never gets dispatched .
I have tried putting before and after I.click('Log In'); statement but no change in behaviour.

Details

  • CodeceptJS version: ^3.0.5
  • NodeJS Version: v15.4.0
  • Operating System: mac
  • puppeteer : ^8.0.0
  • Configuration file:
exports.config = {
  tests: './*_test.js',
  output: './output',
  helpers: {
    Puppeteer: {
      url: 'XXXX',
      show: true,
      chrome: {
        args: [
          '--disable-web-security',
        ],
      },
      waitForNavigation: "networkidle0",
      windowSize: '1200x900'
    },
    MockRequestHelper: {
      require: '@codeceptjs/mock-request'
    }
  },
  include: {
    I: './steps_file.js'
  },
  bootstrap: null,
  mocha: {},
  name: 'Puppeteer',
  plugins: {
    pauseOnFail: {},
    retryFailedStep: {
      enabled: true
    },
    tryTo: {
      enabled: true
    },
    screenshotOnFail: {
      enabled: true
    }
  }
}

package.json

{
  "dependencies": {},
  "resolutions": {
    "@pollyjs/adapter-puppeteer": "^5.1.0",
    "@pollyjs/core": "^5.1.0"
  },
  "devDependencies": {
    "@codeceptjs/mock-request": "^0.3.0",
    "@pollyjs/adapter-fetch": "^5.1.0",
    "@pollyjs/adapter-puppeteer": "^5.1.0",
    "@pollyjs/adapter-xhr": "^5.1.0",
    "@pollyjs/core": "^5.1.0",
    "@pollyjs/persister-rest": "^5.0.0",
    "codeceptjs": "^3.0.5",
    "puppeteer": "^8.0.0"
  }
}
@kobenguyent
Copy link
Collaborator

should be fixed by #4262

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

2 participants