.network.mockResponse() 建議編輯
自: 2.2.0攔截在特定 URL 上發出的請求並模擬回應。
使用方式
.mockNetworkResponse(urlToIntercept, {status, headers, body}, [callback])
.network.mockResponse(urlToIntercept, {status, headers, body}, [callback])
範例
describe('mock network response', function() {
it('intercepts the request made to Google search and mocks its response', function() {
browser
.network.mockResponse('https://www.google.com/', {
status: 200,
headers: {
'Content-Type': 'UTF-8'
},
body: 'Hello there!'
})
.navigateTo('https://www.google.com/')
.pause(2000);
});
});
參數
名稱 | 類型 | 描述 |
---|---|---|
urlToIntercept |
字串 | 要攔截並模擬回應的 URL。 |
response |
物件 | 要返回的回應。預設值: |
callback 選用 |
函式 | 指令完成時要呼叫的回呼函式。 |