3
我使用testcafe在电子商务页面中运行一些测试,但随机弹出正在打破测试。当它出现在窗口上时,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...}
最后,我正在执行另一个.js,在此我使用测试命令声明测试:
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。
更新了一些示例代码的问题。尝试了你的建议,但没有奏效。我相信我做错了:) –
布鲁诺,你是页面公共?我可以尝试创建一个工作示例,如果你与我分享它的网址 –
AlexanderMos谢谢,但我更喜欢尝试实施自己。我会回答你的问题,并与我的同事分享,然后再试一次。 –