123456789101112131415161718192021222324252627282930313233 |
- function plugin (wdInstance, requests) {
- if (typeof wdInstance.addCommand !== "function") {
- throw new Error("You can't use WebdriverAjaxStub with this version of WebdriverIO");
- }
-
- function stub({template, data}, done) {
- window.XMLHttpRequest = function () {
- this.open = function (method, url) {
- this.method = method;
- this.url = url;
- };
-
- this.send = function () {
- this.status = 200;
- this.readyState = 4;
- const response = this.url.includes(".njk") ? template : data;
- this.response = response;
- this.responseText = response;
- this.onreadystatechange();
- };
-
- return this;
- };
-
- done();
- }
-
- wdInstance.addCommand("setupStub", function() {
- return wdInstance.executeAsync(stub, requests);
- });
- }
-
- module.exports.init = plugin;
|