单击第一个需要登录的内容时,我想检测URL重定向到登录页面。
有什么办法可以实现?
我在选择有条件地出现在页面上的元素时遇到了麻烦。我尝试过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)
拿这个夹具我想checkoutId根据before夹具钩子中API 调用的结果来设置,这样我就可以用它来设置我的测试页面
let checkoutId;
fixture`Check out as guest user`
.page`localhost:3001/checkout/start/${checkoutId}`
.before(async () => {
await checkout.getCheckoutId(sampleData.cart)
.then(id => (checkoutId = id));
});
// and here the rest of my tests based on the page
Run Code Online (Sandbox Code Playgroud)
我尝试了fixture hooks,共享变量,但我无法让它工作,请求页面时 checkoutId 未定义。
这种情况甚至可能吗?
testing automated-tests browser-automation e2e-testing testcafe
基于各种论坛讨论,TestCafe文档,并尝试将其与结果进行比较,我仍然不确定哪种方法正确(或最佳)来断言页面元素可见。
await t.expect(Selector('#elementId').visible).ok();
与
await t.expect(await Selector('#elementId').visible).ok();
还是这些都不正确,还有另一种方法更可取?与断言元素存在相比,这有何不同?还是元素的其他属性,例如:checked?
我有一个变量“ 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) 我的测试包括根据当前日期(使用dayjs())设置日期的步骤。我需要始终获得相同的预定义日期。
dayjs() 调用new Date(),所以我的方法是模拟全局Date()构造函数。我试过这样:
await t.eval( () => {
const fixedDate = new Date(2010, 0, 1);
Date = class extends Date {
constructor() {
super();
return fixedDate;
}
};
});
Run Code Online (Sandbox Code Playgroud)
像这样,testcafe 无法完成eval(尽管在我的 Chrome 中有效)。到目前为止,我只设法Date.now()直接覆盖,而不是构造函数。
我想知道修改Datewitheval的方法是否是正确的方法,或者是否有更好的解决方案来固定当前的Date.
我正在尝试将参数传递给使用异步/等待的函数。我已经像这样定义了我的功能
// 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
我正在尝试在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)
我的代码没有任何错误。它编译并运行良好,并通过了我所有的笑话和酶单元测试。但是我在网上找不到任何有关此的指导。如您所见,忽略错误标志无效。
干杯。
testcafe ×10
e2e-testing ×7
testing ×6
javascript ×2
assert ×1
async-await ×1
asynchronous ×1
console ×1
date ×1
gitlab ×1
reactjs ×1
redirect ×1
visible ×1
web-testing ×1