【发布时间】:2021-10-06 09:24:01
【问题描述】:
我是 Cypress 和 JavaScript 的新手,请帮助我了解更多信息
我必须使用 cypress 自动化网站以验证 EMI 值。
下面是我的 .js 代码,我需要在其中实现 EMI 计算器逻辑并需要将其传递给另一个方法(cypress 中的“it”块)。 'it' 块将从网站获取值,并应使用我在代码 EMILogic() 方法中返回的 EMI 逻辑进行验证。
EMILogic() 将返回一个值 (emi),我在 cy.get('#emi').should('have.text', EMIdata.emi) 行中传递该值但是在执行代码时,我在 cypress 中遇到断言错误,因为 Timed out retrying after 4000ms: expected '' to have text undefined, but the text is '925.11'
describe('EMI Calculation', function () {
class abc{
EMILogic() {
const amount = 20000;
const rate = 5;
const month = 2;
let emi;
rate = rate/(12*100);
period = period*12;
emi = (amount*rate*Math.pow(1+rate, month))/(Math.pow(1+rate, month)-1);
return emi
}
}
下面是我需要从上面的类中传递 emi 值的代码
it('EMI calculator', function () {
const EMIdata = new abc();
cy.visit('emi-calculator.html')
cy.get('.MR15').click()
cy.get('#emi').should('have.text', EMIdata.emi)
})
})
【问题讨论】:
标签: javascript object cypress method-call