标签: e2e-testing

Cypress:子命令主题似乎不是一个元素

我有一个fillInput()将选择器和值作为参数的函数,然后:

  • 清除输入通过 cy.get(selector).clear()

  • 然后通过填充输入值 cy.get(selector).type(value)

据我所知,这确实是某种反模式,应该使用cypress 命令

因此,在阅读 child commands 时,我提出了这个命令,它应该与我的fillInput()实用程序功能相同:

Cypress.Commands.add('fillInput', {prevSubject: 'element'}, (subject, value) => {
  subject.clear();
  subject.type(value);
});
Run Code Online (Sandbox Code Playgroud)

但是,当我通过以下方式在规范中尝试此操作时:

cy.get('#my-selector').fillInput('my-value');
Run Code Online (Sandbox Code Playgroud)

我在 cypress 浏览器控制台中收到此错误:

TypeError: subject.clear is not a function
Run Code Online (Sandbox Code Playgroud)

在文档中,cy.get()据说会产生一个 DOM 元素,并且{prevSubject: 'element'}应该subject是相同的类型(据我所知)。

但是,subject似乎是一种不同的类型和方法,适用于type()或 ' clear()等元素or ' should()不适用于子命令主题。

如何让subject我的孩子命令充当 Dom 元素?

javascript e2e-testing cypress

1
推荐指数
2
解决办法
1398
查看次数

如何使用 testcafe 定位/单击选择器(按钮)

我正在尝试使用 testcafe 测试应用程序的提交。但是,我似乎无法让 testcafe 单击“提交申请”。

到目前为止,我已经尝试了以下方法:

.click(Selector('button').withText('Submit Applicaition'))
.click('#submit-application').withText('Submit Application')
Run Code Online (Sandbox Code Playgroud)

还有一些选择。

我什至无法让 testcafe 找到按钮

import {Selector} from 'testcafe';

fixture `MES login`
 .page `http://mes.coeo.com.au/`;

test('FindButton', async t => {

    await t
    .wait(2000)
        .navigateTo('/le12625-senior-exploration-geologist')
    .wait(2000);

    const one = await Selector('#submit-application');

    const two = one.exists;

    await t
        .expect(two).ok()

    await t
    .wait(5000)
        .click(Selector(one));
}
Run Code Online (Sandbox Code Playgroud)

谁能帮我解释一下是我的 testcafe 脚本还是网站的构建方式,以及如何让 testcafe 单击按钮?

非常感谢。

网站链接

javascript automated-tests button e2e-testing testcafe

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

有没有办法在 TestCafe docker 中运行非无头浏览器?

我正在运行 TestCafe docker,希望查看浏览器,以便我知道发生了什么,并且默认情况下不以无头模式运行它。是否可以?

automated-tests browser-automation docker e2e-testing testcafe

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

Nest JS微服务TCP端到端测试

有人知道如何为 Nest 微服务编写 E2E 测试吗?给这个代码?

主要.ts

import { NestFactory } from '@nestjs/core';
import { Transport } from '@nestjs/microservices';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.createMicroservice(AppModule, {
    transport: Transport.TCP,
  });
  app.listen(() => console.log('Microservice is listening'));
}
bootstrap();
Run Code Online (Sandbox Code Playgroud)

应用程序控制器.ts

import { Controller } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';

