mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-08-03 19:27:11 -04:00
parent
bc820aff38
commit
e846b3e07a
@ -255,9 +255,15 @@ function runTests (driver, modes, keepDriver) {
|
|||||||
}, 10000, 'Content inside iframe did not load');
|
}, 10000, 'Content inside iframe did not load');
|
||||||
|
|
||||||
// Locate the article link and get its text
|
// Locate the article link and get its text
|
||||||
const text = await driver.wait(async function () {
|
let text;
|
||||||
const articleLink = await driver.findElement(By.xpath('/html/body/div/div/ul/li[77]/a[2]'));
|
await driver.wait(async function () {
|
||||||
return await articleLink.getText();
|
try {
|
||||||
|
const articleLink = await driver.findElement(By.xpath('/html/body/div/div/ul/li[77]/a[2]'));
|
||||||
|
text = await articleLink.getText();
|
||||||
|
return text && text.length > 0;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}, 6000);
|
}, 6000);
|
||||||
|
|
||||||
// Assert that the text matches the expected value
|
// Assert that the text matches the expected value
|
||||||
@ -302,10 +308,11 @@ function runTests (driver, modes, keepDriver) {
|
|||||||
await driver.sleep(2000);
|
await driver.sleep(2000);
|
||||||
// Focus on the next link "A Fool for You" with id="mwWw"
|
// Focus on the next link "A Fool for You" with id="mwWw"
|
||||||
await driver.executeScript('document.getElementById("mwWw").focus();');
|
await driver.executeScript('document.getElementById("mwWw").focus();');
|
||||||
// Wait for the popover to appear
|
// Wait for the popover to appear with expected text
|
||||||
await driver.sleep(2500); // DEV: Adjust this delay if failing on older, slower browsers
|
let popover = await driver.wait(async function () {
|
||||||
// Use standard JavaScript methods to find the popover element because Safari 14 fails when using WebDriver methods
|
const tooltip = await driver.executeScript('return document.querySelector(".kiwixtooltip") ? document.querySelector(".kiwixtooltip").outerHTML : null;');
|
||||||
let popover = await driver.executeScript('return document.querySelector(".kiwixtooltip").outerHTML;');
|
return tooltip && /bluesy/.test(tooltip) ? tooltip : false;
|
||||||
|
}, 10000, 'Popover with "bluesy" text did not appear');
|
||||||
// The popover should contain the word "bluesy" (description of style of song)
|
// The popover should contain the word "bluesy" (description of style of song)
|
||||||
let popoverContainsText = /bluesy/.test(popover);
|
let popoverContainsText = /bluesy/.test(popover);
|
||||||
assert.ok(popoverContainsText, 'Popover div with class ".kiwixtooltip" did not have expected text "bluesy"');
|
assert.ok(popoverContainsText, 'Popover div with class ".kiwixtooltip" did not have expected text "bluesy"');
|
||||||
@ -321,19 +328,24 @@ function runTests (driver, modes, keepDriver) {
|
|||||||
const prefix = await driver.findElement(By.id('prefix'));
|
const prefix = await driver.findElement(By.id('prefix'));
|
||||||
// Search by setting the value of the prefix element using JavaScript
|
// Search by setting the value of the prefix element using JavaScript
|
||||||
await driver.executeScript('arguments[0].value = "Ray"; document.getElementById("searchArticles").click();', prefix);
|
await driver.executeScript('arguments[0].value = "Ray"; document.getElementById("searchArticles").click();', prefix);
|
||||||
// Wait for at least four results to appear
|
// Wait for search results to appear and find Ray Charles entry
|
||||||
await driver.sleep(500);
|
|
||||||
await driver.findElement(By.css('.list-group-item:nth-child(4)'));
|
|
||||||
// Check the contents of the result and Add the hover attribute to it so we can select it with the keyboard
|
|
||||||
await driver.wait(async function () {
|
await driver.wait(async function () {
|
||||||
// NB dispatchEvent for keydown does not work in IE, so we do this later using WebDriver methods
|
try {
|
||||||
// const found = await driver.executeScript('return new Promise(function (resolve) { setTimeout(function () { var found = false; var el = document.querySelector(".list-group-item:nth-child(4)"); found = el.innerText === "Ray Charles"; el.scrollIntoView(false); el.classList.add("hover"); document.getElementById("prefix").dispatchEvent(new KeyboardEvent("keydown", {"key": "Enter"})); resolve(found); }, 1000); });');
|
// Wait for at least 4 results to appear
|
||||||
const found = await driver.executeScript('var found = false; var el = document.querySelector(".list-group-item:nth-child(4)"); found = el.innerText === "Ray Charles"; el.scrollIntoView(false); el.classList.add("hover"); return found;');
|
await driver.findElement(By.css('.list-group-item:nth-child(4)'));
|
||||||
assert.equal(true, found);
|
// Check if the 4th result is "Ray Charles" and prepare it for selection
|
||||||
return found;
|
const found = await driver.executeScript('var found = false; var el = document.querySelector(".list-group-item:nth-child(4)"); if (el) { found = el.innerText === "Ray Charles"; if (found) { el.scrollIntoView(false); el.classList.add("hover"); } } return found;');
|
||||||
}, 3000);
|
if (found) {
|
||||||
// Now select the result by sending the enter key
|
assert.equal(true, found);
|
||||||
await driver.findElement(By.id('prefix')).sendKeys(Key.ENTER);
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, 15000, 'Ray Charles search result not found within timeout');
|
||||||
|
// Now select the result by clicking the search button instead of sending enter
|
||||||
|
await driver.findElement(By.id('searchArticles')).click();
|
||||||
// Check if that worked, and if search result still visible, try with a click instead
|
// Check if that worked, and if search result still visible, try with a click instead
|
||||||
try {
|
try {
|
||||||
const resultElement = await driver.findElement(By.css('.list-group-item:nth-child(4)'));
|
const resultElement = await driver.findElement(By.css('.list-group-item:nth-child(4)'));
|
||||||
@ -350,7 +362,7 @@ function runTests (driver, modes, keepDriver) {
|
|||||||
const articleTitle = await driver.executeScript('return document.getElementById("titleHeading").innerText');
|
const articleTitle = await driver.executeScript('return document.getElementById("titleHeading").innerText');
|
||||||
// console.log('Article title: ' + articleTitle);
|
// console.log('Article title: ' + articleTitle);
|
||||||
return articleTitle === 'Ray Charles';
|
return articleTitle === 'Ray Charles';
|
||||||
}, 5000);
|
}, 10000);
|
||||||
// Check that the article title is correct
|
// Check that the article title is correct
|
||||||
const title = await driver.findElement(By.id('titleHeading')).getText();
|
const title = await driver.findElement(By.id('titleHeading')).getText();
|
||||||
assert.equal('Ray Charles', title);
|
assert.equal('Ray Charles', title);
|
||||||
|
@ -151,6 +151,8 @@ function runTests (driver, modes, keepDriver) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await driver.sleep(2000); // Give time for content to load
|
await driver.sleep(2000); // Give time for content to load
|
||||||
|
// Wait for the iframe to be available before switching to it
|
||||||
|
await driver.wait(until.elementLocated(By.id('articleContent')), 5000);
|
||||||
await driver.switchTo().frame('articleContent');
|
await driver.switchTo().frame('articleContent');
|
||||||
const androidIosLink = await driver.wait(until.elementLocated(By.css('a[href="android-ios-ear-training-app"]')), 5000);
|
const androidIosLink = await driver.wait(until.elementLocated(By.css('a[href="android-ios-ear-training-app"]')), 5000);
|
||||||
await androidIosLink.click();
|
await androidIosLink.click();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user