Пример на веб-сайте в контексте общего доступа:
Код: Выделить всё
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
})
})
})
})
Код: Выделить всё
describe('myTests', () => {
beforeEach(() => {
// producing data resulting in a jquery list element
cy.wrap($element).as('element')
})
it('firstTest', function () {
this.element.click()
})
}
редактирования:
Итак, я получаю элемент списка с веб-сайта. Второй видимый элемент в главном меню.
Код: Выделить всё
describe('Click test', () => {
beforeEach(() => {
let counter = 0
cy.visit('https://www.qalybr.nl')
cy.get('ul[class~=menu] li').each(($el) => {
if($el.is(':visible')) {
if(counter === 1) {
cy.wrap($el).as('werkenBij')
}
counter++;
}
})
})
it('Werken', () => {
this.werkenBij.click()
})
})

Подробнее здесь: https://stackoverflow.com/questions/787 ... -a-it-test
Мобильная версия