小智 5
假设您的测试网站是 www.yourtestingwebsite.com 并且您的 username=username password=password
如果它们在加载您的测试站点时提示,您的脚本应该是这样的。cy.visit(' https://username:password@yourtestingwebsite.com ')
别的,
您可以只在 test.js 文件中使用 cy.visit ('/'),但请在您的 integration/command.js 文件中包含以下内容:
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options)
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options)
//
//
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
return false
});
Cypress.Commands.overwrite('visit', async (orig, url, options) => {
let localBool = Cypress.config().baseUrl.includes('local');
if (!localBool) {
const auth = {
username: 'username',
password: 'password'
};
if (options) {
options.auth = auth;
} else {
options = { auth };
}
}
return await orig(url, options);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2758 次 |
| 最近记录: |