gentle-accountant-4760
06/16/2022, 12:12 PMgentle-accountant-4760
06/16/2022, 12:18 PMts
cy
.get('.selenium-custom-test')
.contains('custom')
.then((initial) => {
initial.get('.selenium-value').invoke('text')
});
happy-rose-36850
06/16/2022, 12:23 PMnutritious-honey-65632
06/16/2022, 12:45 PMgentle-accountant-4760
06/16/2022, 12:48 PMhtml
<section class="selenium-Worktop">
<div class="selenium-worktop-header">
<div><span class="h3 selenium-section-title">Worktop</span></div>
</div>
<div class="selenium--content">
<div class="selenium-section-info">
<div class="selenium-section-wrapper">
<section class="selenium-item-component-12345">
<div class="itemList-item-firstBlock">
<div class="selenium-article-data">
<div class="selenium-item-info"><span class="selenium-item-name lead-paragraph">THRILL</span> <span class="selenium-item-desc ">custom walnut</span></div>
</div>
</div>
<div class="itemList-item-columns">
<div class="itemList-number">903.475.58</div>
</div>
</div>
</section>
<section class="selenium-item-component-67890">
<div class="itemList-item-firstBlock">
<div class="selenium-article-data">
<div class="selenium-item-info"><span class="selenium-item-name lead-paragraph">THRILLOFIT</span> <span class="selenium-item-desc ">custom orange</span></div>
</div>
</div>
<
<div class="itemList-item-columns">
<div class="itemList-number">134.124.31</div>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
What I need to do first is to check if selenium-item-desc
contains the word custom and if it does, then I want the itemList-number
text - any suggestions on what I sohuld do to be able to do it?``ยดgray-kilobyte-89541
06/16/2022, 12:55 PMgray-kilobyte-89541
06/16/2022, 12:56 PMcustom
is presentgentle-accountant-4760
06/16/2022, 12:57 PMgentle-accountant-4760
06/16/2022, 12:58 PMgray-kilobyte-89541
06/16/2022, 12:59 PMgentle-accountant-4760
06/16/2022, 1:01 PMcy.get(.item-compnent).each((
cy.get(item-name).contains('custom').then(($found) => (
cy.get(itemList-Number)
)
)
gentle-accountant-4760
06/16/2022, 1:01 PMgray-kilobyte-89541
06/16/2022, 1:57 PMcy.each
syntax (it takes a callback) and find its examples using https://cypress.tips/search You can probably even find all elements with custom right away using :has
and :contains
selectors, see https://glebbahmutov.com/cypress-examples/9.7.0/recipes/find-elements-with-subelements.htmlgentle-accountant-4760
06/16/2022, 2:14 PMts
cy.get('.selenium-Worktop:has(.selenium-item-desc:contains("custom"))').each((art) => {
art.find('.itemList-number');
cy.log('in here');
});
but it looks like the art.find('.itemList-number');
is just being skipped in my tests for some reason which is odd, however it does print out "cy.log('in here')" - weird...gentle-accountant-4760
06/16/2022, 2:15 PMnutritious-honey-65632
06/16/2022, 2:21 PMquaint-elephant-51746
06/16/2022, 2:22 PMnutritious-honey-65632
06/16/2022, 2:31 PMart
element and see is .itemList-number
is descendant of art. art.find() should works fine, this is a jquery find() but cy.get(el).find() should work exactly the samegentle-accountant-4760
06/16/2022, 2:32 PMgentle-accountant-4760
06/16/2022, 2:33 PMcy.get('.selenium-Worktop:has(.selenium-item-desc:contains("custom"))').each((art) => {
- I believe this goes into selenium-item-desc which means its in the wrong "section" in the html, and I believe I need to go back a few levels to reach the itemListnutritious-honey-65632
06/16/2022, 2:35 PMgentle-accountant-4760
06/16/2022, 2:35 PMgray-kilobyte-89541
06/16/2022, 2:37 PMart
is a jQuery object, so art.find(...)
synchronously gives you the number element. You want to get its text .text()
then convert it to a number and maybe call cy.log('number', x)
to see itgentle-accountant-4760
06/16/2022, 2:41 PMmelodic-hydrogen-41542
06/16/2022, 3:25 PMicy-camera-47315
06/16/2022, 3:36 PMswift-kitchen-62493
06/16/2022, 3:39 PMproud-breakfast-29892
06/16/2022, 3:46 PMbeforeEach
. Outside of the contexts, there is a global beforeEach
as well, as follows:
js
beforeEach(() => {
cy.log('Setup');
// Sets up my application...
});
context('First Context', () => {
beforeEach(() => {
// Do specific setups for this context...
cy.visit('MyUrl');
});
it('My test', () => {
// My test occours here
});
it('Another test', () => {
// Another test occours here..
});
});
context('Second Context', () => {
beforeEach(() => {
// Do specific setups for this context...
cy.visit('MyUrl');
});
it('My Second test', () => {
// My test occours here
});
});
If a test in the first context passes, Cypress will go to the next context without issue.
However, if the test in the first context FAILS, Cypress will not run the tests in the second context, and it will show the message "No commands were issued in this test."
I have no idea what's the cause for this issue, I'm clueless. I'm using version 9.6.1melodic-hydrogen-41542
06/16/2022, 3:48 PMswift-kitchen-62493
06/16/2022, 3:49 PM