Mock data not getting injected in Testcafe requestMock
const myMock = RequestMock() .onRequestTo(async (request) => { if (request.url.match(constants.catalogCall)) { console.log(request.url); } return ( request.url.match(mockData) && request.headers[‘Origin’] === ‘http://localhost:1337’ && request.headers[‘Host’] === ‘localhost:1338’ ); }) .respond(myMock, 200, { ‘access-control-allow-origin’: ‘http://localhost:1337’, ‘access-control-allow-methods’: ‘GET,POST,PUT,HEAD,DELETE,CONNECT,OPTIONS,TRACE,PATCH’, ‘access-control-allow-headers’: ‘X-Urbn-Auth-Required,X-Urbn-Auth-Token,Authorization,X-Urbn-Captcha-Token,X-Urbn-Channel,X-Urbn-Client-Id,X-Urbn-Country,X-Urbn-Currency,X-Urbn-Device-Id,X-Urbn-Device-Type,X-Urbn-Direct-STS-Inventory-Source,X-Urbn-Error,X-Urbn-Geo-Region,X-Urbn-Include-Realtime-Inventory,X-Urbn-ISPU-Inventory-Source,X-Urbn-Language,X-Urbn-Mobile-Referer,X-Urbn-Pool,X-Urbn-Remote-IP,X-Urbn-Site-Id,X-Urbn-Time,Trace-Id,X-Urbn-Web-Referer,X-Akamai-Edgescape,content-length,content-type,X-Forwarded-For,Referer,True-Client-Ip,User-Agent,DNT,X-Requested-With,If-Modified-Since,Cache-Control,Range,X-Urbn-Primary-Data-Center-Id,X-Urbn-Experience,X-Urbn-Retry-Attempt’, ‘access-control-expose-headers’: ‘X-Urbn-Auth-Required,X-Urbn-Auth-Token,Authorization,X-Urbn-Captcha-Token,X-Urbn-Channel,X-Urbn-Client-Id,X-Urbn-Country,X-Urbn-Currency,X-Urbn-Device-Id,X-Urbn-Device-Type,X-Urbn-Direct-STS-Inventory-Source,X-Urbn-Error,X-Urbn-Geo-Region,X-Urbn-Include-Realtime-Inventory,X-Urbn-ISPU-Inventory-Source,X-Urbn-Language,X-Urbn-Mobile-Referer,X-Urbn-Pool,X-Urbn-Remote-IP,X-Urbn-Site-Id,X-Urbn-Time,Trace-Id,X-Urbn-Web-Referer,X-Akamai-Edgescape,content-length,content-type,X-Forwarded-For,Referer,True-Client-Ip,User-Agent,DNT,X-Requested-With,If-Modified-Since,Cache-Control,Range,X-Urbn-Primary-Data-Center-Id,X-Urbn-Experience,X-Urbn-Retry-Attempt,X-Urbn-Scopes,X-Urbn-Accepted-Scopes’, });
Mock data to get injected for the testcase while running test cafe automation
Initially got CORS error (Access to XMLHttpRequest at 'http://localhost:1338/0fYTtAIl5*Q4cCpktnt!a!0!s*staging3.xxx.com' from origin 'http://localhost:1337' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.). I have added the request.headers['Origin'] === 'http://localhost:1337'. still the mock data is not getting injected while running test cafe test
Tara Regmi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.