标签: testcafe

testcafe如何进行条件元素的选择

我在选择有条件地出现在页面上的元素时遇到了麻烦。我尝试过awaiting,但是没有用。

// Gets imported as detailedProductPage 
export default class Page {
  constructor () {
    this.chipItem0 = Selector('[data-test-id="chipItem0"]').child('.tag-name').child('[data-test-id="tagValue"]');
  }
}


test('should accept value and allow for making the selection of multiple     items.', async t => {
  const string0 = 'Professionelle Nassreinigung nicht erlaubt';
  const string1 = 'Handwäsche';
  const string2 = 'Waschen 30°C';

  await t
    .click(detailedProductPage.listContainerFirstChild)

    .typeText(detailedProductPage.symbols, string0)
    .click(detailedProductPage.symbolsResultsItem0)
    .expect(string0).eql(detailedProductPage.chipItem0.innerText)

    .typeText(detailedProductPage.symbols, string1)
    .click(detailedProductPage.symbolsResultsItem0)
    .expect(string1).eql(detailedProductPage.chipItem1.innerText)

    .typeText(detailedProductPage.symbols, string2)
    .click(detailedProductPage.symbolsResultsItem1)
    .expect(string2).eql(detailedProductPage.chipItem2.innerText);
});    
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

在此处输入图片说明

testing automated-tests e2e-testing testcafe

6
推荐指数
1
解决办法
1250
查看次数

TestCafe-断言元素的正确方法是可见的

基于各种论坛讨论,TestCafe文档,并尝试将其与结果进行比较,我仍然不确定哪种方法正确(或最佳)来断言页面元素可见。

await t.expect(Selector('#elementId').visible).ok();

await t.expect(await Selector('#elementId').visible).ok();

还是这些都不正确,还有另一种方法更可取?与断言元素存在相比,这有何不同?还是元素的其他属性,例如:checked?

testing automated-tests assert visible testcafe

6
推荐指数
1
解决办法
1413
查看次数

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

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

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

测试:

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
});
Run Code Online (Sandbox Code Playgroud)

ProductListerPage:

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

