Skip to content
Snippets Groups Projects
Commit 83aaf874 authored by François Grand's avatar François Grand
Browse files

fix(e2e): test fails due to bad path

refs #608
parent 8decbc4d
No related branches found
No related tags found
2 merge requests!225Release v4.17.0,!211Resolve "Documentation: Les formules de math ne s'affichent pas dans la version anglaise"
......@@ -71,11 +71,6 @@ install:
test:
stage: test
only:
- tags
- schedules
- web
- master
script:
- npm run e2e
......
......@@ -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}`);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment