清除cookie或注销,以便下一个方案未登录

时间:2018-02-15 15:36:51

标签: javascript protractor cucumber

如何在测试后清除cookie,以便我运行的下一个测试尚未登录。我正在尝试测试登录,我正在尝试的解决方案不起作用。感觉这是黄瓜问题?

var myHooks = function () {
        // Synchronous
        this.Before(function (scenario) {
          this.count = 0;
          return this.driver.open();
        });

        // Asynchronous Callback
        this.Before(function (scenario, callback) {
          var world = this;
          tmp.dir({unsafeCleanup: true}, function(error, dir) {
            if (error) {
              callback(error);
            } else {
              world.tmpDir = dir;
              callback();
            }
          });
        });

        // Asynchronous Promise
        this.After(function (scenario) {
          // Assuming this.driver is a selenium webdriver
        return this.driver.close();
        });
      };

      module.exports = myHooks;

我还尝试更改配置文件并添加了shardTestFiles:true但没有运气。我可以在配置文件中添加什么,以便在每个黄瓜场景后重新启动浏览器?请注意,我在功能文件中添加了多个用于登录的示例

const crew = require('serenity-js/lib/stage_crew');

exports.config = {
  getPageTimeout: 30000,
  seleniumAddress: 'http://localhost:4444/wd/hub',
  baseUrl: 'https://abcccc.com/',
  specs: [ 'features/**/*.feature' ],
  shardTestFiles: true,
  multicapabilities: [{
    'browserName': 'chrome'
  /* }, {
    'browserName': 'firefox'
  }, {
    'browserName': 'internet explorer' */
  }],

  // maxSession: 2,

  framework: 'custom',

  frameworkPath: require.resolve('serenity-js'),

  serenity: {
    crew: [
      crew.serenityBDDReporter(),
      crew.photographer(),
      crew.consoleReporter()
    ]
  },

  cucumberOpts: {
    require: [ './features/step_definition/*.ts' ],
    format: [ "pretty" ],
    compiler: 'ts:ts-node/register'
  }
};

这是我的功能文件,看起来这可能是一个黄瓜问题?

Feature: Add item and place the order for that item
    In order to wear something new
    As an online shopping customer
    I want to be able to add an item to my shopping bag and then place the order

    Scenario Outline: Add an item to shopping bag to place the order using PaypalPro
        Given "<User>" is logged in to his "<EnvName>" account
         When he searches item with SKU "<SKUID>" from "<Gender>" section and adds it to his shopping bag
         Then "<User>" can place the order
    Examples:
        | User         | EnvName | SKUID        | Gender |
        | user1        | Test  | 51230M000010   | men    |
        | user2        | Test  | 51230M000010   | women  |

0 个答案:

没有答案