“ TypeError:
cy.FillAddCaseDetails
不是函数”
describe('Adding a Case on CSS Poratal ', function() {
before(function () {
cy.login() // calling login function successfully
})
it('open add case',function(){
cy.wait(9000)
cy.hash().should('contains','#/home')
cy.wait(['@GETcontentLoad']);
cy.wait(['@POSTcontentLoad']);
cy.get('[uib-tooltip="Add Case"]').click({force:true})
cy.log('clicked on Add case')
cy.wait(3000)
cy.get('[ng-click="lookup.cancel()"]').click({force: true})
cy.get('[ng-click="lookup.closeAddCase()"]').click({force: true})
cy.get('[uib-tooltip="Add Case"]').click({force:true})
cy.wait(3000)
cy.get('[ng-model="lookup.selectedPartner"]',{force:true})
.type(AddJob.JobData.Partner,{force: true})
cy.xpath('//input[@ng-model="lookup.selectedPartner"]')
.should('be.visible').then(() => {
cy.FillAddCaseDetails() // unable to call
cy.FillCustomerDetails() // unable to call
})
函数:
Cypress.Commands.add("FillCustomerDetails", () => {
cy.get('[ng-model="lookup.firstName"]')
.type(AddJob.JobData.FirstName, { force: true})
cy.get('[ng-model="lookup.lastName"]')
.type(AddJob.JobData.LastName, { force: true })
cy.get('[ng-model="lookup.customerPhone"]')
.type(AddJob.JobData.CustomerPhone, { force: true })
cy.get('[value="NEXT"]').click({ force: true })
})
表格:功能将被调用
实际:TypeError:cy.FillAddCaseDetails
不是函数
supportFile
设置为
cypress.config.ts
; 我更改了配置:
false
I在import cypress, { defineConfig } from 'cypress'
export default defineConfig({
e2e: {
'baseUrl': 'http://localhost:4200',
supportFile: 'cypress/support/e2e.ts'
},
})
中创建了自定义命令
commands.ts
然后我在我的e2e.ts file中删除了这一行
declare namespace Cypress {
interface Chainable<Subject = any> {
/**
* Custom command to select DOM element by data-cy attribute.
* @example cy.dataCy('greeting')
*/
clearIndexedDB(): Promise<void>
}
}
Cypress.Commands.add('clearIndexedDB', async () => {
const databases = await window.indexedDB.databases();
await Promise.all(
databases.map(
({ name }) => {
if (!name) return
return new Promise((resolve, reject) => {
const request = window.indexedDB.deleteDatabase(name);
request.addEventListener('success', resolve);
request.addEventListener('blocked', resolve);
request.addEventListener('error', reject);
})
},
),
);
});
如果您将自定义命令添加到
support/commands.js
文件导入该文件。创建
support/index.js
,如果不可用,并将行添加到其中。在我的案例解决方案中,是柏树测试跑者的重新启动。 您可以通过添加以下行尝试来修改cypress.config.ts:
如下所示:
support/index.js
},
});
从柏树文档:https://on.cypress.io/typescript#types-for-custom-commands
如果您将命令cy.datacy添加到您的支持file中:
然后,您可以通过创建supportfile旁边的新的打字稿定义文件来将数据命令添加到全局柏树可链接口(因此称为命令被链接在一起),在这种情况下为cypress/support/support/index.d.ts.
supportFile: 'cypress/support/index.ts',
setupNodeEvents(on, config) {
// implement node event listeners here
},
Cy.xpath(“ // Div [@class ='C-navigatorItem-faceplate ng-scope ng-scope ng-sely-sely-scope']”)。单击(); 使用是有效的,因为我得到了typeerror cy.xpath不是函数