【问题标题】:Cypress: Could not able to retrieve a specific data from downloaded excel-sheet赛普拉斯:无法从下载的 excel 表中检索特定数据
【发布时间】:2019-07-21 13:50:40
【问题描述】:

下面是我需要“SIP”数据“37046654”的 Excel

enter image description here enter image description here

我尝试了下面的 cypress 代码,但它失败了,因为它需要 excel-sheet 中的所有数据

赛普拉斯代码:

describe('API Testing with Cypress', () => {
 
    it('Validate the header', () => {
		
responsebodydata = cy.readFile('C:/Users/backNew.csv').should('eq','37046654')
		
		cy.log (responsebodydata)
			
     })
  })

断言结果:通过以下输出超时失败:

预计 'SIP\tAsset Class\tSector\tObservations\tCDP Proximity\r\n37046789\tUP1G\tRetail\t1\t100\r\n37046654\tUG8G\tRetail\t1\t0' 等于 '37046ADD'

谁能告诉我如何获取/检查“37046654”是否存在于 excel 表中

【问题讨论】:

  • 您应该将表格发布为文本。
  • 能否请您提供一些代码示例作为示例,以帮助我理解。
  • 文本格式的表格:SIP ASSERT CLASS Sector Observation CDP Proximity 37046789 UP1G Retails 1 100 37046654 UG8G Retail 1 1(表格也在问题的图片中添加)
  • 嘿@SmrutiranjanaRay。对你有帮助吗?
  • @Yevhen,应用程序已关闭,我会检查并更新

标签: cypress


【解决方案1】:

如果您只想检查37046654 号码是否存在于backNew.csv 文件中,请使用contains

responsebodydata = cy.readFile('C:/Users/backNew.csv').should('contains','37046654')

【讨论】:

  • 酷。很高兴对您有所帮助!
【解决方案2】:

完整的工作代码 -

<reference types="Cypress" />

describe('API Testing with Cypress', () => {

    var responsebodydata

    it('Validate the header', () => {

    responsebodydata = cy.readFile('C:/Users/sharma.al/backNew.csv').then((response)=> {

    responsebodydata = response.body
    cy.log(responsebodydata)
      
    responsebodydata = cy.readFile('C:/Users/sharma.al/backNew.csv').should('contains','37046654')
    
      })     
   })
})

【讨论】:

    猜你喜欢
    • 2019-11-28
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    • 2021-07-07
    • 1970-01-01
    • 2023-02-24
    • 1970-01-01
    相关资源
    最近更新 更多