class ProductListerPage extends AbstractPage { …
Run Code Online (Sandbox Code Playgroud)

javascript e2e-testing testcafe

6
推荐指数
1
解决办法
2239
查看次数

将当前URL写入TestCafe中的控制台

我有一个变量“ currentPage”,我想将其设置为运行页面上的当前URL。但是要查看URL是否正确,我想将其打印到控制台。我尝试执行的操作都会不断出现“未定义”,“对象”,... ...另一方面,如果我使用“ await t.expect(...)”方法并使其失败,则会看到所需的URL。

const getURL = ClientFunction(() => window.location.href);
console.log(getURL) //does not work
console.log(getURL()) //does not work
Run Code Online (Sandbox Code Playgroud)

我可以将其写入控制台输出吗?如果是这样的话,我想也应该可以做类似“ currentPage = getURL()”的事情,但是我得到:

current page function __$$clientFunction$$() {
Run Code Online (Sandbox Code Playgroud)

console automated-tests e2e-testing testcafe

6
推荐指数
1
解决办法
1413
查看次数

将Testcafe与Appium一起使用

我现在正在寻找一段时间,如何在Appium中使用TestCafe。

长话短说:测试环境是一个node.js环境;自动化测试脚本使用TestCafe打字稿编写 ; 计划是在台式机浏览器和手机上执行这些测试。

桌面浏览器:涵盖了TestCafetestcafe-browser-provider-selenium以及Selenium网格服务器。

移动电话:我试图通过执行使用移动电话测试,来弥补这一TestCafe连同Appium

在这里,文档不容易找到,而且我在取得任何进展方面也没有运气。我对从Testcafes端需要执行的操作很感兴趣,因为在LAN内,我可以访问已运行的Appium服务器,并将其连接到实际设备。

是否有人使用上述工具并想分享专有技术?有人可以建议任何链接/ YouTube视频/或任何可能在这个方向上有所帮助的东西吗?TIA!

PS:我已经看到了此链接,但它没有帮助,因为它需要人机交互并且还不是完全自动化的:TestCafe移动设备测试的QR码建议

以后编辑

使用testcafe-browser-provider-webdriverio软件包不能解决问题,因为它存在一些连接问题。因此,我重新寻找解决方案,但我拒绝相信上述方案没有选择 ...

browser-automation typescript appium e2e-testing testcafe

6
推荐指数
1
解决办法
358
查看次数

甚至跨浏览器一一执行测试

我正在用testcafe针对不支持并发的测试后端编写E2E测试,即,如果两个测试并行执行,则测试后端会崩溃。

当我仅针对一个浏览器进行测试时,测试将按顺序执行。但是,当我指定多个浏览器时,测试将按浏览器顺序运行,但是测试会同时在每个浏览器中启动。

我希望testcafe首先在一个浏览器中执行所有测试,然后打开下一个浏览器并在其中执行所有测试,依此类推。

这可能吗?

javascript testing automated-tests typescript testcafe

5
推荐指数
1
解决办法
268
查看次数

TestCafe-选择器/断言可以并行运行吗?

我试图对运行时间进行基准测试,但无法得出结论性的结果。

之间有什么区别:

await t.expect(Selector('something').visible).ok()
await t.expect(Selector('something1').visible).ok()
await t.expect(Selector('something2').visible).ok()
Run Code Online (Sandbox Code Playgroud)

Promise.all([
    t.expect(Selector('something1').visible).ok(),
    t.expect(Selector('something2').visible).ok(),
    t.expect(Selector('something3').visible).ok()
])
Run Code Online (Sandbox Code Playgroud)

似乎在每种情况下断言都是串行运行的。

注意:我要求查看是否可以加快对多个匹配但独立元素的操作和断言,我了解在大多数情况下我们希望测试同步运行。

javascript e2e-testing testcafe

5
推荐指数
1
解决办法
146
查看次数

需要帮助以使用Testcafe检查元素是否在当前视口中

我正在尝试实现一个自定义方法,以查找元素是否在当前视图端口中

以下是我尝试实现的代码片段,但结果未呈现布尔结果:

export const isElementInViewport = () => {
const getBoundValues = ClientFunction(() => document.querySelectorAll(".hero-getstart").item(0).getBoundingClientRect());

const windowHeight = ClientFunction(() => window.innerHeight);
const windowWidth = ClientFunction(() => window.innerWidth);

return getBoundValues.bottom > 0 && getBoundValues.right > 0 && getBoundValues.left < (windowWidth || document.documentElement.clientWidth) && getBoundValues.top < (windowHeight || document.documentElement.clientHeight);
};
Run Code Online (Sandbox Code Playgroud)

上面的代码在浏览器控制台上可以正常运行,即,当我尝试将getBoundValuesin 存储在变量A中并尝试运行return命令时,它会根据视口中元素的可见性将输出打印为true或false。脚本,它总是给出一个假:

这是触发上述方法的方法:

export const verifyElementInView = () => {
  const elementVisible = isElementInViewport();
  console.log(elementVisible);
};
Run Code Online (Sandbox Code Playgroud)

输出始终为假。

这是我尝试执行时收到的输出摘要console.log(getBoundValues)

{ [Function: __$$clientFunction$$]
with: [Function],
[Symbol(functionBuilder)]: 
ClientFunctionBuilder {
callsiteNames: 
  { …
Run Code Online (Sandbox Code Playgroud)

automated-tests ui-testing viewport e2e-testing testcafe

5
推荐指数
1
解决办法
344
查看次数

自动化测试中有多少断言?

我被赋予了使用testcafe构建测试服的任务,并且在我编写测试时,我偶然发现了一个特定问题"多少断言太多了?".基本上,在测试完成后,会生成一个报告.查看报告并不直观.例如,如果在网页上找不到元素,我会看到如下内容:

>Selector('tads') does not exist in the DOM. 
Run Code Online (Sandbox Code Playgroud)

这迫使我手动完成测试以验证失败的原因.

根据testcafe文档,您可以向断言添加可选消息.如此处所见

截至目前,我在一些地方发布了一些消息.在每次点击或每次操作后都有一个断言(带有简明的错误信息)是否明智?(即单击登录按钮,执行断言以查看登录模式是否出现.现在登录,断言登录模式消失)

代码看起来像这样:

await t.click(this.loginButton);
await t.expect(this.loginButton.exists).ok("I don’t see the login button");

await signup.newUserSignUp();
await t.expect(this.loginButton.exists).notOk("The login modal didn’t disappear"); 
Run Code Online (Sandbox Code Playgroud)

任何反馈都会很棒.

javascript automated-tests e2e-testing testcafe

5
推荐指数
1
解决办法
126
查看次数

如果某项测试失败,是否有办法保释套件?

我进行了一项测试,如果测试失败,则表明该应用程序存在较大问题。如果一项测试失败,那么运行其余测试将毫无意义。

如果单个测试失败,是否有办法保全套件,但如果该测试通过,则运行所有测试?

web-testing functional-testing e2e-testing testcafe

5
推荐指数
1
解决办法
229
查看次数