I want to create tests in my repo (https://github.com/DWboutin/jest-spectron-ts) all seems to work, but I can't access the Application.client API in my tests.
I tried in Promises style, async/await, with Mocha and I can't make it work.
This is my only test file (very basic)
const path = require("path");
const Application = require("spectron").Application;
const electron = require("electron");
jest.setTimeout(10000); // increase to 50000 on low spec laptop
let app: any = new Application({
path: electron,
args: [path.join(__dirname, "..", ".webpack", "main", "index.js")]
});
describe("test", () => {
beforeAll(async () => {
await app.start();
});
afterAll(async () => {
if (app && app.isRunning()) {
await app.stop();
}
});
it("shows an initial window", async () => {
const windowCount = await app.client.getWindowCount();
expect(windowCount).toBe(1); // this gives 2, I don't know why
});
it("should have correct text", async () => {
const h1Text = await app.client.getText("h1"); // TypeError: app.client.getText is not a function
expect(h1Text).toEqual("Hello World!");
});
});
Can someone help me please?
In regards to your comment about
windowCountbeing2, see the last comment in this section of the docs.I don't know if devtools are open or not, but that seems to be the official reasoning for now.
In regards to
app.client.getTextnot being a function, it is because it is not a function. It actually seems the documentation is incorrect - possibly not updated from v11.0.0 to v11.1.0, and forgotten about.Source: https://github.com/electron-userland/spectron#client
The
browserobject for WebdriverIO does not contain agetTextfunction (https://webdriver.io/docs/api.html), however, an element retrieved does have thegetTextfunction in question.This should solve your problem:
This unit test on the spectron repository pointed me in the right direction for this solution.
Cheers.