0
0
Cypresstesting~5 mins

cy.first(), cy.last(), cy.eq() in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does cy.first() do in Cypress?

cy.first() selects the first element from a set of matched elements in the DOM.

Think of it like picking the first apple from a basket.

Click to reveal answer
beginner
How does cy.last() differ from cy.first()?

cy.last() selects the last element from a set of matched elements, while cy.first() selects the first.

Imagine picking the last cookie from a jar instead of the first.

Click to reveal answer
beginner
Explain the purpose of cy.eq(index).

cy.eq(index) selects the element at the given zero-based index from matched elements.

It's like choosing the 3rd book on a shelf by counting from the start.

Click to reveal answer
beginner
What is the index base used by cy.eq()?

cy.eq() uses zero-based indexing, meaning the first element is at index 0.

So, cy.eq(0) is the same as cy.first().

Click to reveal answer
beginner
Why is it useful to use cy.first(), cy.last(), or cy.eq() in tests?

They help you pick a specific element from many, making tests precise and reliable.

Like choosing the exact item you want to check in a list.

Click to reveal answer
What does cy.first() select?
AAn element by index
BThe last element from matched elements
CThe first element from matched elements
DAll elements
Which command selects the last element in a set?
Acy.eq(0)
Bcy.last()
Ccy.eq(-1)
Dcy.first()
What index does cy.eq(2) select?
AThird element
BSecond element
CFirst element
DLast element
If you want the second element, which command is correct?
Acy.eq(2)
Bcy.last()
Ccy.first()
Dcy.eq(1)
Which command is equivalent to cy.eq(0)?
Acy.first()
Bcy.last()
Ccy.eq(1)
Dcy.eq(-1)
Describe how cy.first(), cy.last(), and cy.eq() help in selecting elements during testing.
Think about picking items from a list or basket.
You got /4 concepts.
    Explain zero-based indexing in the context of cy.eq().
    Remember how arrays count in programming.
    You got /4 concepts.