Cypress: Getting 'TypeError', while returning values from a Page object class function

爷,独闯天下 提交于 2020-12-14 11:39:58

问题


Not able to return values from a Page object class function, where as same function is returns values through custom command.

Custom command function: [This will return 10 texts]

Cypress.Commands.add("defultPrelist", () => {
    cy.get('div[class="css-tpolag"]').then(function($elem) {                     
        const presetList_Name = $elem.text()  
        return cy.wrap(presetList_Name)
       })
    })

Main cypress driver class (where i need the custom function returned values)

describe('Defult PresetsList Validation', function() {
   it('Defult PresetList', function() {
   cy.defultPrelist().then(presetList_Name => {
   cy.log(presetList_Name);    
    }) })

and here i could use the values of custom command function. Now the problem is if i use the same custom command function in a page object class and try to returned in main cypress class getting 'TypeError'.

Page Object Class function: (Same as above custom command function)

class ManagePresetPopup {
   defultPreset () {
   cy.get('div[class="css-tpolag"]').then(function($elem) {                     
   const presetList_Name = $elem.text()  
   return cy.wrap(presetList_Name)
 })
 }}
export default ManagePresetPopup

Main cypress driver class (where i need the page object class function returned values)

describe('Defult PresetsList Validation', function() {
   it('Defult PresetList', function() {    
    const defultPrelist = new ManagePresetPopup()    
     defultPrelist.defultPreset().then(presetList_Name => {
     cy.log(presetList_Name);
  }) 
 }) }}

But here i am getting error as 'TypeError Cannot read property 'then' of undefined' in following line : 'defultPrelist.defultPreset().then(presetList_Name =>'

来源:https://stackoverflow.com/questions/63508925/cypress-getting-typeerror-while-returning-values-from-a-page-object-class-fu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!