@Controller()
export class MathController {
  @MessagePattern({ cmd: 'sum' })
  accumulate(data: number[]): number {
    return (data || []).reduce((a, b) => a + b);
  } …
Run Code Online (Sandbox Code Playgroud)

microservices e2e-testing nestjs

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

如何在 testcafe 中存根 window.open

我想在 testcafe 中模拟 window.open 函数。这样如果我的应用程序调用 window.open 而不是点击实际的,我们可以使用模拟

这样的事情会更好

onBeforeLoad: (window) => {
   cy.stub(window, 'open');
}
Run Code Online (Sandbox Code Playgroud)

testing automated-tests mocking e2e-testing testcafe

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

在 Safari 浏览器上运行 TestCafe 测试所需的设置

我正在尝试在本地安装的 Safari 上执行 TestCafe 套件。我之前已经在 chrome、chrome:headless、firefox 和 firefox:headless 上执行过测试。当运行命令testcafe --list-browsers来检索已安装浏览器的列表时,我收到以下信息:

testcafe --list-browsers
Using locally installed version of TestCafe.
firefox
chrome
safari
Run Code Online (Sandbox Code Playgroud)

当我通过命令行执行简单测试时testcafe safari path/to/tests/,Safari 浏览器将启动,但不会发生导航。我保留在启动窗口上(显示我最喜欢的页面和最近访问的页面)。当对不同的浏览器(例如,)执行相同的命令时testcafe chrome path/to/tests/,测试将在本地浏览器中执行。

我是否缺少启动 Safari 并与 TestCafe 一起运行所需的东西?我正在使用 TestCafe 版本1.6.1。我没有看到 TestCafe 文档中提到的任何其他设置......

testing safari automated-tests e2e-testing testcafe

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

将多个文件中的固定装置和测试导入到 main.js 文件中时,TestCafe “固定装置未定义”错误

我无法将测试和固定装置导入到一个 main.ts 文件中以立即运行所有测试。出于组织目的,我将测试组织到单独的文件夹中。我收到错误:

ERROR Cannot prepare tests due to an error.
ReferenceError: fixture is not defined
Run Code Online (Sandbox Code Playgroud)

我创建了一个 main.ts 文件来运行所有测试。我导入 Fixture()、Test1() 和 Test2()。

主要.ts

import { Fixture } from "../utils/envUtils";
import { Test1 } from "./testSet1/test1";
import { Test2 } from "./testSet2/test2";

Fixture();
Test1();
Test2();
Run Code Online (Sandbox Code Playgroud)

夹具.ts

export const Fixture = () => {
    fixture("Running tests")
}
Run Code Online (Sandbox Code Playgroud)

测试1.ts

export function Test1() {
    test("Test1", async (t: TestController) => {
         ...
    }
}
Run Code Online (Sandbox Code Playgroud)

测试2.ts

export function Test2() {
    test("Test2", async (t: TestController) => { …
Run Code Online (Sandbox Code Playgroud)

testing automation typescript e2e-testing testcafe

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

cypress-file-upload 不将文件附加到其中一个字段

我用于cypress-file-upload将文件附加到输入字段。对不同位置的所有这些输入使用相同的方法(在我的例子中是在不同的模式窗口中)。但在一个地方,由于某种原因,文件没有附加,在执行的步骤中,文件被附加,但在模式中,它没有显示(红色区域)

在此输入图像描述

我需要做什么:

  1. 开放模式
  2. 附加一个文件
  3. 填写所有字段
  4. 单击提交按钮,但它被禁用,因为未附加失败

以及它在代码中的样子:

addUpdates(name, family, version, notes, file) {
  cy.get(this.topMenu_addButton).click()
  cy.get('.upload-field').should('be.visible')
  cy.get('input[type=file]').attachFile(file)
  cy.get(this.modal_field).should('be.visible').fill(name)
  cy.get(this.modal_familyField).fill(family)
  cy.get(this.modal_versionField).fill(version)
  cy.get(this.modal_notesField).fill(notes)
  cy.get(this.modal_proceedButton).should('be.enabled').click()
}
Run Code Online (Sandbox Code Playgroud)

所有字段均已成功填写,但未附加文件。有任何想法吗?

javascript e2e-testing cypress cypress-file-upload

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

为什么赋值运算符在先前声明的操作之前执行?

有这样的代码

let someGlobalVariable = undefined;

describe('Test description', () => {
    it('Should init global variable after action 2', () => {
        action1() // returns Chainable object
            .then(() => {
                // actions like 'cy.xpath('myXpath').click()' (action2)
                someGlobalVariable = 'some value';
                console.log('someGlobalVariable initialized');
            });
    });
})
Run Code Online (Sandbox Code Playgroud)

当执行这段代码时,赋值和日志输出到控制台是在action1完成之后立即完成的,但在action2之前(看起来是同步的)。如果action2出了问题并且失败了,那么全局变量已经被初始化了,但事实不应该是这样。我假设这样的执行是通过 Cypress 的某种性能优化来实现的。这是真的吗?如何修复/禁用它?

我正在使用赛普拉斯 12.13.0。

e2e-testing cypress

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

使用 TestCafe 发出真实的 HTTP 请求

由于严格通过前端自动化我们工作流程的某些部分的复杂性,我们需要在前端自动化测试运行之前发出 HTTP 请求以设置测试数据。

使用 TestCafe 文档,我尝试将一些东西拼凑在一起,当测试运行时,http 请求没有得到执行。这是我的代码:

import {Selector, ClientFunction, RequestHook, RequestLogger} from 'testcafe';
import https from 'https';


fixture `Call Create Test Move`
    .before(async ctx => {
        test('test', async t => {
            const executeRequest = () => {
                return new Promise(resolve => {
                    const options = {
                        method: 'POST',
                        uri: 'https://api.com/move/sample',
                        headers: {
                            "X-Company-Secret": "xxxxxxx",
                            "X-Permanent-Access-Token": "xxxxxxx"
                        },
                        body: {
                            companyKey: 'xxxxxx'
                        },
                        json: true
                    };

                    const req = https.request(options, res => {
                        console.log('statusCode:', res.statusCode);
                        console.log('headers:', res.headers);
                        resolve();
                    });

                    req.on('error', …
Run Code Online (Sandbox Code Playgroud)

javascript testing automated-tests e2e-testing testcafe

0
推荐指数
1
解决办法
1458
查看次数