【发布时间】:2019-11-20 08:24:30
【问题描述】:
测试之间的浏览器始终以全新状态打开。登录在我的应用程序中被记住,因为身份验证仍然存在,但由于浏览器总是以干净的状态打开,我必须在所有夹具的钩子之前执行登录。 有什么方法可以打开浏览器,以便记住用户设置、缓存、本地和会话存储?
【问题讨论】:
标签: browser automated-tests e2e-testing web-testing testcafe
测试之间的浏览器始终以全新状态打开。登录在我的应用程序中被记住,因为身份验证仍然存在,但由于浏览器总是以干净的状态打开,我必须在所有夹具的钩子之前执行登录。 有什么方法可以打开浏览器,以便记住用户设置、缓存、本地和会话存储?
【问题讨论】:
标签: browser automated-tests e2e-testing web-testing testcafe
这就是我使用 Role API 解决的方法。
Login.js 页面对象文件
const loginBtn = Selector('[type="submit"]');
const password = Selector('input[placeholder="Password"]');
const userName = Selector('input[placeholder="Email"]');
export const login = Role(`http://example.com/login`, async t => {
await t
.typeText(userName, `abc`)
.typeText(password, `password`)
.click(loginBtn);
});
然后我在我的夹具文件中调用了这个 const Login,如下所示: 夹具.js
import { login } from '../page-objects/login';
fixture('Example Fixture').beforeEach(async t => {
await t.useRole(login).navigateTo('url of the page that you want to open');
});
【讨论】: