小编soc*_*way的帖子

无法使用 Cypress.io 测试页脚的背景颜色,它会引发错误

无法使用 Cypress.io 测试背景颜色,在运行 cypress 测试时抛出以下错误;CypressError:重试超时:actual.equals 不是函数。通过安装chai-colorsnpm install chai-colors并在/support/index.js下添加以下内容

import chaiColors from 'chai-colors'
chai.use(chaiColors)
Run Code Online (Sandbox Code Playgroud)

cypress 测试如下:

describe("Background Color test", () => {
  //before(() => {
  //  cy.visit('https://sometesturl.com')
//  })
  it.only('Verify the backgroud color, this should work', () => {
     cy.visit('https://sometesturl.com')
      cy.get('#footer')
        .should('colored', '#f2e47d')
        .and('be.colored', '#f2e47d')
  })
})
Run Code Online (Sandbox Code Playgroud)

javascript cypress

5
推荐指数
3
解决办法
7311
查看次数

Cypress.io如何读取Windows环境变量?

我已经在“ Cypress.env.json”文件中设置了环境变量,在运行cypress测试时,它成功读取了Cypress.env变量。但是,为了更加注重安全性,而不是“硬编码”值,我的团队要求我将此变量保留为单独的“参数”,该参数从Windows 10环境变量中读取。我该如何实现?如果有人可以对此提供建议,那将真的很有帮助。

{
"QA_Server": "https://sometestingsite.com",
"username": "testQA",
"password": "Password1234!"
}
Run Code Online (Sandbox Code Playgroud)

javascript cypress

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

如何使用jquery在赛普拉斯测试中获取div'text'值

在Cypress.io测试中使用Jquery,如何从下面的html标记中获取名为“ Wildness”的div“文本”值。我在赛普拉斯测试中尝试过以下方法,但在控制台中抛出未定义的结果。

const $divText = Cypress.$('.ibxudA .WildnessText-kRKTej').text()
         cy.wrap($divText)
           .should("eq", "Wildness")
Run Code Online (Sandbox Code Playgroud)

const $divText = Cypress.$('.ibxudA .WildnessText-kRKTej').text()
         cy.wrap($divText)
           .should("eq", "Wildness")
Run Code Online (Sandbox Code Playgroud)

javascript jquery cypress

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

在cypress中将测试结果导出为HTML

有什么方法test results可以将 Cypress 导出为 HTML 或任何其他格式(如 cucumber-report.html

javascript cypress

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

我们如何使用Cypress.io Js自动化框架测试警报和内部显示的文本?

我们如何使用Cypress.io Js自动化框架测试警报和内部显示的文本?我无法在赛普拉斯文档中找到相关示例,请告知。

describe('Test an alert and the text displaying', function() {
it('Verify alert and its text content', function(){
    cy.visit('http://www.seleniumeasy.com/test/javascript-alert-box-demo.html')     
    cy.get('button').contains('Click me!').click()
    cy.on ('window:alert', 'I am an alert box!')    

    })

})
Run Code Online (Sandbox Code Playgroud)

javascript cypress

4
推荐指数
3
解决办法
3333
查看次数

在Cypress.io中仍然可以控制测试运行吗?

每次Cypress.io将运行在“ example-spec.js”中编写的所有15个测试时,我在“集成”文件夹下的“ example-spec.js”测试均包含15个测试。我想选择并指定“哪个”测试需要运行,一次可能要进行1或2个测试。原因也许是我不想在添加“新”测试时等待查看所有测试的输出。有什么方法可以控制Cypress.io中的测试运行?

在此处输入图片说明

javascript cypress

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

Cypress.io 测试中未发生拖放

我试图拖动一个元素,然后将其放入放置区域,但测试并未在 Cypress.io 中执行拖放操作。如果有人可以就这里的潜在问题提供建议,那将非常有帮助。没有抛出错误,但是这里仍然没有发生拖放。

describe('Verify the drag and drop test', function() {

  it.only('Check whether the drag and drop of an item is working fine', function() {

  cy.visit('http://www.seleniumeasy.com/test/drag-and-drop-demo.html')  

    const MyDataTransfer = function () {};
    const dt = new MyDataTransfer ();
    dt.types = [];

    // cy.wait(3000);

    cy.get('#todrag span')
      .contains('Draggable 1')
      .trigger("draggable", {dataTransfer: dt});

    cy.get("#todrag span")
      .contains('Draggable 1')
      .trigger('mousedown', { which: 1, pageX: 600, pageY: 600 })
      .trigger('mousemove', { which: 1, clientX: 330, clientY: 35 });

    cy.wait(3000);

    cy.get('#mydropzone')
      .trigger("dropzone", {dataTransfer: dt});                     
  });   
});
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

javascript drag-and-drop cypress

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

useContext 值在页面刷新和注销期间被清除

更新配置文件时,通过navlink (Navigation.js)profile.name显示。useContext()但是,一旦页面刷新或注销期间,profile.name 就会被清除,也profile.photo不会在导航链接中显示。

我想始终在导航链接中显示名称和照片,我该怎么做。?

UserProfileProvider.js

import React, { useMemo, useState} from 'react';
import UserProfileContext from '../context';

const UserProfileProvider = ({children}) => {

    const [profile, setProfile] = useState({ _id: '', photo: '', name: '', email:'', phonenumber:'', position:'', privilege:'', password:''});

    const value = useMemo(() => ({
        profile, setProfile
    }), [profile]);


    return (
       <UserProfileContext.Provider value={value}>
           {children}
       </UserProfileContext.Provider>
    )   
}
export default UserProfileProvider;
Run Code Online (Sandbox Code Playgroud)

Navigation.js

import React, { useContext } from 'react';
import { NavLink, useHistory } from 'react-router-dom'; …
Run Code Online (Sandbox Code Playgroud)

reactjs react-hooks use-context

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

如何使用 cypress 与打印布局交互

我有一个打印按钮,单击该按钮会显示打印布局。如何使用 cypress 与“打印”布局交互。我想在这里检查几件事:

cypress version: 3.5.0 (latest)

1) Check the text "Print" available in `h1` inside the header container div, see image
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

2) Click on the `Cancel` button: please see the html image below 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

下面是我的 cypress 测试,但这未能识别CypressError: Timed out retrying: Expected to find element: 'print-preview-app', but never found it.

context('Print button tests', () => {
            it.only('Print action displays correct data', () => {
                cy.get('.timetable-filter-panel-button.btn.btn-primary > span')
                    .contains("Print current view")
                    .click();
                cy.get('print-preview-app').find('#sidebar').find('#header').find('#headerContainer').find('h1').contains("Print")

            })
        })
Run Code Online (Sandbox Code Playgroud)

cypress

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

如何在 cypress.config.js 中的 cy.task() 函数(例如 validateZipFile 和 getZipFileSize)中添加等待

如何在 cypress.config.js 文件中的cy.task() 函数(例如validateZipFile和)中添加等待?getZipFileSize

test.spec.js

cy.get('button[type="submit"]').contains("Download").click({force:true});
helperFunctions.validateZip("Booking Results Resource Pack - Task");
Run Code Online (Sandbox Code Playgroud)

// helperFunctions.js

validateZip (text) {
    const dfilename = text.replace(/-|_|\s/g,"");
    const downloadedFilename = dfilename+"ZipFile.zip";
   
    cy.task('getZipFileSize', downloadedFilename)
    .should('eq', 6149237)

    cy.task('validateZipFile', downloadedFilename)
    .should('deep.eq', [
      '__Booking-Resource__Question-Cards__Booking_BW.pdf', 
      '__Booking-Resource__Question-Cards__Booking-Colour.pdf'
    ]);
    
  }

  
Run Code Online (Sandbox Code Playgroud)

赛普拉斯.config.js

    const AdmZip = require("adm-zip");
    
    const { defineConfig } = require('cypress')
    
    module.exports = defineConfig({
       e2e: {
        setupNodeEvents(on, config) {
          .....
    
    
            on('task', {
            validateZipFile: filename => {
              const downloadsFolder = config.downloadsFolder
              return  validateZipFile(path.join(downloadsFolder, filename))
            },
            getZipFileSize: filename => {
              const downloadsFolder …
Run Code Online (Sandbox Code Playgroud)

javascript node.js cypress

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