I am working to write auto tester code on cypress. As web app is vue.js project, page consists of component in src. So in cypress, I decide to scope all subsequent commands to within component root instead of document root(html). So that cy.get or cy.find will query within component root dom.
But I often need to query some elements outside current scoped component. for example: when I have custom select that renders dropdown outside component, in cypress, inside cy.within there is no way to select dropdown option because it is rendered outside component root.
So I tried to escape scope temporarily to select dropdown and then come back into scope again for next commands.
cy.get(".account-mortgage-component form").within(() => {
cy.get("input[name='postcode']").type("ng2 6dg").blur();
// click input.select-address to open dropdown
cy.get("input.select-address").click();
// then dropdown is rendered outside .account-mortgage-component. so next command can not work
cy.get(".select-address-dropdown").contains("3 Carnarvon Road, West Bridgford").click();
// I hope to escape current scope, so make above code to work. after this I should come back to scope again for next commands.
cy.root().submit();
});
<div class="account-mortgage-component">
<form>
<input name="postcode" />
<div class="custom-select">
<input class="select-address" />
</div>
</form>
<div>
<div class="select-address-dropdown">
<ul>
<li>3 Carnarvon Road, West Bridgford</li>
<li>5 Carnarvon Road, West Bridgford</li>
<li>6 Carnarvon Road, West Bridgford</li>
</ul>
</div>
As my web project is big scaled already, in cypress I should scope most commands using cy.within. Any solution will be help.