I’m learning how to use cypress in a pretty informal way, so my apologies if this seems obvious.
In this example on the website: Sharing Context, they say there is a simple way to use data you create in before() or beforeEach() in a testcase it(). But when I tried it it said my this.variable was undefined. After a little more searching I found that al aliases are cleared before each test, making the example on the website not possible. Am I going crazy?
Example on the website under Sharing context:
describe('parent', () => {
beforeEach(() => {
cy.wrap('one').as('a')
})
context('child', () => {
beforeEach(() => {
cy.wrap('two').as('b')
})
describe('grandchild', () => {
beforeEach(() => {
cy.wrap('three').as('c')
})
it('can access all aliases as properties', function () {
expect(this.a).to.eq('one') // true
expect(this.b).to.eq('two') // true
expect(this.c).to.eq('three') // true
})
})
})
})
Briefly what I’m trying to do: (I thought the way I get my data irrelevant to the question)
describe('myTests', () => {
beforeEach(() => {
// producing data resulting in a jquery list element
cy.wrap($element).as('element')
})
it('firstTest', function () {
this.element.click()
})
}
This results on a TypeError (void 0) is undefined
With an error to the beginning of this