美文网首页
Cypress 用例数据分离

Cypress 用例数据分离

作者: BestFei | 来源:发表于2020-06-09 15:00 被阅读0次

    一、项目结构
    1、用例文件 ../../tests/myPage/demoTest.spec.js
    2、数据文件 ../../tests/myPage/demoTest.data.js

    二、定义数据文件

    const randomNum = Math.floor((Math.random()*90000000)+1)
    const emailAccount = `best${randomNum}@fei.com`
    const mobileNo = Math.floor(9660000000 + Math.random() * 9000000)
    export default {
        "notice": "Welcome to register",
        register: {
            "email": emailAccount,
            "mobileNo": mobileNo,
            "loginPasword": "P@ssw0rd"
        }
    };
    

    三、编写case

    /// <reference types="Cypress" />
    
    const userData = require("../../tests/myPage/demoTest.data")
    
    describe('My First Test Suite', function() {
    
        it('Test Parameter file', function() {
            cy.visit('https://cn.bing.com/')
            cy.log(userData.notice)
            cy.log("register email is "+userData.register.email+",mobile is "+userData.register.mobileNo+",pasword is "+userData.register.pasword)
        })
    })
    

    相关文章

      网友评论

          本文标题:Cypress 用例数据分离

          本文链接:https://www.haomeiwen.com/subject/epwstktx.html