diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 92811cedb1fad95a05865e51acd895e050f929ce..e00eb59e20f0cd4bfd3d12c351803c6e1095bebc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -71,11 +71,6 @@ install: test: stage: test - only: - - tags - - schedules - - web - - master script: - npm run e2e diff --git a/e2e/load-save-session.e2e-spec.ts b/e2e/load-save-session.e2e-spec.ts index 8689c6f13a7510026cff21608aefa1ff663ee5cd..b565723752ae37daed7b3f2a299c49536908b7a7 100644 --- a/e2e/load-save-session.e2e-spec.ts +++ b/e2e/load-save-session.e2e-spec.ts @@ -18,16 +18,35 @@ let navbar: Navbar; let sidenav: SideNav; let prefPage: PreferencesPage; -async function saveSession(): Promise<string> { - await calcPage.clickSaveCalcButton(); - await browser.sleep(500); +function findDownloadedFile(filename: string): string { + const downloadDirs = ["Téléchargements", "Downloads", "/tmp"]; + for (const d of downloadDirs) { + const download_prefix = d.charAt(0) === "/" ? d : path.resolve(os.homedir(), d); + const fp = path.resolve(download_prefix, filename); + if (fs.existsSync(fp)) { + return fp; + } + } +} +function deleteDownloadedFile(filename: string) { // see: https://stackoverflow.com/questions/21935696/protractor-e2e-test-case-for-downloading-pdf-file - const filename = path.resolve(os.homedir(), "Téléchargements/session.json"); - if (fs.existsSync(filename)) { + const fp = findDownloadedFile(filename); + if (fp !== undefined) { // Make sure the browser doesn't have to rename the download. - fs.unlinkSync(filename); + fs.unlinkSync(fp); } +} + +async function saveSession(): Promise<string> { + const sessionFile = "session.json"; + deleteDownloadedFile(sessionFile); + + await calcPage.clickSaveCalcButton(); + await browser.sleep(500); + + // cf. protractor.conf.fs, exports.config.capabilities.chromeOptions.prefs.download.default_directory + // protractor.conf.fs/exports.config.capabilities.chromeOptions.prefs.download.default_directory DOES NOT WORK ! // Le code laissé en commentaire tente de corriger un bug : // il s'écoule 40 secondes entre le clic sur le bouton menu (en haut à gauche) et l'ouverture du sidenav. @@ -63,7 +82,8 @@ async function saveSession(): Promise<string> { // browser.actions().sendKeys(protractor.Key.ESCAPE).perform(); - return filename; + console.log("saveSession() saved to ", findDownloadedFile(sessionFile)); + return findDownloadedFile(sessionFile); } async function loadSession(path: string) { @@ -125,13 +145,14 @@ describe("ngHyd − save and load sessions", () => { await changeSelectValue(calcPage.getSelectById("select_section"), 2); // mode "trapezoidal" await calcPage.getInputById("Ks").clear(); // coefficient de Strickler - await browser.sleep(1000); + await browser.sleep(200); await calcPage.getInputById("Ks").sendKeys("42"); - await browser.sleep(1000); + await browser.sleep(200); const filename = await saveSession(); - await browser.sleep(1000); + await browser.sleep(500); const fileContent = fs.readFileSync(filename, { encoding: "utf8" }); + await browser.sleep(200); expect(fileContent).toContain(`"nodeType":"SectionTrapeze"`); expect(fileContent).toContain(`{"symbol":"Ks","mode":"SINGLE","value":42}`);