问题
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