Skip to content
This repository was archived by the owner on Apr 30, 2023. It is now read-only.

Commit 297ec46

Browse files
authored
Merge pull request #289 from ukalifon/download-with-chrome
Download with Chrome
2 parents a642961 + 3b066e7 commit 297ec46

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

Diff for: cypress/integration-qe/e2e-createNewCluster.spec.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { CLUSTER_NAME, PULL_SECRET, SSH_PUB_KEY, createCluster, generateIso } from './shared';
1+
import {
2+
CLUSTER_NAME,
3+
PULL_SECRET,
4+
SSH_PUB_KEY,
5+
createCluster,
6+
generateIso,
7+
downloadFileWithChrome,
8+
} from './shared';
29

310
describe('Flow', () => {
411
it('start from the /clusters page', () => {
@@ -14,4 +21,12 @@ describe('Flow', () => {
1421
it('generate the ISO', () => {
1522
generateIso(SSH_PUB_KEY);
1623
});
24+
25+
it('download the ISO', () => {
26+
cy.get('#button-download-discovery-iso').click(); // open the dialog
27+
cy.get('.pf-c-modal-box__footer > .pf-m-primary').click(); // "Get Discovery ISO"
28+
downloadFileWithChrome('button[data-test-id="download-iso-btn"]', ' ~/Downloads/cluster-*.iso');
29+
cy.get('button[data-test-id="close-iso-btn"]').click(); // now close the dialog
30+
cy.exec('mv -f ~/Downloads/cluster-*.iso /var/lib/libvirt/images/cluster-discovery.iso');
31+
});
1732
});

Diff for: cypress/integration-qe/e2e-enterClusterSpecs.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
openCluster,
1010
startClusterInstallation,
1111
waitForClusterInstallation,
12+
downloadFileWithChrome,
1213
} from './shared';
1314

1415
import {
@@ -104,3 +105,13 @@ describe('Run install', () => {
104105
waitForClusterInstallation();
105106
});
106107
});
108+
109+
describe('Donwload kubeconfig', () => {
110+
it('download kubeconfig', () => {
111+
downloadFileWithChrome(
112+
'div.pf-l-grid__item > button.pf-c-button.pf-m-secondary',
113+
'~/Downloads/kubeconfig',
114+
);
115+
cy.exec('mv -f ~/Downloads/kubeconfig ~');
116+
});
117+
});

Diff for: cypress/integration/constants.js

+4
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ export const HOST_DISCOVERY_TIMEOUT = 30 * 1000;
88
export const VALIDATE_CHANGES_TIMEOUT = 10 * 1000;
99
// timeout for install preparation - 1 minute
1010
export const INSTALL_PREPARATION_TIMEOUT = 60 * 1000;
11+
// timeout for generating ISO
12+
export const GENERATE_ISO_TIMEOUT = 2 * 60 * 1000;
13+
// timeout for downloading files (such as ISO images)
14+
export const FILE_DOWNLOAD_TIMEOUT = 10 * 60 * 1000;
1115
// timeout for cluster instation to finish - 1 hour
1216
export const CLUSTER_CREATION_TIMEOUT = 60 * 60 * 1000;

Diff for: cypress/integration/shared.js

+26-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
CLUSTER_CREATION_TIMEOUT,
66
HOST_DISCOVERY_TIMEOUT,
77
HOST_REGISTRATION_TIMEOUT,
8+
FILE_DOWNLOAD_TIMEOUT,
89
} from './constants';
910

1011
export const testInfraClusterName = 'test-infra-cluster';
@@ -127,7 +128,8 @@ export const generateIso = (sshPubKey) => {
127128
cy.get('.pf-c-modal-box__footer > .pf-m-primary').click();
128129
// cy.get('.pf-c-modal-box__footer > .pf-m-primary', { timeout: 5 * 60 * 1000 });
129130
// bug: cy.get() timeout is ignored since former inner XHR is aborted by Cypress
130-
cy.wait(90 * 1000).then(() => {
131+
// using constant GENERATE_ISO_TIMEOUT causes a lint crash https://github.com/cypress-io/eslint-plugin-cypress/issues/43
132+
cy.wait(2 * 60 * 1000).then(() => {
131133
// yield potentially onAnyAbort()
132134
if (aborted) {
133135
cy.log('Long-running XHR was aborted');
@@ -139,9 +141,30 @@ export const generateIso = (sshPubKey) => {
139141
} else {
140142
cy.log('Waiting for ISO was successful');
141143
}
142-
cy.get('.pf-c-modal-box__footer > .pf-m-primary').contains('Download Discovery ISO');
143144
});
144-
cy.get('#pf-modal-part-7 > footer > button.pf-c-button.pf-m-secondary').click(); // now close the dialog
145+
cy.get('button[data-test-id="download-iso-btn"]', { timeout: 2 * 60 * 1000 }).contains(
146+
'Download Discovery ISO',
147+
);
148+
cy.get('button[data-test-id="close-iso-btn"]').click(); // now close the dialog
149+
};
150+
151+
export const downloadFileWithChrome = (downloadButton, resultantFilename) => {
152+
// NOTE: This works only with Chrome, where the default behavior is:
153+
// 1) It starts the download without popping up a save dialog (which would require automating native windows)
154+
// 2) It caches to a temporary location, and when the download is complete it moves the file to ~/Downloads
155+
156+
// first delete old downloads
157+
cy.exec(`[ -f ${resultantFilename} ] && rm -rf ${resultantFilename}`, {
158+
failOnNonZeroExit: false,
159+
});
160+
cy.get(downloadButton).click();
161+
162+
// wait until the file shows up, to know that the download finshed
163+
cy.exec(`while [ ! -f ${resultantFilename} ]; do sleep 1; done`, {
164+
timeout: FILE_DOWNLOAD_TIMEOUT,
165+
}).should((result) => {
166+
expect(result.code).to.be.eq(0);
167+
});
145168
};
146169

147170
export const assertTestClusterPresence = (cy) => {

0 commit comments

Comments
 (0)