并行运行测试会失败

时间:2018-09-04 07:24:35

标签: cucumber webdriver-io

当我并行运行要素时(通过将maxInstances中的2设置为wdio.conf.js),它们每隔一次就会失败,但是当maxInstances1时,一切正常。当这两个测试并行运行时,似乎以某种方式使用了彼此的会话。知道会是什么吗?

一件重要的事情。 Webdriver.io无法执行断言(因为它们是在不同的会话上进行的),因此对于失败的断言而言,堆栈跟踪非常简单。

wdio.conf.js

exports.config = {
  specs: [
    './features/*.feature'
  ],
  maxInstances: 2,
  services: ['selenium-standalone'],
  capabilities: [
    { browserName: 'chrome' }
  ],
  baseUrl: 'http://localhost:4000',
  framework: 'cucumber',
  reporters: ['spec'],
  cucumberOpts: {
    require: ['./features/steps.js'],
    strict: true
  }
};

login.feature

Feature: Login page
  Scenario: Click on the search link redirects the user
    Given the user is on the login route
    When the user clicks on the search link
    Then he sees the search route

search.feature

Feature: Search page
  Scenario: Click on the login link redirects the user
    Given the user is on the search route
    When the user clicks on the login link
    Then he sees the login route

steps.js

const { Given, When, Then, Before, After } = require('cucumber');
const { assert } = require('chai');

Given(/^the user is on the login route$/, () => browser.url('/login'));
When(/^the user clicks on the search link$/, () => browser.click('.search-link'));
Then(/^he sees the search route$/, () => assert.equal(browser.isExisting('.search-route'), true));

Given(/^the user is on the search route$/, () => browser.url('/search'));
When(/^the user clicks on the login link$/, () => browser.click('.login-link'));
Then(/^he sees the login route$/, () => assert.equal(browser.isExisting('.login-route'), true));

1 个答案:

答案 0 :(得分:2)

这是因为我试图使用browser-sync在应用程序中提供目录。当使用任何其他Web服务器为目录提供服务时,一切正常。据我了解,这是因为browser-sync在打开多个浏览器时会尝试同步网址。