Skip to content

Commit

Permalink
Improve test reliability (#2777)
Browse files Browse the repository at this point in the history
* Use driver.wait for condition

* Use global timeout values

* Wait until button is hid

* Wait for button visibility before taking screenshot

* Update minNumActivitiesShown

* Wait for scroll to bottom button visibility

* Typo

* Wait until language change

* Do 5 consecutive checks

* Add entry

* Fix tests

* Use another timeout for images

* Update entry

* Update __tests__/setup/conditions/scrollToBottomCompleted.js

Co-Authored-By: Corina <14900841+corinagum@users.noreply.github.com>

* Rename to negationOf

Co-authored-by: Corina <14900841+corinagum@users.noreply.github.com>
  • Loading branch information
compulim and corinagum committed Dec 29, 2019
1 parent 31c2006 commit 3c78937
Show file tree
Hide file tree
Showing 29 changed files with 144 additions and 100 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [`abort-controller`](https://npmjs.com/package/abort-controller)
- [`event-target-shim`](https://npmjs.com/package/event-target-shim)
- [`p-defer`](https://npmjs.com/package/p-defer)
- Fixes the following issues and improves test reliability, by [@compulim](https://github.com/compulim) in PR [#XXX](https://github.com/microsoft/BotFramework-WebChat/pull/XXX)
- Fixes [#2612](https://github.com/microsoft/BotFramework-WebChat/issues/2612). Wait until language change
- Fixes [#2653](https://github.com/microsoft/BotFramework-WebChat/issues/2653). Scroll-to-bottom check will do 5 consecutive checks to determine stickiness.
- Fixes [#2691](https://github.com/microsoft/BotFramework-WebChat/issues/2691). Wait until button is shown/hid before taking screenshot
- Fixes [#2737](https://github.com/microsoft/BotFramework-WebChat/issues/2737). Use `driver.wait` for conditions
- Fixes [#2776](https://github.com/microsoft/BotFramework-WebChat/issues/2776). Wait until button is shown/hid before taking screenshot
- Use a new timeout `fetchImage` for images

### Changed

Expand Down
8 changes: 4 additions & 4 deletions __tests__/adaptiveCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('breakfast card', async () => {
await pageObjects.sendMessageViaSendBox('card breakfast', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand All @@ -40,7 +40,7 @@ test('breakfast card with custom host config', async () => {
await pageObjects.sendMessageViaSendBox('card breakfast', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand All @@ -60,7 +60,7 @@ test('breakfast card with custom style options', async () => {
await pageObjects.sendMessageViaSendBox('card breakfast', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand All @@ -74,7 +74,7 @@ test('disable card inputs', async () => {
await pageObjects.sendMessageViaSendBox('card inputs', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);
await driver.wait(scrollToBottomCompleted(), timeouts.scrollToBottom);

await driver.executeScript(() => {
Expand Down
16 changes: 8 additions & 8 deletions __tests__/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('setup', async () => {
await pageObjects.sendMessageViaSendBox('layout carousel', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand All @@ -33,7 +33,7 @@ test('long URLs with break-word', async () => {
);

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand All @@ -52,7 +52,7 @@ test('long URLs with break-all', async () => {
);

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand All @@ -69,7 +69,7 @@ test('long URLs with keep-all', async () => {
});

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand All @@ -96,7 +96,7 @@ test('hero card with a long title and richCardWrapTitle set to true', async () =
await pageObjects.sendMessageViaSendBox('herocard long title', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand All @@ -110,7 +110,7 @@ test('hero card with a long title and richCardWrapTitle set to default value', a
await pageObjects.sendMessageViaSendBox('herocard long title', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand All @@ -124,7 +124,7 @@ test('thumbnail card with a long title and richCardWrapTitle set to true', async
await pageObjects.sendMessageViaSendBox('thumbnailcard long title', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand All @@ -138,7 +138,7 @@ test('thumbnail card with a long title and richCardWrapTitle set to default valu
await pageObjects.sendMessageViaSendBox('thumbnailcard long title', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), 2000);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand Down
1 change: 0 additions & 1 deletion __tests__/bubbleBorder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { imageSnapshotOptions, timeouts } from './constants.json';

import allImagesLoaded from './setup/conditions/allImagesLoaded';
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
import uiConnected from './setup/conditions/uiConnected';

Expand Down
2 changes: 1 addition & 1 deletion __tests__/bubbleNub.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function sendMessageAndMatchSnapshot(driver, pageObjects, message) {
await pageObjects.sendMessageViaSendBox(message);

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

const base64PNG = await driver.takeScreenshot();

Expand Down
6 changes: 4 additions & 2 deletions __tests__/cardActionMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import uiConnected from './setup/conditions/uiConnected';
// selenium-webdriver API doc:
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html

jest.setTimeout(timeouts.test);

test('card action "openUrl"', async () => {
const { driver, pageObjects } = await setupWebDriver({
props: {
Expand Down Expand Up @@ -42,7 +44,7 @@ test('card action "openUrl"', async () => {
const base64PNG = await driver.takeScreenshot();

expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions);
}, 60000);
});

test('card action "signin"', async () => {
const { driver, pageObjects } = await setupWebDriver({
Expand Down Expand Up @@ -85,4 +87,4 @@ test('card action "signin"', async () => {
const base64PNG = await driver.takeScreenshot();

expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions);
}, 60000);
});
24 changes: 12 additions & 12 deletions __tests__/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('carousel without avatar initials', () => {
await pageObjects.sendMessageViaSendBox('carousel', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);

Expand All @@ -43,7 +43,7 @@ describe('carousel without avatar initials', () => {
await pageObjects.sendMessageViaSendBox('layout carousel', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);

Expand All @@ -67,7 +67,7 @@ describe('carousel without avatar initials', () => {
await pageObjects.sendMessageViaSendBox('layout double', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);
});
Expand All @@ -79,7 +79,7 @@ describe('carousel without avatar initials', () => {
await pageObjects.sendMessageViaSendBox('layout double', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);
});
Expand All @@ -91,7 +91,7 @@ describe('carousel without avatar initials', () => {
await pageObjects.sendMessageViaSendBox('layout single carousel', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);
});
Expand All @@ -103,7 +103,7 @@ describe('carousel without avatar initials', () => {
await pageObjects.sendMessageViaSendBox('layout single carousel', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);
});
Expand All @@ -119,7 +119,7 @@ describe('carousel with avatar initials', () => {
await pageObjects.sendMessageViaSendBox('carousel', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);

Expand All @@ -143,7 +143,7 @@ describe('carousel with avatar initials', () => {
await pageObjects.sendMessageViaSendBox('layout carousel', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);

Expand All @@ -167,7 +167,7 @@ describe('carousel with avatar initials', () => {
await pageObjects.sendMessageViaSendBox('layout double', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);
});
Expand All @@ -179,7 +179,7 @@ describe('carousel with avatar initials', () => {
await pageObjects.sendMessageViaSendBox('layout double', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);
});
Expand All @@ -191,7 +191,7 @@ describe('carousel with avatar initials', () => {
await pageObjects.sendMessageViaSendBox('layout single carousel', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);
});
Expand All @@ -203,7 +203,7 @@ describe('carousel with avatar initials', () => {
await pageObjects.sendMessageViaSendBox('layout single carousel', { waitForSend: true });

await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/clockSkew.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('Clock skew', () => {
await driver.executeScript(() => window.WebChatTest.releaseActivity(3));
await driver.wait(minNumActivitiesShown(5), timeouts.directLine);
await driver.wait(allOutgoingActivitiesSent(), timeouts.directLine);
await driver.wait(allImagesLoaded(), timeouts.fetch);
await driver.wait(allImagesLoaded(), timeouts.fetchImage);

expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions);
});
Expand Down
1 change: 1 addition & 0 deletions __tests__/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"timeouts": {
"directLine": 15000,
"fetch": 2500,
"fetchImage": 5000,
"navigation": 10000,
"postActivity": 30000,
"scrollToBottom": 2000,
Expand Down
15 changes: 8 additions & 7 deletions __tests__/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { By, Key } from 'selenium-webdriver';
import { imageSnapshotOptions, timeouts } from './constants.json';
import allOutgoingActivitiesSent from './setup/conditions/allOutgoingActivitiesSent';
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
import negationOf from './setup/conditions/negationOf.js';
import scrollToBottomCompleted from './setup/conditions/scrollToBottomCompleted';
import sendBoxTextBoxFocused from './setup/conditions/sendBoxTextBoxFocused';
import suggestedActionsShown from './setup/conditions/suggestedActionsShown';
Expand All @@ -22,7 +23,7 @@ test('should not focus send box after clicking on send button', async () => {
await pageObjects.typeOnSendBox('echo 123');
await pageObjects.clickSendButton();

await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeFalsy();
await driver.wait(negationOf(sendBoxTextBoxFocused()), timeouts.ui);
});

// Verification of fix of #1971, https://github.com/microsoft/BotFramework-WebChat/issues/1971
Expand All @@ -36,7 +37,7 @@ test('SHOULD focus send box after clicking on suggested actions', async () => {

await pageObjects.clickSuggestedActionButton(0);

await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeTruthy();
await driver.wait(sendBoxTextBoxFocused(), timeouts.ui);
});

// Verification of fix of #1971, https://github.com/microsoft/BotFramework-WebChat/issues/1971
Expand All @@ -47,7 +48,7 @@ test('should focus send box after pressing ENTER to send message', async () => {

await pageObjects.typeOnSendBox('echo 123', Key.RETURN);

await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeTruthy();
await driver.wait(sendBoxTextBoxFocused(), timeouts.ui);
});

describe('type focus sink', () => {
Expand All @@ -60,7 +61,7 @@ describe('type focus sink', () => {

await transcript.click();

await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeFalsy();
await driver.wait(negationOf(sendBoxTextBoxFocused()), timeouts.ui);

await driver
.actions()
Expand Down Expand Up @@ -111,14 +112,14 @@ describe('type focus sink', () => {

await transcript.click();

await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeFalsy();
await driver.wait(negationOf(sendBoxTextBoxFocused()), timeouts.ui);

await driver
.actions()
.sendKeys(Key.SHIFT)
.perform();

await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeFalsy();
await driver.wait(negationOf(sendBoxTextBoxFocused()), timeouts.ui);
});

test('should paste into the send box when focus is on the transcript', async () => {
Expand All @@ -132,7 +133,7 @@ describe('type focus sink', () => {

await transcript.click();

await expect(sendBoxTextBoxFocused().fn(driver)).resolves.toBeFalsy();
await driver.wait(negationOf(sendBoxTextBoxFocused()), timeouts.ui);

await driver
.actions()
Expand Down
8 changes: 4 additions & 4 deletions __tests__/hooks/useLanguage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ test('getter should return language set in props', async () => {
}
});

const [groupTimestamp] = await pageObjects.runHook('useLanguage');
const [language] = await pageObjects.runHook('useLanguage');

expect(groupTimestamp).toMatchInlineSnapshot(`"zh-YUE"`);
expect(language).toMatchInlineSnapshot(`"zh-YUE"`);
});

test('getter should return default language if not set in props', async () => {
const { pageObjects } = await setupWebDriver();

const [groupTimestamp] = await pageObjects.runHook('useLanguage');
const [language] = await pageObjects.runHook('useLanguage');

expect(groupTimestamp).toMatchInlineSnapshot(`"en-US"`);
expect(language).toMatchInlineSnapshot(`"en-US"`);
});

test('setter should be undefined', async () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/hooks/useSendBoxSpeechInterimsVisible.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { timeouts } from '../constants.json';

import negate from '../setup/conditions/negate';
import negationOf from '../setup/conditions/negationOf';
import speechRecognitionStartCalled from '../setup/conditions/speechRecognitionStartCalled';
import speechSynthesisUtterancePended from '../setup/conditions/speechSynthesisUtterancePended';
import uiConnected from '../setup/conditions/uiConnected';
Expand Down Expand Up @@ -73,7 +73,7 @@ test('sendBoxSpeechInterimsVisible should return false when synthesizing', async

await pageObjects.clickMicrophoneButton();

await driver.wait(negate(speechSynthesisUtterancePended()), timeouts.ui);
await driver.wait(negationOf(speechSynthesisUtterancePended()), timeouts.ui);

await expect(
pageObjects.runHook(
Expand Down

0 comments on commit 3c78937

Please sign in to comment.