【发布时间】:2019-07-04 08:27:17
【问题描述】:
我有一个关于 TestCafe 使用的问题。我有一个脚本(夹具),里面有两个测试。如果第一个测试运行 URL 并且如果没有登录,脚本将登录到站点。
但是:第二个测试也总是登录。看起来 Testcafe 无法识别在夹具中完成的 cookie。固定装置或跑步者内的字符串是什么,用于保存设置的 cookie?
import { Selector } from 'testcafe';
fixture `Ordner erstellen`
.page `xxxx`
.before(async ctx => {
ctx.clLogin = `xxxx`;
ctx.clPassword = `xxx`;
});
test('Create and Delete Folder1', async t => {
const testfolder = Selector('.np-folder-name[title="19233456"]')
await t
.typeText(Selector('#email'), t.fixtureCtx.clLogin, {
caretPos: 0
})
.typeText(Selector('#password'), t.fixtureCtx.clPassword, {
caretPos: 0
})
.click(Selector('span').withText('Login'))
.click(Selector('.np-top-section-tab.folder'))
await t
.wait(2000)
.expect(testfolder.withText('19233456').exists).notOk()
test('Create and Delete Folder2', async t => {
const testfolder = Selector('.np-folder-name[title="19233456"]')
await t
.typeText(Selector('#email'), t.fixtureCtx.clLogin, {
caretPos: 0
})
.typeText(Selector('#password'), t.fixtureCtx.clPassword, {
caretPos: 0
})
.click(Selector('span').withText('Login'))
.click(Selector('.np-top-section-tab.folder'))
await t
.wait(2000)
.expect(testfolder.withText('19233456').exists).notOk()
我还尝试了 testcafe 的角色概念。但这也不好用。
import { Selector, Role } from 'testcafe';
const admin = Role('https://bc3-channel.cliplister.com/', async t => {
await t
.typeText(Selector('#email'), `xxx`, {
caretPos: 0
})
.typeText(Selector('#password'), `xxx`, {
caretPos: 0
})
.click(Selector('span').withText('Login'))
});
fixture `Ordner erstellen`
.page `xxx`
test('Create and Delete Folder', async t => {
const testfolder = Selector('.np-folder-name[title="19233456"]')
await t
.useRole(admin)
.navigateTo('xxx')
.click(Selector('.np-top-section-tab.folder'))
});
test('Create and Delete Folder2', async t => {
const testfolder = Selector('.np-folder-name[title="19233456"]')
await t
.navigateTo('xxx')
.click(Selector('.np-top-section-tab.folder'))
await t
.wait(2000)
.expect(testfolder.withText('19233456').exists).notOk()
});
【问题讨论】:
-
参考stackoverflow.com/questions/56975267/…中提到的解决方案
标签: cookies automated-tests e2e-testing web-testing testcafe