cy.visit() 和 cy.request() 的不同 Cypress baseUrl

thi*_*nic 6 cypress

我们在本地测试的应用程序有一个前端和后端,分别在localhost:4200127.0.0.1:8000上运行。

调用时,cy.visit('/somepage')我们希望它与baseUrlfor不同,cy.request('/someapi')因为cy.visit()将访问前端托管的页面,同时cy.request()向后端的 API 端点发出请求。

我们可以使用for 中的默认baseUrl配置,但是有没有办法将默认配置设置为与开箱即用的默认设置不同的配置设置?试图避免必须像. 谢谢!cypress.jsoncy.visit()cy.request()baseUrlcy.request(<fully qualified domain name> + '/someapi')

Pig*_*wer 6

我认为您可以使用配置文件 cypress.env.json 来存储您的 API url 并从每个测试用例中获取它。

在你的 cypress.env.json 中

"apiUrl": "http://api"
Run Code Online (Sandbox Code Playgroud)

在您的测试用例中

describe('get the api variable from config file', () => {
    //set up the variables
    const apiUrl = Cypress.env('apiUrl');
    cy.request(apiUrl + '/someapi');
Run Code Online (Sandbox Code Playgroud)