1
我的項目使用了Electron框架。開發人員已經建立並給了我一個電子exe。當你點擊並打開exe時,它會顯示一個登錄框架,這是我的應用程序的入口點。表單基本上有3個控件,用戶名,密碼文本框和登錄按鈕。現在我必須在該頁面上執行功能測試。我的要求是在用戶名和密碼文本框中輸入一些文本,然後點擊提交按鈕。 (在這種情況下,假設是成功的登錄)。登錄後,我看到一個歡迎信息,我必須測試。我的問題是你如何獲得文本框並從電子應用程序提交按鈕引用並對其執行操作。我已經嘗試了下面的代碼,它打開我的電子exe文件,但什麼也沒做,測試用例通過。如何使用spectron與電子應用程序的控件進行交互
var assert = require('assert');
var Application = require('spectron').Application
describe('Test Suite 1', function() {
this.timeout(100000)
beforeEach(function() {
this.app = new Application({
path: '/CorumDispense-win32-ia32/CorumDispense.exe'
})
return this.app.start()
})
/*afterEach(function() {
if (this.app && this.app.isRunning()) {
return this.app.stop()
}
})*/
it('Login Dispense', function() {
var txtUserName = this.app.client.elementIdText('inpuUsername3');
var txtPassword = this.app.client.elementIdText('inputPassword3');
var btnSignIn = this.app.client.element('//button/*[text(),Sign in]');
txtUserName.keys('Bharat');
txtPassword.keys('Bharat');
//click on signin button
btnSignIn.click();
})
})
輸出是測試用例已經過去了,但我沒有看到任何文字被鍵入到用戶名或密碼和按鈕沒有被點擊
Test Name: Test Suite 1 Login Dispense
Test Outcome: Passed
Result StandardOutput:
mocha.json options file not found. Using default values: { ui: 'tdd', reporter: 'tap', timeout: 2000 }
1..1
ok 1 Test Suite 1 Login Dispense
# tests 1
# pass 1
# fail 0
我的package.json
{
"name": "lighthouse",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"description": "Lighthouse",
"author": {
"name": "bpappu"
},
"dependencies": {
"body-parser": "~1.8.1",
"cookie-parser": "~1.3.3",
"debug": "~2.0.0",
"express": "~4.9.0",
"jade": "~1.6.0",
"morgan": "~1.3.0",
"serve-favicon": "~2.1.3",
"spectron": "^3.4.0",
"stylus": "0.42.3"
},
"devDependencies": {
"chai": "^3.5.0",
"electron": "^1.4.6",
"electroner": "^4.0.2",
"mocha": "^3.1.2",
"spectron": "^3.4.0",
"spectron-keys": "0.0.1"
}
}
有人可以告訴我,如果我在這裏丟失任何東西。 歡呼聲, Bharadwaj。