The directory structure

The login

The outermost before, add a judgment without landed on login, the login window, after page, the route, the router, the store on the global

(For Puppeteer encapsulation processing, here)

login.js

const {run} = require('nine-nine-six'); Before (function() {return new Promise(function (resolve, reject) { If (global.window){resolve() return} run({url:'http://localhost:8080', chromeUrl:'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe' },function (res) { //window,page,route,router,store let {window,page,route,router,store} = res let login = page.findVueNode({ tag:'Login' }) // Vue router front hook router. BeforeEach ((to, from, next)=>{ global.route = to next() }) let form = login.form form.userName = 'xx' form.password = 'xx' form.vcode = 'xx' / login/login. HandleSubmit () / / global Settings window, page, the route, the router, store Object. The keys (res). ForEach (key = > {global [key] = res [key]})  resolve() }) }) })Copy the code

Make Expect global

setup.js

const chai = require('chai');

global.expect = chai.expect;
Copy the code

The test code

delivery.spec.js

Describe ('test Delivery',()=>{ Before (function () {router.push({name:'Delivery', }) }) it('test page title',() => { expect(window.document.title).to.be.equal('DeliveryTitle'); }) it('route name',() => { expect(route.name).to.be.equal('Delivery'); }) it('test FormItem label',() => { let FormItem = page.findVueNode('FormItem') expect(FormItem.label).to.be.equal('item  label'); })})Copy the code

Test command: mocha –require setup login specs –recursive -t 0

The demo address