docs: change examples in docs to use for..of and async/await (#15196)

This commit is contained in:
AbhilashJN 2018-10-16 23:11:42 +05:30 committed by Michelle Tilley
parent 0252d7686c
commit de1d24b616
2 changed files with 42 additions and 37 deletions

View file

@ -12,24 +12,28 @@ title is `Electron`:
// In the renderer process. // In the renderer process.
const { desktopCapturer } = require('electron') const { desktopCapturer } = require('electron')
desktopCapturer.getSources({ types: ['window', 'screen'] }, (error, sources) => { desktopCapturer.getSources({ types: ['window', 'screen'] }, async (error, sources) => {
if (error) throw error if (error) throw error
for (let i = 0; i < sources.length; ++i) { for (const source of sources) {
if (sources[i].name === 'Electron') { if (source.name === 'Electron') {
navigator.mediaDevices.getUserMedia({ try {
audio: false, const stream = await navigator.mediaDevices.getUserMedia({
video: { audio: false,
mandatory: { video: {
chromeMediaSource: 'desktop', mandatory: {
chromeMediaSourceId: sources[i].id, chromeMediaSource: 'desktop',
minWidth: 1280, chromeMediaSourceId: source.id,
maxWidth: 1280, minWidth: 1280,
minHeight: 720, maxWidth: 1280,
maxHeight: 720 minHeight: 720,
maxHeight: 720
}
} }
} })
}).then((stream) => handleStream(stream)) handleStream(stream)
.catch((e) => handleError(e)) } catch (e) {
handleError(e)
}
return return
} }
} }

View file

@ -20,32 +20,33 @@ $ npm install --save-dev spectron
```javascript ```javascript
// A simple test to verify a visible window is opened with a title // A simple test to verify a visible window is opened with a title
var Application = require('spectron').Application const Application = require('spectron').Application
var assert = require('assert') const assert = require('assert')
var app = new Application({ const myApp = new Application({
path: '/Applications/MyApp.app/Contents/MacOS/MyApp' path: '/Applications/MyApp.app/Contents/MacOS/MyApp'
}) })
app.start().then(function () { const verifyWindowIsVisibleWithTitle = async (app) => {
// Check if the window is visible await app.start()
return app.browserWindow.isVisible() try {
}).then(function (isVisible) { // Check if the window is visible
// Verify the window is visible const isVisible = await app.browserWindow.isVisible()
assert.strictEqual(isVisible, true) // Verify the window is visible
}).then(function () { assert.strictEqual(isVisible, true)
// Get the window's title // Get the window's title
return app.client.getTitle() const title = await app.client.getTitle()
}).then(function (title) { // Verify the window's title
// Verify the window's title assert.strictEqual(title, 'My App')
assert.strictEqual(title, 'My App') } catch (error) {
}).catch(function (error) { // Log any failures
// Log any failures console.error('Test failed', error.message)
console.error('Test failed', error.message) }
}).then(function () {
// Stop the application // Stop the application
return app.stop() await app.stop()
}) }
verifyWindowIsVisibleWithTitle(myApp)
``` ```
## Setting up with WebDriverJs ## Setting up with WebDriverJs