问题
I have written one login test case for my electron app using mocha via spectron tool.
I am facing following issues.
- Sometimes my script works completely fine, and I am able to pass username and password value to web elements and login is executed.
- Sometimes I am able to see testcases as passed, but values are not passed to username and password web elements.
- One day I tried to clear my system temp files and executed "npm test" command and script executed properly, but again next day facing same issue as mention in point no. 2.
Can you guys please help me how this can be fixed or if am missing any package required.
My package.json file
{
"name": "new_spectron_module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
"dependencies": {
"npm": "^6.5.0",
"npm-check-updates": "^2.15.0",
"spectron": "^5.0.0"
},
"devDependencies": {
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
"debug": "^4.1.0",
"electron": "^4.0.0",
"electroner": "^4.0.7",
"express": "^4.16.4",
"jade": "^1.11.0",
"mocha": "^5.2.0",
"morgan": "^1.9.1",
"serve-favicon": "^2.5.0",
"spectron-keys": "0.0.1",
"stylus": "^0.54.5",
"webdriverio": "^4.14.1"
},
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC"
}
My spec.js file
var assert = require('assert');
var Application = require('spectron').Application
describe('Test Suite 1', function () {
this.timeout(500000)
beforeEach(function () {
this.app = new Application({
path: 'C:/Users/Admin/AppData/Local/Programs/Tradovate Trader Devel/Tradovate Trader Devel.exe'
})
return this.app.start()
})
/*afterEach(function () {
if (this.app && this.app.isRunning()) {
return this.app.stop()
}
})*/
it('Login', function () {
this.app.client.debug();
var txtUserName = this.app.client.element('//*[@id="content"]/div/div[2]/div/div[2]/div[1]/div[1]/div/input');
var txtPassword = this.app.client.element('//*[@id="content"]/div/div[2]/div/div[2]/div[1]/div[2]/div/input');
var btnSignIn = this.app.client.element('//*[@id="content"]/div/div[2]/div/div[2]/div[2]/div[1]/button');
//var accClick = this.app.client.element('//div[@class="pane account-selector dropdown"]//div[@class="caret"]');
//var logoutLink = this.app.client.element('//*[@id="content"]/div/div[1]/div[5]/div/ul/li[3]/a');
txtUserName.setValue('Clarion_19');
//thread.sleep(2000);
txtPassword.setValue('19Passw0rd$');
//click on signin button
btnSignIn.click();
//await accClick.click();
//logoutLink.click();
//console.log(btnSignIn.hasFocus());
})
})
回答1:
did you tried to run "npm install" first?
来源:https://stackoverflow.com/questions/53956207/spectron-using-mocha-is-not-working-as-expected