私のプロジェクトは Electron フレームワークを使用しています。開発者はビルドを作成し、electron exe を提供してくれました。exe を開くと、アプリケーションのエントリ ポイントであるログイン フォームが表示されます。フォームには基本的に、ユーザー名とパスワードのテキスト ボックスと [サインイン] ボタンの 3 つのコントロールがあります。次に、そのページで機能テストを実行する必要があります。
私の要件は、ユーザー名とパスワードのテキスト ボックスにテキストを入力し、送信ボタンをクリックすることです。(この場合は、ログインが成功したことを前提としています。) ログインすると、テストする必要があるウェルカム メッセージが表示されます。
電子アプリからテキストボックスと送信ボタンの参照を取得し、それらに対してアクションを実行するにはどうすればよいですか?
以下のコードを試しました。電子exeを開きますが、何もせず、テストケースに合格します。
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"
}
}