admin管理员组文章数量:1136174
I'm just starting to learn JavaScript and have been using Cypress to automate some regression tests. The test I writing currently is meant to verify link's text and href in a header and footer.
The issue I am having is that these tests need to be run across various environments and I cannot seem to access the baseUrl property set in the cypress.json in order to set the domain in my assertion.
In the script that follows it is the line cy.get("a").should("have.attr", "href", baseUrl + footerLink.link)
:
it.only("translates the content info section", () => {
cy.wrap(orbitData).each(service => {
cy.visit(service.name);
cy.get("#orb-contentinfo > div > ul > li").each(($li, index) => {
let footerLink = service.links[index]
cy.wrap($li).should("have.text", footerLink.linkText)
.within(($li) => {
cy.get("a").should("have.attr", "href", baseUrl + footerLink.link)
});
});
});
});
I'm just starting to learn JavaScript and have been using Cypress to automate some regression tests. The test I writing currently is meant to verify link's text and href in a header and footer.
The issue I am having is that these tests need to be run across various environments and I cannot seem to access the baseUrl property set in the cypress.json in order to set the domain in my assertion.
In the script that follows it is the line cy.get("a").should("have.attr", "href", baseUrl + footerLink.link)
:
it.only("translates the content info section", () => {
cy.wrap(orbitData).each(service => {
cy.visit(service.name);
cy.get("#orb-contentinfo > div > ul > li").each(($li, index) => {
let footerLink = service.links[index]
cy.wrap($li).should("have.text", footerLink.linkText)
.within(($li) => {
cy.get("a").should("have.attr", "href", baseUrl + footerLink.link)
});
});
});
});
So far I have tried a number of things, I'm a bit embarrassed to list them all, I'm new to this so they're probably insane and definitely just guesses; amongst them were Cypress.env('CYPRESS_baseUrl')
and Cypress.baseUrl
. Each time it just comes back as undefined
.
Or, if I'm attacking this in completely the wrong way any guidance on a better way would be appreciated. I'd be grateful for any help or guidance, thanks.
Share Improve this question edited Oct 25, 2018 at 8:55 David Boydell asked Oct 25, 2018 at 8:30 David BoydellDavid Boydell 1,1852 gold badges8 silver badges22 bronze badges3 Answers
Reset to default 174You can use the Cypress.config()
command.
To get baseUrl
value use Cypress.config().baseUrl
or Cypress.config('baseUrl')
.
cy.visit('/')
will visit the baseUrl if you have it defined in your Cypress e2e config. (Source)
Using Cypress 7.7, I found that Cypress.env('baseUrl')
worked.
本文标签: javascriptHow to access the value of baseURL in CypressStack Overflow
版权声明:本文标题:javascript - How to access the value of baseURL in Cypress - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736957957a1957654.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论