与webdriver和黄瓜Stubbing API

时间:2017-11-30 13:30:58

标签: javascript selenium-webdriver webdriver cucumber

我想使用配置了Cucumber的Webdriver对我的应用程序运行一些BDD测试,但是想要将我的API存根。我最好不要使用Express,因为我希望我的CI服务器执行这些测试,而Express会增加复杂性。

我无法在线找到有关从wdio向浏览器上下文中注入nockfetch-mock的任何指南。我想在每个场景之前设置我的存根调用,然后在场景之后进行清理。

以下是我wdio.conf.js的相关位。显然它不会像书面那样工作,但我希望说明我想做什么。如果有人提出有用的建议偏离这个方向,我仍然喜欢听到它。

/**
 * Gets executed before test execution begins. At this point you can access to all global
 * variables like `browser`. It is the perfect place to define custom commands.
 * @param {Array.<Object>} capabilities list of capabilities details
 * @param {Array.<String>} specs List of spec file paths that are to be run
 */
before: function (capabilities, specs) {
    fetchMock = require('fetch-mock');

    browser.execute(() => { 
       injectFetchMockSomehow(fetchMock);
    }, fetchMock); 
},

/**
 * Runs before a Cucumber scenario
 * @param {Object} scenario scenario details
 */
beforeScenario: function (scenario) {
    fetchMock.get('/foo', {hello: 'world'});
},

/**
 * Runs after a Cucumber scenario
 * @param {Object} scenario scenario details
 */
afterScenario: function (scenario) {
    fetchMock.reset()
    fetchMock.restore();
},

0 个答案:

没有答案