Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More examples getting attributes #191

Merged
merged 4 commits into from Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 32 additions & 1 deletion app/commands/querying.html
Expand Up @@ -119,6 +119,7 @@ <h4><a href="https://on.cypress.io/get">cy.get()</a></h4>
// ↲
// Use CSS selectors just like jQuery</code></pre>
</div>

<div class="col-xs-5">
<div class="well">
<button id="query-btn" class="query-btn btn btn-primary">
Expand All @@ -144,9 +145,39 @@ <h4><a href="https://on.cypress.io/get">cy.get()</a></h4>
</div>
</div>
</div>
</div>

<div class="col-xs-12"><hr /></div>
<div class="row">
<div class="col-xs-7">
<p>
<code>cy.get()</code> yields a jQuery object, you can get its attribute by invoking the <code>.attr()</code> method.
</p>
<pre><code class="javascript">cy.get('[data-test-id="test-example"]')
.invoke('attr', 'data-test-id')
.should('equal', 'test-example')

// or you can get an element's CSS property
cy.get('[data-test-id="test-example"]')
.invoke('css', 'position')
.should('equal', 'static')</code></pre>
</div>
</div>

<div class="row">
<div class="col-xs-7">
<p>
Alternatively, chain assertions directly to the <code>cy.get()</code> call.
See <a href="https://on.cypress.io/assertions" target="_blank">assertions documentation</a>.
</p>
<pre><code class="javascript">cy.get('[data-test-id="test-example"]')
.should('have.attr', 'data-test-id', 'test-example')
.and('have.css', 'position', 'static')</code></pre>
</div>
</div>

<div class="col-xs-12"><hr /></div>

<div class="row">
<div class="col-xs-7">
<h4><a href="https://on.cypress.io/contains">cy.contains()</a></h4>
<p>
Expand Down
17 changes: 17 additions & 0 deletions cypress/integration/examples/querying.spec.js
Expand Up @@ -20,6 +20,23 @@ context('Querying', () => {
// Use CSS selectors just like jQuery

cy.get('[data-test-id="test-example"]').should('have.class', 'example')

// 'cy.get()' yields jQuery object, you can get its attribute
// by invoking `.attr()` method
cy.get('[data-test-id="test-example"]')
.invoke('attr', 'data-test-id')
.should('equal', 'test-example')

// or you can get element's CSS property
cy.get('[data-test-id="test-example"]')
.invoke('css', 'position')
.should('equal', 'static')

// or use assertions directly during 'cy.get()'
// https://on.cypress.io/assertions
cy.get('[data-test-id="test-example"]')
.should('have.attr', 'data-test-id', 'test-example')
.and('have.css', 'position', 'static')
})

it('cy.contains() - query DOM elements with matching content', () => {
Expand Down