我们如何在
multiple
BDD 框架中与 cypress-cucumber-preprocessor
用户运行并行 cypress 测试。我无法在并行运行中使用单用户,因为最新的会话将kicked out
现有的 cypress 测试运行和现有的测试运行将失败。
请注意:在我们的网络应用程序中,如果用户访问系统并登录网络应用程序并执行某些操作。同时在不同的浏览器中访问系统并使用同一用户登录。第一个会话将被注销。
我们正在使用
如果您碰巧遇到类似情况,请有人指教
自动化文件夹结构:
tests/
cypress/
integration
/folder1/
test1.feature
/folder2/
test2.feature
test3.feature
/folder3/
test4.feature
/folder4/
test5.feature
/folder5/
test6.feature
/folder6/
test7.feature
如果您只需要多个用户,但测试是完全独立的,您可以在一个装置中拥有多个用户凭据,
例如
// users.json
[
{
userId: 1,
username: 'John',
password: 'abc'
},
{
userId: 2,
username: 'Jack',
password: 'def'
},
... // and so on
]
每个测试一开始都会选择不同的用户
// test1
import { Given } from "@badeball/cypress-cucumber-preprocessor";
Given('User has logged in with unique credentials', () => {
before(() => {
cy.fixture('users.json').then(users => {
const user = users[0]
cy.login(user.username, user.password)
})
})
// test2
import { Given } from "@badeball/cypress-cucumber-preprocessor";
Given('User has logged in with unique credentials', () => {
before(() => {
cy.fixture('users.json').then(users => {
const user = users[1]
cy.login(user.username, user.password)
})
})
如果并行运行时测试重叠,服务器会看到不同的用户登录。
或者使用黄瓜
Before
钩子
import { Before } from "@badeball/cypress-cucumber-preprocessor";
Before(function () {
cy.fixture('users.json').then(users => {
const user = users[0]
cy.login(user.username, user.password)});
})
})
您可以让每个测试创建一个具有适当权限的新用户,并使用 API 运行以加快执行速度。您可能需要一个单独的清理过程来删除所有创建的用户。这样做的好处是每次测试都能真正拥有干净的状态,而不必担心用户帐户。
Cypress:是否有一种方法可以访问测试中当前的并行运行实例,以便为每个线程或实例使用不同的用户登录?