使用摩卡的Spectron无法正常工作 [英] Spectron using mocha is not working as expected

查看:237
本文介绍了使用摩卡的Spectron无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过Spectron工具使用Mocha为我的电子应用编写了一个登录测试用例.

I have written one login test case for my electron app using mocha via spectron tool.

我正面临以下问题.

  1. 有时我的脚本可以正常工作,并且能够将用户名和密码值传递给Web元素并执行登录.
  2. 有时我可以看到测试用例已通过,但值未传递到用户名和密码Web元素.
  3. 有一天,我试图清除我的系统临时文件,并正确执行了"npm test"命令和脚本,但第二天又遇到了与要点号相同的问题. 2.

你们能帮助我如何解决此问题,或者是否缺少所需的软件包.

Can you guys please help me how this can be fixed or if am missing any package required.

我的package.json文件

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

我的spec.js文件

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()); 

    })
})

推荐答案

您是否尝试过先运行"npm install"?

did you tried to run "npm install" first?

这篇关于使用摩卡的Spectron无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