更新时间:2023-11-14 08:38:16
请参阅提取可重复使用的测试代码收据,以查找有关如何在测试用例之间共享测试代码的信息.
Refer to the Extract Reusable Test Code receipt to find information on how you can share your test code between your test cases.
此外,如果您只想在特定灯具的测试之间共享对象,则可以使用灯具上下文对象:
Also, you can use the fixture context object if you want to share your object only between tests of a particular fixture: Sharing Variables Between Fixture Hooks and Test Code.
例如:
helper.js
var authToken = 111;
function setToken(x) {
authToken = x;
}
function getToken(x) {
return authToken;
}
export { setToken, getToken };
test.js
import { getToken, setToken } from './helper.js'
fixture("test1")
.page("http://localhost");
test('test1', async t => {
console.log('token: ' + getToken());
setToken(111);
});
test1.js
import { getToken } from './helper.js'
fixture("test2")
.page("http://localhost");
test('test2', async t => {
console.log('token2: ' + getToken());
});
另请参阅: