Automation/Cypress

sibling, parent

c29130811 2020. 11. 26. 22:49

DOM Node의 Sibling이나 Parent를 접근하려고 했었었는데, 기본 예제에는 항상 답이 있었다.

cy.xpath('//a[text()="Completed Story"]/parent::div/parent::div/parent::td/following-sibling::td/button')
  .should(($button) => {
  expect($button.get(0).innerText).to.eq('Completed')
})

 

Cypress Open을 통해 맨 처음 만들어진 예제들을 재 확인 해보면,

 

siblings와, parent를 접근할 수 있는 것이 있었다.

it('.siblings() - get all sibling DOM elements', () => {
    // https://on.cypress.io/siblings
    cy.get('.traversal-pills .active')
      .siblings().should('have.length', 2)
})
it('.parent() - get parent DOM element from DOM elements', () => {
    // https://on.cypress.io/parent
    cy.get('.traversal-mark')
      .parent().should('contain', 'Morbi leo risus')
})
728x90

'Automation > Cypress' 카테고리의 다른 글

data-cy  (0) 2021.04.25
cypress-file-upload  (0) 2021.03.05
commands  (0) 2020.12.02
Element  (0) 2020.10.13
Cypress  (0) 2020.10.12