Improve reliability of E2E tests (#2654)

Co-authored-by: David Marby <david@dmarby.se>
This commit is contained in:
Opender SinghandDavid Marby authored and GitHub committed 2020-09-24 10:49:25 +12:00
1 parent 403ddf20ad
commit 4d17a92f73
4 files changed
+56 -40

No files matched your search

+13 -19
View File
@@ -48,30 +48,23 @@ describe('Application launch', function() {
await debug.workspaceDropdownExists(app);
});
it('creates and sends a request', async () => {
it('sends JSON request', async () => {
const url = 'http://127.0.0.1:4010/pets/1';
await debug.workspaceDropdownExists(app);
const requestName = 'Request from test';
await debug.createNewRequest(app, requestName);
// Ensure first item is the one we created and is selected
const requests = await app.client.$$('.sidebar__item');
const firstRequest = requests[0];
const firstRequestName = await firstRequest.$('span.editable').then(e => e.getText());
const firstRequestClasses = await firstRequest.getAttribute('class');
expect(firstRequestName).toBe(requestName);
expect(firstRequestClasses).toContain('sidebar__item--active');
await debug.typeUrl(app, 'http://127.0.0.1:4010/pets/1');
await debug.createNewRequest(app, 'json');
await debug.typeInUrlBar(app, url);
await debug.clickSendRequest(app);
await debug.expect200(app);
});
it('sends CSV request and shows rich response', async () => {
const url = 'http://127.0.0.1:4010/csv';
await debug.workspaceDropdownExists(app);
await debug.createNewRequest(app);
await debug.typeUrl(app, 'http://127.0.0.1:4010/csv');
await debug.createNewRequest(app, 'csv');
await debug.typeInUrlBar(app, url);
await debug.clickSendRequest(app);
await debug.expect200(app);
@@ -82,10 +75,11 @@ describe('Application launch', function() {
it('sends PDF request and shows rich response', async () => {
// Cannot mock the pdf response using Prism because it is not yet supported
// https://github.com/stoplightio/prism/issues/1248#issuecomment-646056440
const pdfUrl = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf';
const url = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf';
await debug.workspaceDropdownExists(app);
await debug.createNewRequest(app);
await debug.typeUrl(app, pdfUrl);
await debug.createNewRequest(app, 'pdf');
await debug.typeInUrlBar(app, url);
await debug.clickSendRequest(app);
await debug.expect200(app);
+27 -18
View File
@@ -1,8 +1,10 @@
const faker = require('faker');
const workspaceDropdownExists = async (app, workspaceName = 'Insomnia') => {
await app.client.waitUntilTextExists('.workspace-dropdown', workspaceName);
};
const createNewRequest = async (app, name = undefined) => {
const createNewRequest = async (app, name) => {
await app.client.$('.sidebar .dropdown .fa-plus-circle').then(e => e.click());
await app.client
@@ -16,34 +18,41 @@ const createNewRequest = async (app, name = undefined) => {
// Set name and create request
const input = await app.client.$('.modal input');
if (name) {
await input.waitUntil(() => input.isFocused());
await input.keys(name);
}
const requestName = `${name}-${faker.lorem.slug()}`;
await input.waitUntil(() => input.isFocused());
await input.keys(requestName);
await app.client
.$('.modal .modal__footer')
.then(e => e.$('button=Create'))
.then(e => e.click());
await waitUntilRequestIsActive(app, requestName);
};
const typeUrl = async (app, url) => {
const urlEditor = await app.client.$('.urlbar .editor .input');
await typeCodeMirror(app, urlEditor, url, 500);
const waitUntilRequestIsActive = async (app, name) => {
const requestIsActive = async () => {
const requests = await app.client.react$$('SidebarRequestRow', { props: { isActive: true } });
const firstRequest = requests[0];
const activeRequestName = await firstRequest.react$('Editable').then(e => e.getText());
return activeRequestName === name;
};
await app.client.waitUntil(requestIsActive);
};
const typeCodeMirror = async (app, element, value, debounceWait) => {
await element.click();
const cm = await element.$('.CodeMirror');
await cm.waitForExist();
await cm.keys(value);
// Wait for the code-editor debounce
await app.client.pause(debounceWait);
const typeInUrlBar = async (app, url) => {
const urlEditor = await app.client.react$('RequestUrlBar');
await urlEditor.waitForExist();
await urlEditor.click();
await urlEditor.keys(url);
};
const clickSendRequest = async app => {
await app.client.$('.urlbar__send-btn').then(e => e.click());
await app.client
.react$('RequestUrlBar')
.then(e => e.$('.urlbar__send-btn'))
.then(e => e.click());
};
const expect200 = async app => {
@@ -69,7 +78,7 @@ const getPdfCanvas = async app => {
module.exports = {
workspaceDropdownExists,
createNewRequest,
typeUrl,
typeInUrlBar,
clickSendRequest,
expect200,
getCsvViewer,
+15 -3
View File
@@ -821,6 +821,12 @@
"uri-template-lite": "^20.5.0"
},
"dependencies": {
"faker": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/faker/-/faker-4.1.0.tgz",
"integrity": "sha1-HkW7vsxndLPBlfrSg1EJxtdIzD8=",
"dev": true
},
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
@@ -2884,9 +2890,9 @@
"dev": true
},
"faker": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/faker/-/faker-4.1.0.tgz",
"integrity": "sha1-HkW7vsxndLPBlfrSg1EJxtdIzD8=",
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/faker/-/faker-5.1.0.tgz",
"integrity": "sha512-RrWKFSSA/aNLP0g3o2WW1Zez7/MnMr7xkiZmoCfAGZmdkDQZ6l2KtuXHN5XjdvpRjDl8+3vf+Rrtl06Z352+Mw==",
"dev": true
},
"fast-deep-equal": {
@@ -5974,6 +5980,12 @@
"uuid": "3.4.0"
},
"dependencies": {
"faker": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/faker/-/faker-4.1.0.tgz",
"integrity": "sha1-HkW7vsxndLPBlfrSg1EJxtdIzD8=",
"dev": true
},
"iconv-lite": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.2.tgz",
@@ -18,6 +18,7 @@
"@stoplight/prism-cli": "^3.3.6",
"concurrently": "^5.3.0",
"cross-env": "^7.0.2",
"faker": "^5.1.0",
"jest": "^26.4.2",
"spectron": "^11.1.0",
"spectron-keys": "0.0.1",