import { assert } from 'chai';
import spectron from 'spectron';
import { testWithSpectron } from 'vue-cli-plugin-electron-builder';
describe('E2E Test', function () {
this.timeout(500000);
before(async function () {
this.electronApplication = await testWithSpectron(spectron);
});
after(async function () {
await this.electronApplication.stopServe();
});
it('Open Application', async function () {
const { app } = this.electronApplication;
const isRunning = await app.isRunning();
assert.equal(isRunning, true, 'App should be running');
const isVisible = await app.browserWindow.isVisible();
assert.equal(isVisible, true, 'Window should be visible');
const count = await app.client.getWindowCount();
assert.equal(count, 1, 'Window count should be 1');
const title = await app.client.getTitle();
assert.equal(title, 'Recruitment Tools | FuryFerret', 'Title should be right');
await app.webContents.openDevTools();
});
it('Rules page', async function () {
const { app } = this.electronApplication;
const agreeRulesText = await app.client.getText('[data-test-id="agreeRules"]');
/*
---- Error:
TypeError: app.client.getText is not a function
at Context.<anonymous> (tests/e2e/index.spec.js:27:45)
at processImmediate (internal/timers.js:456:21)
at process.topLevelDomainCallback (domain.js:137:15)
*/
const agreeRulesText = await app.webContents.executeJavaScript(`2+5`);
console.log('agreeRulesText', agreeRulesText);
/*
---- OK
agreeRulesText7
*/
const agreeRulesText = await app.webContents.executeJavaScript(`$('[data-test-id="agreeRules"]').textContent`);
console.log('agreeRulesText', agreeRulesText);
/*
- Error:
javascript error: Script failed to execute, this normally means an error was thrown. Check the renderer console for the error.
JavaScript stack:
Error: Script failed to execute, this normally means an error was thrown. Check the renderer console for the error.
at WebFrame.e.startsWith.e.startsWith.WebFrame.<computed> [as _executeJavaScript] (electron/js2c/renderer_init.js:87:1542)
at electron/js2c/renderer_init.js:139:429
at electron/js2c/renderer_init.js:123:361
at EventEmitter.<anonymous> (electron/js2c/renderer_init.js:127:872)
at EventEmitter.emit (events.js:223:5)
at Object.onMessage (electron/js2c/renderer_init.js:115:818)
(Session info: chrome=83.0.4103.122)
---- Console in browser
Uncaught ReferenceError: $ is not defined
at <anonymous>:1:1
at WebFrame.e.startsWith.e.startsWith.WebFrame.<computed> [as _executeJavaScript] (electron/js2c/renderer_init.js:87)
at electron/js2c/renderer_init.js:139
at electron/js2c/renderer_init.js:123
at EventEmitter.<anonymous> (electron/js2c/renderer_init.js:127)
at EventEmitter.emit (events.js:223)
at Object.onMessage (electron/js2c/renderer_init.js:115)
(anonymous) @ VM281:1
e.startsWith.e.startsWith.WebFrame.<computed> @ electron/js2c/renderer_init.js:87
(anonymous) @ electron/js2c/renderer_init.js:139
(anonymous) @ electron/js2c/renderer_init.js:123
(anonymous) @ electron/js2c/renderer_init.js:127
emit @ events.js:223
onMessage @ electron/js2c/renderer_init.js:115
// todo but it's ok:
$('[data-test-id="agreeRules"]').textContent
"Agree with the rules?"
*/
app.webContents.savePage('/Users/kevin/page.html', 'HTMLComplete')
.then(function () {
console.log('page saved')
}).catch(function (error) {
console.error('saving page failed', error.message)
})
/*
---- Result
Page is ok, html is full
*/
assert.equal(agreeRulesText, "Agree with the rules?");
});
});
Hello!
I'm trying to get a text from the page, but i can't. I get error:
app.client.getText is not a function
;A wrote all errors in comments (in the code below). Thanks!
pakage.json
P.s. https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/testingAndDebugging.html#testing
background.js
tests/e2e/index.spec.js