我正在使用 testcafe 在电子商务页面中运行一些测试,但是一个随机弹出窗口正在破坏测试。当它出现在窗口中时,Testcafe 无法单击下一个选择器并继续进行测试,然后失败。
目前,我正在使用 .js 文件来保存选择器,例如:
import { Selector } from 'testcafe';
export default class Checkout {
constructor () {
//address
this.addressName = Selector('input#CC-checkoutCepAddressBook-sfirstname');
this.addressLastname = Selector('input#CC-checkoutCepAddressBook-slastname');
//Rest of selectors...
}
然后,我将它们导入另一个 .js 并声明测试,如函数:
import { ClientFunction } from 'testcafe';
import { Selector } from 'testcafe';
import Fixture from '../../../DesktopModel/Chrome/fixture.js';
import Home from '../../../DesktopModel/Chrome/home.js';
import Cart from '../../../DesktopModel/Chrome/cart.js';
...
const fixtureUrlBase = new Fixture();
const home = new Home();
const pdp = new Pdp();
const cart = new Cart();
...
export async function checkoutLoggedBoleto(t) {
await t
.click(pdp.addToCartBtn)
.click(home.finishOrderBtn)
.click(cart.finishOrderBtn)
//Rest of the test actions...}
最后,我正在执行 another.js,在其中使用test命令声明测试:
test
.before(async t => {
await login(t);
})
('Desktop - User Login + Checkout with Invoice', async t => {
// Function Login => Search => PDP => Checkout with Invoice
await checkoutLoggedBoleto(t);
});
由于它是随机事件(它发生在不同的时刻,例如有时在产品页面中,有时在结帐页面中),可以使用一些条件测试绕过此弹出窗口,例如弹出窗口“x”出现在屏幕,单击“关闭弹出窗口”并继续测试,否则继续测试。
我在testcafe Test API中搜索并没有找到这样的功能。
我正在使用 testcafe 0.17.0。