question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prevent/Stub network request

See original GitHub issue

Current behavior:

I’ve in my application several <script>...</script> like pulling in jQuery and also a few internal things. Cypress gets errors that it is not authorised to get certain things. Now this question would be answered (if authorised or not) by an external js file. But this fails, as the “cypress user” is unknown.

Desired behavior:

A way of either overriding or mocking this <script>...</script>-tag to be able to influence the response.

  • Operating System: Mac OS High Sierra
  • Cypress Version: 2.0.3
  • Browser Version: electron

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
brian-manncommented, Feb 23, 2018

This feature is part of part of our large rewrite of the network layer that’s actively being worked on - and you’ll be able to fully stub all network requests including ones for script tags. Read this issue: https://github.com/cypress-io/cypress/issues/687

For today - you could either blacklist these requests, or you could use some combination of document.currentScript to get access to the <script> and then swap its src attribute to something you control.

You have native access to everything in Cypress - and you can use that to alter your scripts before they are fetched.

1reaction
benpolinskycommented, Feb 23, 2018

Similar situation, I think:

I ended up blacklisting the host in my cypress.json, and then mocking it during the window:before:load event inside of a beforeEach method.

Edit: although your local scripts may not work with this solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Network Requests - Cypress Documentation
With Cypress, you can stub network requests and have it respond instantly ... This prevents the next commands from running until responses come...
Read more >
Recommended Way to Stub Out Network Requests When UI ...
As the title suggests, what is Apple's recommended approach to stubbing out network requests when doing UI tests? Making real network requests in...
Read more >
How to stub network requests on UITesting - Stack Overflow
You'll have to stub the NSURLSession to inject the response you want, and use some launch arguments to identify when to use the...
Read more >
How to Stub External Services in Tests - Thoughtbot
Another approach for preventing external requests is to record a live interaction and 'replay' it back during tests. The VCR gem has a...
Read more >
Network Stubbing options for XCTest and XCUITest in Swift
We can still use those libraries to stub out the network requests but ... so that we don't need to explicitly start or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found