Skip to content

Commit e9e55c9

Browse files
committed
Add throttle_response command for helping on sporadic failures
1 parent 454d6bb commit e9e55c9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Usage: cy.throttle_response(1000, 56);
2+
Cypress.Commands.add('throttle_response', (response_delay, throttle_kbps) => {
3+
cy.intercept(
4+
{
5+
url: 'http://localhost:3000/**',
6+
middleware: true,
7+
},
8+
(req) => {
9+
req.on('response', (res) => {
10+
// Add response delay and throttle network to simulate slower networks
11+
res.setDelay(response_delay).setThrottle(throttle_kbps)
12+
})
13+
}
14+
)
15+
});
16+

cypress/support/e2e.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import './commands/gtl.js'
4545
import './commands/login.js'
4646
import './commands/menu.js'
4747
import './commands/toolbar.js'
48+
import './commands/throttle_response.js'
4849

4950
// Assertions
5051
import './assertions/expect_rates_table.js';
@@ -65,3 +66,8 @@ Cypress.on('uncaught:exception', (err, runnable) => {
6566
return false;
6667
}
6768
});
69+
70+
beforeEach(() => {
71+
// Global hook run once before each test
72+
// cy.throttle_response(500, 56);
73+
})

0 commit comments

Comments
 (0)