Skip to content

Fix doc and type #897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ property which do not require Node integration.

#### client

Spectron uses [WebdriverIO](http://webdriver.io) and exposes the managed
Spectron uses [WebdriverIO](https://webdriver.io) and exposes the managed
`client` property on the created `Application` instances.

The `client` API is WebdriverIO's `browser` object. Documentation can be found
[here](http://webdriver.io/api.html).
[here](https://webdriver.io/docs/api).

Several additional commands are provided specific to Electron.

Expand All @@ -219,8 +219,10 @@ All the commands return a `Promise`.
So if you wanted to get the text of an element you would do:

```js
app.client.getText('#error-alert').then(function (errorText) {
console.log('The #error-alert text content is ' + errorText)
app.client.$('#error-alert').then(function (element) {
element.getText().then(function (errorText) {
console.log('The #error-alert text content is ' + errorText)
})
})
```

Expand All @@ -237,9 +239,8 @@ API in your tests you would do:

```js
app.electron.clipboard.writeText('pasta')
.electron.clipboard.readText().then(function (clipboardText) {
console.log('The clipboard text is ' + clipboardText)
})
const clipboardText = app.electron.clipboard.readText()
console.log('The clipboard text is ' + clipboardText)
```

#### browserWindow
Expand Down Expand Up @@ -649,7 +650,7 @@ test.afterEach(t => {
return t.context.app.stop();
});

test(t => {
test('opens a window', t => {
return t.context.app.client.waitUntilWindowLoaded()
.getWindowCount().then(count => {
t.is(count, 1);
Expand Down Expand Up @@ -686,7 +687,7 @@ test.afterEach.always(async t => {
await t.context.app.stop();
});

test(async t => {
test('example', async t => {
const app = t.context.app;
await app.client.waitUntilWindowLoaded();

Expand Down
12 changes: 8 additions & 4 deletions lib/spectron.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,19 @@ declare module 'spectron' {
): Promise<AccessibilityAuditResult>;
}

export interface SpectronWindow extends Electron.BrowserWindow {
capturePage(): Promise<Electron.NativeImage>;
}
export type SpectronWindow = {
[P in keyof Electron.BrowserWindow]: Electron.BrowserWindow[P] extends (
...args: infer A
) => infer R
? (...args: A) => Promise<R>
: undefined;
};
Comment on lines +121 to +127
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this more completely in #999, using Promise<R extends PromiseLike<infer T> ? T : R> to avoid doubly-wrapped Promises, and wrapping every module in Electron, not just BrowserWindow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andersk Great works!


export interface SpectronWebContents extends Electron.WebContents {
savePage(
fullPath: string,
saveType: 'HTMLOnly' | 'HTMLComplete' | 'MHTML',
callback?: (eror: Error) => void
callback?: (error: Error) => void
): boolean;
savePage(
fullPath: string,
Expand Down