我正在尝试将参数传递给使用异步/等待的函数。我已经像这样定义了我的功能
// common.js
export const myAsyncFunc = async (t, textA, textB) => {
await t
.typeText('#input-1', textA)
.typeText('#input-2', textB);
};
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将此函数导入另一个文件时,t由于以下原因,我无法传递它t is not defined:
// index.js
import { myAsyncFunc } from './common'
myAsyncFunc(t, textA, textB)
Run Code Online (Sandbox Code Playgroud)
是否可以通过async / await 传递我textA和textB参数(可能通过curring或其他方式)?
编辑:因此,这正在作为测试咖啡馆库的一部分运行。看起来好像t来自何时testcafe chrome client/__tests__/运行,而不是导入到common.js文件中。
我正在使用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...
}
Run Code Online (Sandbox Code Playgroud)
然后,将它们导入另一个.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 …Run Code Online (Sandbox Code Playgroud) testing automated-tests conditional-statements e2e-testing testcafe
我正在用testcafe针对不支持并发的测试后端编写E2E测试,即,如果两个测试并行执行,则测试后端会崩溃。
当我仅针对一个浏览器进行测试时,测试将按顺序执行。但是,当我指定多个浏览器时,测试将按浏览器顺序运行,但是测试会同时在每个浏览器中启动。
我希望testcafe首先在一个浏览器中执行所有测试,然后打开下一个浏览器并在其中执行所有测试,依此类推。
这可能吗?
我正在尝试在gitlab的CI管道中运行端到端测试(使用testcafe)。但是我遇到以下错误:
ERROR The Firefox 52.0.0 / Linux 0.0.0 browser disconnected. This problem may appear when a browser hangs or is closed, or due to network issues.
Run Code Online (Sandbox Code Playgroud)
我的.gitlab-ci.yml如下:
stages:
- test
before_script:
- apt-get update -yqqq
- apt-get install -y xvfb
- apt-get install iceweasel -yqq
- Xvfb :99 -ac &
- export DISPLAY=:99
test-frontend:
image: node:7.7.4
stage: test
script:
- npm install
- npm install -g testcafe@0.19.2
- testcafe --list-browsers
- testcafe firefox e2etests/tests/login.test.js
tags:
- vue
Run Code Online (Sandbox Code Playgroud)
因此,基本上,我将节点docker映像用于测试“阶段”并安装xvfb以“显示”浏览器。
输出ci gitlab: …
我正在尝试运行我的第一个 testcafe 测试,但它被证明是艰巨的。
testcafe -e chrome client/routes/Lookup/components/testcafe/lookup-test.js
SyntaxError: client/routes/Lookup/components/Lookup.js: Unexpected token (60:8)
58 | if (error.status && error.status !== 404) {
59 | return (
> 60 | <NetworkIssues code={error.status} />
| ^
61 | );
62 | }
63 |
at Object.<anonymous> (client/routes/Lookup/components/testcafe/lookup-test.js:1:1)
Run Code Online (Sandbox Code Playgroud)
查找-test.js
import Lookup from '../Lookup';
import React from 'react';
import { waitForReact } from 'testcafe-react-selectors';
fixture('Lookup Component').page('http://localhost:3000/web/lookup').beforeEach(async () => {
await waitForReact();
});
test('foo', async (x) => {
await x
.typeText('customerName', '07450118811')
.expect('customerName.value').contains('07450118811');
});
Run Code Online (Sandbox Code Playgroud)
我的代码没有任何错误。它编译并运行良好,并通过了我所有的笑话和酶单元测试。但是我在网上找不到任何有关此的指导。如您所见,忽略错误标志无效。
干杯。
用于如下用途
test(testName, async (t) => {
const ua = await getUA()
await t.takeScreenshot(
fixtureName +
"/" +
testName +
"/" +
identifyUserAgent(ua) +
"/" +
"scsh_1.png",
)
...
Run Code Online (Sandbox Code Playgroud)
从 testcafe@0.21.1 开始,我的解决方法是
const fixtureName = "Index_Page_Test"
fixture(fixtureName).page(...)
...
const testName = "dom_has_critical_elements"
test(testName, async (t) => {
...
Run Code Online (Sandbox Code Playgroud)
但更愿意在 t 上提供它。我错过了什么吗?
我有一个<select>带有几个<option>标签的。其中一些可以通过使用“is-disabled”类来禁用。我想要做的是选择列表中的第一个可用选项。为此,我使用了在 testcafe 网站上找到的示例(https://devexpress.github.io/testcafe/documentation/recipes/testing-select-elements.html),但我似乎无法让它工作。
运行测试时,该工具会单击一次选择,然后再单击一次,然后关闭。此后,不再选择任何值。
有没有更好的方法来处理选项的动态选择?或者什么是更好的解决方案?任何帮助将不胜感激!
问候康奈尔
SizeSelector component:
import {t, Selector} from 'testcafe';
class SizeSelector {
constructor() {
this._sizeSelector = Selector('.sizeSelectionGroup');
this._selectors = this._sizeSelector.child('.productSizeSelection');
this._widthSelector = this._selectors.nth(0);
// todo other size types (single numeric/text)
}
// todo refactor
async setFirstAvailableWidth() {
const options = this._widthSelector.find('option'); // contains 13 elements while debugging
const availableOptions = options.filter(node => {
return !node.classList.contains('is-disabled');
});
const count = await availableOptions.count; // contains around 8 elements while debugging
if (count …Run Code Online (Sandbox Code Playgroud) 使用 testcafe grep 模式将部分解决我们使用标签的问题,但它仍然会在规范报告上显示这些标签......!!!
有没有办法在测试/夹具名称中包含标签并使用 grep 模式,但跳过这些标签以显示在执行报告中?
import { Selector } from 'testcafe';
fixture `Getting Started`
.page `http://devexpress.github.io/testcafe/example`;
test('My first test --tags {smoke, regression}', async t => {
// Test code
});
test('My Second test --tags {smoke}', async t => {
// Test code
});
test('My first test --tags {regression}', async t => {
// Test code
});
testcafe chrome test.js -F "smoke"
Run Code Online (Sandbox Code Playgroud)
上面的代码片段将为我触发仅烟雾测试,但报告将显示测试名称以及这些标签
是否有其他处理标签的方法或不在测试执行报告中显示标签的解决方案?
testing smoke-testing regression-testing e2e-testing testcafe
我正在尝试使用withText过滤器创建一个选择器并希望选择同级元素。
给出: const Create_asset = S('span').withText('Create Asset')
Create_asset()ReExecutablePromise用nextSibling()方法返回一个。
await Create_asset()返回一个 DOM-like(?) 对象,但没有nextSibling()方法,所以我似乎做不到await Create_asset().withText('text').nextSibling()
使用withText()过滤器时如何随后选择兄弟姐妹?
也感谢您提供任何调试技巧!
数据驱动测试是为任何工具编写自动化测试用例的重要方面。我最近一直在测试testcafe,但还没有找到令人信服的方式来进行数据驱动的测试,即对不同的输入执行测试。
我遇到了以下示例:https : //testcafe-discuss.devexpress.com/t/multiple-execution-of-one-test-with-different-data/219, 但在上面的示例中,我们处理的是不同的登录用户名作为输入。如果我设想必须检查页面上是否显示元素列表的情况,那么我肯定会采取一些步骤进行验证。在这种情况下,我可能不想在每次传递新输入时都执行引导步骤。在上面的示例中,输入看起来像是在测试用例级别上,而不是在测试步骤级别上,因为我们将测试用例放在for循环中,因此无论我是否要重复它们,所有验证/导航点都将执行
由于我是testcafe的新手,并且遍历分散的文档,所以我的问题是-对于数据驱动的测试,这是我们在测试咖啡馆中唯一的方法吗?还是在testcafe中有更令人信服的,非冗长的方法-如果是的话,有人可以向我指出该文档吗?
testcafe ×10
testing ×7
e2e-testing ×6
javascript ×4
async-await ×1
asynchronous ×1
filter ×1
gitlab ×1
reactjs ×1
typescript ×1
web-testing ×1