答案 0 :(得分:0)
您可以通过两个链接的步骤进行此操作。首先,您需要掌握输入内容。最简单的方法通常是按名称命名,然后使用type()方法输入一些数据,所以...
//html
<input type='text' name='username'/>
// test script
cy.get('input[name="username"]').type('john.doe@email.com')
答案 1 :(得分:0)
假设您的测试网站是www.yourtestingwebsite.com
和您的用户名=用户名密码=密码
如果他们在加载测试站点时提示您,则脚本应类似于此。
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);
});