Skip to content

[🐛 Bug]: v9 browser.mock not returning mock response #13555

@SimonRazor

Description

@SimonRazor

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

latest

Node.js Version

20.11.1

Mode

WDIO Testrunner

Which capabilities are you using?

No response

What happened?

Using browser.mock in v9 doesn't appear to intercept the network request and therefore doesn't update the reponse. Reverting to version 8.32.3 works as expected

What is your expected behavior?

No response

How to reproduce the bug.

describe('Mocking the BBC Sports Page with JS Alert on failure', () => {
    it('should show an alert when navigating to the sports page fails', async () => {
      // Mock the request for the BBC Sports page
      const bbcSportsMock = await browser.mock('https://www.bbc.co.uk/sport', {
        method: 'get',
      });
  
      // Simulate a 500 Internal Server Error
      bbcSportsMock.respond({}, {
        statusCode: 500,
        headers: { 'Content-Type': 'text/html' }
      });
  
      // Navigate to the BBC Sports page
      await browser.url('https://www.bbc.co.uk/sport');
  
      // Inject JavaScript into the page to trigger an alert when there's an error
      await browser.execute(() => {
        // Check if the page failed to load properly (status 500)
        const errorStatus = 500; // Simulated error status
        if (errorStatus === 500) {
          alert('Page failed to load due to server error!');
        }
      });

      await browser.debug(); // should see the JS alert but don't
    });
  });

Relevant log output

N/A

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛help wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions