Skip to content

Commit

Permalink
Fix unstable e2e tests (#3465)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis authored May 12, 2020
1 parent 87d3a1b commit 1f25eed
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 40 deletions.
36 changes: 28 additions & 8 deletions end-to-end-testing-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {executeContextMenuAction} from './articlesList';
import {navigateTo} from './workspace';
import * as path from 'path';

const WAIT_TIMEOUT = 200;

const getTestSelector = (testIds: Array<string> | null = null, text: string | null = null): Locator => {
const selector = (testIds == null ? [] : testIds)
.map((testId) => `[data-test-id="${testId}"]`)
Expand All @@ -29,7 +27,34 @@ export function el(

const elem = byLocator == null ? locator : locator.element(byLocator);

browser.wait(() => elem.isPresent(), WAIT_TIMEOUT);
[
'click',
'sendKeys',
'getTagName',
'getCssValue',
'getAttribute',
'getText',
'getSize',
'getLocation',
'isEnabled',
'isSelected',
'submit',
'clear',
'isDisplayed',
'getId',
'takeScreenshot',
].forEach((methodName) => {
const originalHandler = elem[methodName];

// override methods to wait for an element to be visible
// if the element is already visible, the action will be executed immediately
elem[methodName] = (...args: Array<any>) => {
return browser.wait(ECE.presenceOf(elem), 5000).then(() => {
return originalHandler(...args); // forward arguments
});
};
});

return elem;
}

Expand Down Expand Up @@ -73,11 +98,6 @@ export function hover(elem: ElementFinder) {
browser.actions().mouseMove(elem).perform();
}

export function waitAndClick(elem: ElementFinder) {
browser.wait(ECE.visibilityOf(elem));
elem.click();
}

export function selectFilesForUpload(
fileInput: ElementFinder,
fileNames: Array<string>, // relative to spec/test-files folder
Expand Down
2 changes: 1 addition & 1 deletion end-to-end-testing-helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "end-to-end-testing-helpers",
"version": "1.0.5",
"version": "1.0.6",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"docs-soap": "github:tomaskikutis/docs-soap#convert-tables",
"draft-js": "github:tomaskikutis/draft-js#add-subscript-superscript",
"draft-js-export-html": "1.3.3",
"end-to-end-testing-helpers": "^1.0.5",
"end-to-end-testing-helpers": "1.0.6",
"eslint": "6.6.0",
"eslint-plugin-react": "7.16.0",
"extract-text-webpack-plugin": "3.0.2",
Expand Down Expand Up @@ -164,7 +164,7 @@
"build": "grunt build",
"lint": "tsc -p scripts --noEmit && tslint -c tslint.json './**/*.{ts,tsx}' && eslint --parser=@typescript-eslint/parser --ext .js --ext .jsx --ext .ts --ext .tsx scripts spec tasks *.js",
"lint-fix": "tsc -p scripts --noEmit && tslint --fix -c tslint.json 'scripts/**/*.{ts,tsx}' && eslint --fix --parser=@typescript-eslint/parser --ext .js --ext .jsx --ext .ts --ext .tsx scripts spec tasks *.js",
"start-test-server": "cd test-server && docker-compose up -d",
"start-test-server": "cd test-server && docker-compose build && docker-compose up -d",
"stop-test-server": "cd test-server && docker-compose stop",
"start-client-server": "http-server dist -p 9000 -s &",
"stop-client-server": "fuser -k 9000/tcp",
Expand Down
2 changes: 1 addition & 1 deletion scripts/extensions/markForUser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"devDependencies": {
"@types/jasmine": "2.8.9",
"@types/react": "16.8.23",
"end-to-end-testing-helpers": "^1.0.3",
"end-to-end-testing-helpers": "1.0.6",
"superdesk-code-style": "1.3.0",
"typescript": "3.7.2"
},
Expand Down
3 changes: 1 addition & 2 deletions spec/_unstable-tests.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
content can open package using hotkey ctrl+0
editor3 ctrl+z on tables mantains cursor position in the middle
monitoring can close already opened preview on an item action
editor3 can edit body with toolbar
monitoring can display the item in Desk Output when it's published in a production desk
authoring related item widget can open published item
send warns that there are spelling mistakes
Not modifying crops will not trigger an article change
master_desk show content view - edit item
8 changes: 4 additions & 4 deletions spec/authoring_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {dictionaries} from './helpers/dictionaries';
import {workspace} from './helpers/workspace';
import {authoring} from './helpers/authoring';

import {el, ECE, els, waitAndClick, hover, selectFilesForUpload} from 'end-to-end-testing-helpers';
import {el, ECE, els, hover, selectFilesForUpload} from 'end-to-end-testing-helpers';

describe('authoring', () => {
beforeEach(() => {
Expand Down Expand Up @@ -706,7 +706,7 @@ describe('authoring', () => {

el(['multi-image-edit--start-upload']).click();

waitAndClick(el(['change-image', 'done']));
el(['change-image', 'done']).click();

assertToastMsg('success', 'Item updated.');
waitForToastMsgDissapear('success', 'Item updated.');
Expand Down Expand Up @@ -739,7 +739,7 @@ describe('authoring', () => {

el(['multi-image-edit--start-upload']).click();

waitAndClick(el(['change-image', 'done']));
el(['change-image', 'done']).click();

browser.wait(ECE.hasElementCount(els(['authoring-field--media-gallery', 'media-gallery-image']), 1));
});
Expand All @@ -764,7 +764,7 @@ describe('authoring', () => {

el(['multi-image-edit--start-upload']).click();

waitAndClick(el(['change-image', 'done']));
el(['change-image', 'done']).click();

browser.wait(ECE.hasElementCount(els(['authoring-field--media-gallery', 'media-gallery-image']), 1));

Expand Down
11 changes: 8 additions & 3 deletions spec/editor3_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {element, browser, protractor, by} from 'protractor';

import {monitoring} from './helpers/monitoring';
import {authoring} from './helpers/authoring';
import {ECE, el} from 'end-to-end-testing-helpers';
import {assertToastMsg} from './helpers/utils';

class Editor3Toolbar {
controls: any;
Expand Down Expand Up @@ -56,6 +58,7 @@ describe('editor3', () => {
monitoring.openMonitoring();
monitoring.selectDesk('xeditor3');
monitoring.createFromDeskTemplate();
browser.wait(ECE.presenceOf(editors.get(0)));
});

it('can edit headline', () => {
Expand Down Expand Up @@ -152,9 +155,11 @@ describe('editor3', () => {
});

function getPreviewBody() {
browser.sleep(1000); // wait for autosave (input is debounced)
authoring.save();
browser.sleep(500); // wait for saving to complete
const saveButton = el(['authoring', 'authoring-topbar', 'save']);

browser.wait(ECE.elementToBeClickable(saveButton));
saveButton.click();
assertToastMsg('success', 'Item updated.');
monitoring.previewAction(0, 0);
return monitoring.getPreviewBody();
}
Expand Down
22 changes: 5 additions & 17 deletions spec/internal_destinations_spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable newline-per-chained-call */

import {browser, element, by} from 'protractor';
import {el, els, s, ECE} from 'end-to-end-testing-helpers';
import {el, els, s, ECE, hover} from 'end-to-end-testing-helpers';
import {nav} from './helpers/utils';

describe('internal destinations & generic-page-list', () => {
Expand Down Expand Up @@ -33,10 +33,7 @@ describe('internal destinations & generic-page-list', () => {

var firstItem = items.get(0);

// hover in order for action buttons to show up
browser.actions()
.mouseMove(firstItem)
.perform();
hover(firstItem); // in order for action buttons to show up

el(['edit'], null, firstItem).click();

Expand Down Expand Up @@ -71,10 +68,7 @@ describe('internal destinations & generic-page-list', () => {

browser.wait(ECE.textToBePresentInElementValue(el(['list-page--view-edit', 'gform-input--name']), 'alpha'));

// hover in order for action buttons to show up
browser.actions()
.mouseMove(items.get(1))
.perform();
hover(items.get(1)); // in order for action buttons to show up

el(['edit'], null, items.get(1)).click();

Expand All @@ -93,10 +87,7 @@ describe('internal destinations & generic-page-list', () => {

var firstItem = items.get(0);

// hover in order for action buttons to show up
browser.actions()
.mouseMove(firstItem)
.perform();
hover(firstItem); // in order for action buttons to show up

el(['delete'], null, firstItem).click();

Expand All @@ -111,10 +102,7 @@ describe('internal destinations & generic-page-list', () => {

var firstItem = items.get(0);

// hover in order for action buttons to show up
browser.actions()
.mouseMove(firstItem)
.perform();
hover(firstItem); // in order for action buttons to show up

el(['delete'], null, firstItem).click();

Expand Down
4 changes: 2 additions & 2 deletions spec/publishing_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import {monitoring} from './helpers/monitoring';
import {workspace} from './helpers/workspace';
import {authoring} from './helpers/authoring';
import {el, els, waitAndClick, ECE, s} from 'end-to-end-testing-helpers';
import {el, els, ECE} from 'end-to-end-testing-helpers';
import {executeContextMenuAction} from 'end-to-end-testing-helpers/dist/articlesList';

describe('publishing', () => {
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('publishing', () => {
const slugline = 'testing-send-and-publish';

el(['authoring', 'field-slugline']).sendKeys(slugline);
waitAndClick(el(['authoring', 'save']));
el(['authoring', 'save']).click();

el(['authoring', 'open-send-publish-pane']).click();
el(['authoring', 'send-publish-pane', 'tab--publish']).click();
Expand Down

0 comments on commit 1f25eed

Please sign in to comment.