Cypress 练习

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"
    ]
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值