单击我们测试站点中的某个按钮后,系统应导航到 MYOB 登录页面。但是在无头模式下运行测试时,这不会发生并显示在页面下方(请参阅屏幕截图)。在测试运行器模式下,最初我看到此错误,但在添加--disable-features=SameSiteByDefaultCookies
index.js 后,测试成功导航到 MYOB 站点,我能够继续进行。知道为什么上述设置不适用于无头模式。
赛普拉斯版本:6.6.0 Git bash:2.28.0 操作系统:Windows 10 64 位操作系统 cypress-cucumber-preprocessor":2.5.5
从 Git bash 运行以下命令:
CYPRESS_baseUrl=https://some-test-url/book/ npx cypress-tags run -e TAGS='@experimental' --config experimentalSourceRewriting=true GLOB='tests/cypress/integration/book/test-booking.feature' --headless --browser chrome
const testStore = {};
module.exports = (on, config) => {
on('file:preprocessor', cucumber()),
on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'chrome' && browser.isHeadless) {
launchOptions.args.push('--disable-gpu');
return launchOptions
}
if (browser.name === 'chrome' || browser.name === 'edge' || browser.isHeadless) {
launchOptions.args.push('--disable-features=SameSiteByDefaultCookies') // bypass 401 unauthorised access on chromium-based browsers
return launchOptions
}
if (browser.name === 'chrome') {
// launch chrome using incognito
launchOptions.args.push(' --incognito')
return launchOptions
}
});
on('task', {
copySomeData({ name, value }) {
console.log(name, value)
testStore[name] = value
return true
},
});
on('task', {
getSomeData(name) {
return testStore[name]
},
});
};