繁体   English   中英

TestCafe - 点击链接后等待页面加载

[英]TestCafe - Wait for page load after click on link

我正在使用 testcafe 进行 e2e 测试我当前的电子商务项目。 在产品列表页面上,我使用选择器来选择产品磁贴并单击。 在此之后,页面加载产品详细信息页面,我可以继续测试。

问题是,当页面尚未加载时,它已经继续使用产品详细信息页面的断言。 我假设单击操作将等待元素出现并等待页面加载,然后再继续断言。

测试:

import HomePage from '../pages/HomePage/HomePage';
import ProductListerPage from '../pages/ProductListerPage/ProductListerPage';
import Browser from '../helpers/Browser';

fixture('test case').page('http://www.homepage.com');

test('test 1', async t => {
  const homePage = new HomePage();
  await homePage.header.search(t, 'foo bar');

  await t.expect(Browser.getCurrentLocation()).eql('http://www.product-lister/search?q=3301');
  const productListerPage = new ProductListerPage();
  await productListerPage.goToFirstProduct(); // <<< in here I click on the first product

  await t.expect(Browser.getCurrentLocation()).eql('http://www.product-detail/'); // << already executed on lister page instead of product page
});

产品列表页面:

import AbstractPage from '../AbstractPage';
import {t, Selector} from "testcafe";

class ProductListerPage extends AbstractPage {

  constructor() {
    super();

    this._productTilesContainer = Selector('.productLister-productTeasersInner');
    this._productTiles = this._productTilesContainer.child('a.productListerTeaser');
  }

  async goToFirstProduct() {
    return await t.click(this._productTiles.nth(0));
  }
}

export default ProductListerPage;

是否有另一种等待页面加载而不是仅使用睡眠的方法? 或者什么是最好的解决方案?

问候, 康奈尔

您可以指定一个超时值,以便期望将等待一定的时间,直到您的页面在该 url 上。 根据您需要多少时间,您可以将超时更改为更低或更高,否则使用默认超时,我不记得默认值是多少?

有关选择器选项的更多信息

await t.expect(Browser.getCurrentLocation()).eql('http://www.product-detail/', {timeout: 5000});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM