e2e/integration/test_xzm.cy.js
///<reference types="cypress"/>
import '@shelex/cypress-allure-plugin';
// import cypress from 'cypress';
// import{testLoginUser} from '../../fixtures/test_xzm_login.data.js'
var testLoginUser = require('../../fixtures/test_xzm_login.data.js')
//Cypress定位元素默认选择css
describe('测试学掌门网站', () => { //可将describe理解成一个测试套件,suite
before(() => {
//打开网页
cy.visit('https://www.atstudy.com/'); //使用visit方法返回值必须是一个text/html格式文档
})
it.only('首页登录', () => { //一个it就是一条case
for (let user of testLoginUser) {
//点击登录按钮
cy.contains('登录').click();
cy.wait(2000);
//点击密码登录
cy.contains('密码登录').click();
cy.wait(2000);
//输入用户名
cy.get('[placeholder="请输入手机号码"]').type(user.username); //type()方法为输入 相当于sendKeys()
cy.wait(2000);
//输入密码
cy.get('[placeholder="请输入密码"]').focus().type(user.password); //focus()方法为聚焦,相当于将光标移动到此处
cy.wait(2000);
//点击登录
cy.get('.el-button > span').click();
cy.wait(2000);
if (user.result) {
//断言登录成功
cy.get('.study-center > p').should('contain', user.expect_result);
//鼠标悬浮到元素上
cy.get('[src="/img/avatar34.png"][data-v-73171224=""]').trigger('mouseover');
cy.wait(3000);
cy.get('div.user-info-logout > span').click();
cy.wait(3000);
} else {
cy.contains(user.expect_result).should('contain', user.expect_result);
cy.wait(2000);
cy.go(-1);
cy.wait(2000);
};
};
});
})
fixtures/test_xzm_login.data.js
const testLoginUser=[
{
summary:"Login fail",
username:"19929068861",
password:"jzq123...",
expect_result:"该手机号未注册",
result:false
},
{
summary:"Login pass",
username:"19929068860",
password:"jzq123...",
expect_result:"学习中心",
result:true
},
{
summary:"Login fail",
username:"19929068860",
password:"jzq123...1",
expect_result:"账号或密码错误,请重新输入",
result:false
},
{
summary:"Login fail",
username:"19929068861",
password:"jzq123...1",
expect_result:"该手机号未注册",
result:false
},
]
module.exports = testLoginUser;
cypress.config.js
const { defineConfig } = require("cypress");
const allureWriter = require('@shelex/cypress-allure-plugin/writer');
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
allureWriter(on, config);
// implement node event listeners here
},
},
});
jsconfig.json
//jsconfig.json
{
"include": [
"/node_modules/cypress",
"cypress/e2e/**/*.cy.js"
]
}