-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic test for speech recognition and synthesis (#2153)
* Initial commit * Use pageObject for mock speech recognition * First mock synthesis test * Clean up * Clean up * Typo * Clean up * Clean up * Rename * Clean up * Add comments * Clean up * Clean up * Clean up * Remove event-target-shim * Add entry * Improve robustness * Update PR number * Rename * Fix cancelling synthesize test * Remove unnecessary screenshots * Remove screenshot
- Loading branch information
Showing
17 changed files
with
495 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"navigation": 10000, | ||
"postActivity": 30000, | ||
"scrollToBottom": 1000, | ||
"test": 60000 | ||
"test": 60000, | ||
"ui": 1000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Condition } from 'selenium-webdriver'; | ||
|
||
import isRecognizingSpeech from '../pageObjects/isRecognizingSpeech'; | ||
|
||
export default function speechRecognitionStarted() { | ||
return new Condition('Speech recognition to start', async driver => await isRecognizingSpeech(driver)); | ||
} | ||
|
||
function negate() { | ||
const condition = speechRecognitionStarted(); | ||
|
||
return new Condition('Speech recognition not started', async driver => !(await condition.fn(driver))); | ||
} | ||
|
||
export { negate }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Condition } from 'selenium-webdriver'; | ||
|
||
import hasPendingSpeechSynthesisUtterance from '../pageObjects/hasPendingSpeechSynthesisUtterance'; | ||
|
||
export default function speechSynthesisPending() { | ||
return new Condition('Speech synthesis is pending', async driver => await hasPendingSpeechSynthesisUtterance(driver)); | ||
} | ||
|
||
function negate() { | ||
const condition = speechSynthesisPending(); | ||
|
||
return new Condition('Speech synthesis is not pending', async driver => !(await condition.fn(driver))); | ||
} | ||
|
||
export { negate }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import executePromiseScript from './executePromiseScript'; | ||
|
||
export default async function endSpeechSynthesize(driver) { | ||
return await executePromiseScript(driver, () => window.WebSpeechMock.mockEndSynthesize()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// executeAsyncScript is not running a Promise function and is not able to deal with errors. | ||
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html#executeAsyncScript | ||
// This function will use executeAsyncScript to run a Promise function in an async fashion. | ||
|
||
export default async function executePromiseScript(driver, fn, ...args) { | ||
const { error, result } = await driver.executeAsyncScript( | ||
(fn, args, callback) => { | ||
eval(`(${fn})`) | ||
.apply(null, args) | ||
.then(result => callback({ result }), error => callback({ error })); | ||
}, | ||
fn + '', | ||
args | ||
); | ||
|
||
if (error) { | ||
const err = new Error(error.message); | ||
|
||
err.stack = error.stack; | ||
|
||
throw err; | ||
} else { | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { By } from 'selenium-webdriver'; | ||
|
||
export default async function getMicrophoneButton(driver) { | ||
return await driver.findElement(By.css('[aria-controls="webchatSendBoxMicrophoneButton"] > button')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { By } from 'selenium-webdriver'; | ||
|
||
export default async function isRecognizingSpeech(driver) { | ||
return await driver.findElement(By.css('[role="form"] > * > form > input[type="text"]')); | ||
} |
3 changes: 3 additions & 0 deletions
3
__tests__/setup/pageObjects/hasPendingSpeechSynthesisUtterance.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default async function hasPendingSpeechSynthesisUtterance(driver) { | ||
return await driver.executeScript(() => window.WebSpeechMock.hasPendingUtterance()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default async function isRecognizingSpeech(driver) { | ||
return await driver.executeScript(() => window.WebSpeechMock.isRecognizing()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default async function putSpeechRecognitionResult(driver, ...args) { | ||
await driver.executeScript((...args) => window.WebSpeechMock.mockRecognize(...args), ...args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default async function startSpeechSynthesize(driver) { | ||
return await driver.executeScript(() => window.WebSpeechMock.mockStartSynthesize()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.