Skip to content

Commit

Permalink
Add e2e tests for a non-legacy ZIM archive #1042 (#1049)
Browse files Browse the repository at this point in the history
Signed off by @RG7279805
  • Loading branch information
Rishabhg71 authored Aug 22, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e6665ec commit 6689b8a
Showing 8 changed files with 412 additions and 19 deletions.
8 changes: 5 additions & 3 deletions tests/chromium.e2e.runner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Builder } from 'selenium-webdriver';
import { Options } from 'selenium-webdriver/chrome.js';
import legacyRayCharles from './legacy-ray_charles.e2e.spec.js';
import gutenbergRo from './gutenberg_ro.e2e.spec.js';
import paths from './paths.js';

/* eslint-disable camelcase */

@@ -10,13 +12,13 @@ async function loadChromiumDriver () {
if (process.env.GITHUB_ACTIONS) {
options.addArguments('--headless=new');
}
options.setUserPreferences({ 'download.default_directory': paths.downloadDir });
const driver = await new Builder(options)
.forBrowser('chrome')
.setChromeOptions(options)
.build();
return driver;
};

const driver_chrome = await loadChromiumDriver();

legacyRayCharles.runTests(driver_chrome);
legacyRayCharles.runTests(await loadChromiumDriver());
gutenbergRo.runTests(await loadChromiumDriver());
11 changes: 8 additions & 3 deletions tests/firefox.e2e.runner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Builder } from 'selenium-webdriver';
import firefox from 'selenium-webdriver/firefox.js';
import legacyRayCharles from './legacy-ray_charles.e2e.spec.js';
import gutenbergRo from './gutenberg_ro.e2e.spec.js';
import paths from './paths.js';

/* eslint-disable camelcase */

@@ -10,13 +12,16 @@ async function loadFirefoxDriver () {
if (process.env.GITHUB_ACTIONS) {
options.headless();
}
options.setPreference('browser.download.folderList', 2);
options.setPreference('browser.download.dir', paths.downloadDir);
options.setPreference('browser.download.manager.showWhenStarting', false);
options.setPreference('browser.helperApps.neverAsk.saveToDisk', 'octet-stream');
const driver = await new Builder(options)
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
return driver;
};

const driver_fx = await loadFirefoxDriver();

legacyRayCharles.runTests(driver_fx);
legacyRayCharles.runTests(await loadFirefoxDriver());
gutenbergRo.runTests(await loadFirefoxDriver());
366 changes: 366 additions & 0 deletions tests/gutenberg_ro.e2e.spec.js

Large diffs are not rendered by default.

Binary file added tests/gutenberg_ro_all_2023-05.zim
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/ieMode.e2e.runner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Builder } from 'selenium-webdriver';
import { Options } from 'selenium-webdriver/ie.js';
import legacyRayCharles from './legacy-ray_charles.e2e.spec.js';
import gutenbergRo from './gutenberg_ro.e2e.spec.js';

/* eslint-disable camelcase */

@@ -15,6 +16,5 @@ async function loadIEModeDriver () {
return driver;
};

const driver_ie = await loadIEModeDriver();

legacyRayCharles.runTests(driver_ie);
legacyRayCharles.runTests(await loadIEModeDriver());
gutenbergRo.runTests(await loadIEModeDriver(), ['jquery']);
18 changes: 12 additions & 6 deletions tests/legacy-ray_charles.e2e.spec.js
Original file line number Diff line number Diff line change
@@ -19,11 +19,11 @@
* You should have received a copy of the GNU General Public License
* along with Kiwix (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
*/

import { By, Key } from 'selenium-webdriver';
// eslint-disable-next-line no-unused-vars
import { By, Key, WebDriver } from 'selenium-webdriver';
// import firefox from 'selenium-webdriver/firefox.js';
import assert from 'assert';
import path from 'path';
import paths from './paths.js';

/* eslint-disable camelcase, one-var, prefer-const */
/* global describe, it */
@@ -37,7 +37,7 @@ const BROWSERSTACK = !!process.env.BROWSERSTACK_LOCAL_IDENTIFIER;
const port = process.env.BROWSERSTACK_LOCAL_IDENTIFIER ? '8099' : '8080';

// Set the archives to load
let rayCharlesBaseFile = path.resolve('./tests/wikipedia_en_ray_charles_2015-06.zimaa');
let rayCharlesBaseFile = paths.rayCharlesBaseFile;
// For BrowserStack, we have to construct the file blops with XHR instead
if (BROWSERSTACK) {
rayCharlesBaseFile = '/tests/wikipedia_en_ray_charles_2015-06.zimaa';
@@ -54,6 +54,12 @@ for (let i = 0; i < 15; i++) {
}
console.log('\nLoading archive:\n' + rayCharlesAllParts + '\n');

/**
* Run the tests
* @param {WebDriver} driver Selenium WebDriver object
* @param {array} modes Array of modes to run the tests in
* @returns {Promise<void>} A Promise for the completion of the tests
*/
function runTests (driver, modes) {
let browserName, browserVersion;
driver.getCapabilities().then(function (caps) {
@@ -187,7 +193,7 @@ function runTests (driver, modes) {
} else {
// Skip remaining SW mode tests if the browser does not support the SW API
console.log('\x1b[33m%s\x1b[0m', ' Skipping SW mode tests...');
await driver.quit();
return driver.quit();
}
});
});
@@ -302,7 +308,7 @@ function runTests (driver, modes) {
assert.equal('Ray Charles', title);
// If we have reached the last mode, quit the driver
if (mode === modes[modes.length - 1]) {
await driver.quit();
return driver.quit();
}
});
});
7 changes: 3 additions & 4 deletions tests/microsoftEdge.e2e.runner.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Builder } from 'selenium-webdriver';
import { Options } from 'selenium-webdriver/edge.js';
import legacyRayCharles from './legacy-ray_charles.e2e.spec.js';

import gutenbergRo from './gutenberg_ro.e2e.spec.js';
/* eslint-disable camelcase */

async function loadMSEdgeDriver () {
@@ -17,6 +17,5 @@ async function loadMSEdgeDriver () {
return driver;
};

const driver_edge = await loadMSEdgeDriver();

legacyRayCharles.runTests(driver_edge);
legacyRayCharles.runTests(await loadMSEdgeDriver());
gutenbergRo.runTests(await loadMSEdgeDriver());
15 changes: 15 additions & 0 deletions tests/paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* paths.js : Singleton object that contains the paths to the files used in the tests.
*/

import path from 'path';

const rayCharlesBaseFile = path.resolve('./tests/wikipedia_en_ray_charles_2015-06.zimaa');
const gutenbergRoBaseFile = path.resolve('./tests/gutenberg_ro_all_2023-05.zim');
const downloadDir = path.resolve('./tests/');

export default {
rayCharlesBaseFile: rayCharlesBaseFile,
gutenbergRoBaseFile: gutenbergRoBaseFile,
downloadDir: downloadDir
};

0 comments on commit 6689b8a

Please sign in to comment.