Added split row validation fix

This commit is contained in:
2025-05-15 09:52:24 -07:00
parent 77a3b83ca7
commit 964736c345
2 changed files with 319 additions and 40 deletions

Binary file not shown.

View File

@@ -332,11 +332,34 @@ const steps = [
{
description: 'Validate Grade label',
action: async () => {
const elementText = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(1)')).getText();
if (elementText !== 'Grade:') {
throw new Error(`Expected: "Grade:"; Actual: "${elementText}"`);
try {
const element = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(1)'));
//Get different versions of the text for debugging
const fullText = await element.getText();
//Check for the expected text in different ways
const expectedText = 'Grade';
const trimmedFullText = fullText.trim();
const firstLine = trimmedFullText.split('\n')[0].trim();
//Try multiple matching strategies
if (firstLine.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found in first line`);
} else if (trimmedFullText.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found within full text`);
} else {
throw new Error(
`Text validation failed.\nExpected: "${expectedText}"\n` +
`Full text: "${fullText}"\n` +
`First line: "${firstLine}"\n`
);
}
} catch (error) {
console.error('Detailed error during validation:', error);
throw error; //Re-throw after logging
}
console.log('Passed: Grade: label matched as expected');
}
},
@@ -356,11 +379,34 @@ const steps = [
{
description: 'Validate Subject label',
action: async () => {
const elementText = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(2)')).getText();
if (elementText !== 'Subject:') {
throw new Error(`Expected: "Subject:"; Actual: "${elementText}"`);
try {
const element = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(2)'));
//Get different versions of the text for debugging
const fullText = await element.getText();
//Check for the expected text in different ways
const expectedText = 'Subject';
const trimmedFullText = fullText.trim();
const firstLine = trimmedFullText.split('\n')[0].trim();
//Try multiple matching strategies
if (firstLine.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found in first line`);
} else if (trimmedFullText.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found within full text`);
} else {
throw new Error(
`Text validation failed.\nExpected: "${expectedText}"\n` +
`Full text: "${fullText}"\n` +
`First line: "${firstLine}"\n`
);
}
} catch (error) {
console.error('Detailed error during validation:', error);
throw error; //Re-throw after logging
}
console.log('Passed: Subject: label matched as expected');
}
},
@@ -380,11 +426,34 @@ const steps = [
{
description: 'Validate Alignment Status label',
action: async () => {
const elementText = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(3)')).getText();
if (elementText !== 'Alignment Status:') {
throw new Error(`Expected: "Alignment Status:"; Actual: "${elementText}"`);
try {
const element = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(3)'));
//Get different versions of the text for debugging
const fullText = await element.getText();
//Check for the expected text in different ways
const expectedText = 'Alignment Status:';
const trimmedFullText = fullText.trim();
const firstLine = trimmedFullText.split('\n')[0].trim();
//Try multiple matching strategies
if (firstLine.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found in first line`);
} else if (trimmedFullText.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found within full text`);
} else {
throw new Error(
`Text validation failed.\nExpected: "${expectedText}"\n` +
`Full text: "${fullText}"\n` +
`First line: "${firstLine}"\n`
);
}
} catch (error) {
console.error('Detailed error during validation:', error);
throw error; //Re-throw after logging
}
console.log('Passed: Alignment Status: label matched as expected');
}
},
@@ -923,11 +992,46 @@ const steps = [
{
description: 'Validate Grade label',
action: async () => {
const elementText = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(1)')).getText();
if (elementText !== 'Grade:') {
throw new Error(`Expected: "Grade:"; Actual: "${elementText}"`);
try {
const element = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(1)'));
//Get different versions of the text for debugging
const fullText = await element.getText();
//Check for the expected text in different ways
const expectedText = 'Grade:';
const trimmedFullText = fullText.trim();
const firstLine = trimmedFullText.split('\n')[0].trim();
//Try multiple matching strategies
if (firstLine.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found in first line`);
} else if (trimmedFullText.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found within full text`);
} else {
throw new Error(
`Text validation failed.\nExpected: "${expectedText}"\n` +
`Full text: "${fullText}"\n` +
`First line: "${firstLine}"\n`
);
}
console.log('Passed: Grade: label matched as expected');
} catch (error) {
console.error('Detailed error during validation:', error);
throw error; //Re-throw after logging
}
}
},
//Grade: selection
{
description: 'Validate selected Grade option',
action: async () => {
const elementText = await driver.findElement(By.xpath('//*[@id="searchbox-content"]/ul/li[1]/div/button/span')).getText();
if (elementText !== '8 (1530)') {
throw new Error(`Expected: Grade: "8 (1530)" option; Actual: "${elementText}"`);
}
console.log('Passed: Grade: "8 (1530)" option matched as expected');
}
},
@@ -935,11 +1039,46 @@ const steps = [
{
description: 'Validate Subject label',
action: async () => {
const elementText = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(2)')).getText();
if (elementText !== 'Subject:') {
throw new Error(`Expected: "Subject:"; Actual: "${elementText}"`);
try {
const element = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(2)'));
//Get different versions of the text for debugging
const fullText = await element.getText();
//Check for the expected text in different ways
const expectedText = 'Subject:';
const trimmedFullText = fullText.trim();
const firstLine = trimmedFullText.split('\n')[0].trim();
//Try multiple matching strategies
if (firstLine.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found in first line`);
} else if (trimmedFullText.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found within full text`);
} else {
throw new Error(
`Text validation failed.\nExpected: "${expectedText}"\n` +
`Full text: "${fullText}"\n` +
`First line: "${firstLine}"\n`
);
}
console.log('Passed: Subject: label matched as expected');
} catch (error) {
console.error('Detailed error during validation:', error);
throw error; //Re-throw after logging
}
}
},
//Subject: selection
{
description: 'Validate selected Grade option',
action: async () => {
const elementText = await driver.findElement(By.xpath('//*[@id="searchbox-content"]/ul/li[2]/div/button/span')).getText();
if (elementText !== 'Science (1066), Social Studies (77)') {
throw new Error(`Expected: Subject: "Science (1066), Social Studies (77)" option; Actual: "${elementText}"`);
}
console.log('Passed: Subject: "Science (1066), Social Studies (77)" option matched as expected');
}
},
@@ -947,11 +1086,46 @@ const steps = [
{
description: 'Validate Alignment Status label',
action: async () => {
const elementText = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(3)')).getText();
if (elementText !== 'Alignment Status:') {
throw new Error(`Expected: "Alignment Status:"; Actual: "${elementText}"`);
try {
const element = await driver.findElement(By.css('.list-group:nth-child(2) > .list-group-item:nth-child(3)'));
//Get different versions of the text for debugging
const fullText = await element.getText();
//Check for the expected text in different ways
const expectedText = 'Alignment Status:';
const trimmedFullText = fullText.trim();
const firstLine = trimmedFullText.split('\n')[0].trim();
//Try multiple matching strategies
if (firstLine.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found in first line`);
} else if (trimmedFullText.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found within full text`);
} else {
throw new Error(
`Text validation failed.\nExpected: "${expectedText}"\n` +
`Full text: "${fullText}"\n` +
`First line: "${firstLine}"\n`
);
}
console.log('Passed: Alignment Status: label matched as expected');
} catch (error) {
console.error('Detailed error during validation:', error);
throw error; //Re-throw after logging
}
}
},
//Alignment Status: selection
{
description: 'Validate selected Alignment Status option',
action: async () => {
const elementText = await driver.findElement(By.xpath('//*[@id="searchbox-content"]/ul/li[3]/div/button/span')).getText();
if (elementText !== 'Pending (13), Aligned (8)') {
throw new Error(`Expected: Alignment Status: "Pending (13), Aligned (8)" option; Actual: "${elementText}"`);
}
console.log('Passed: Alignment Status: "Pending (13), Aligned (8)" option matched as expected');
}
},
@@ -1031,11 +1205,47 @@ const steps = [
{
description: 'Validate Biology - QA count',
action: async () => {
const elementText = await driver.findElement(By.css('.form-group:nth-child(1)')).getText();
if (elementText !== 'Biology - QA (2)') {
throw new Error(`Expected: "Biology - QA (2)"; Actual: "${elementText}"`);
try {
const element = await driver.findElement(By.css('.form-group:nth-child(1)'));
//Get different versions of the text for debugging
const fullText = await element.getText();
//Try XPath approach
let xpathText;
try {
xpathText = await driver.findElement(
By.xpath('//*[@id="facets"]/div[1]/text()')
).getText();
} catch (e) {
xpathText = "XPath method failed: " + e.message;
}
//Check for the expected text in different ways
const expectedText = 'Biology - QA (2)';
const trimmedFullText = fullText.trim();
const firstLine = trimmedFullText.split('\n')[0].trim();
//Try multiple matching strategies
if (firstLine.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text in first line`);
} else if (trimmedFullText.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text within full text`);
} else if (xpathText.includes(expectedText)) {
console.log('Passed: Found expected text via XPath method');
} else {
throw new Error(
`Text validation failed.\nExpected: "${expectedText}"\n` +
`Full text: "${fullText}"\n` +
`First line: "${firstLine}"\n` +
`XPath result: "${xpathText}"`
);
}
} catch (error) {
console.error('Detailed error during validation:', error);
throw error; //Re-throw after logging
}
console.log('Passed: Biology - QA (2) label matched as expected');
}
},
@@ -1043,11 +1253,34 @@ const steps = [
{
description: 'Validate Grade title',
action: async () => {
const elementText = await driver.findElement(By.css('.form-group:nth-child(3) > b')).getText();
if (elementText !== 'Grade') {
throw new Error(`Expected: "Grade"; Actual: "${elementText}"`);
try {
const element = await driver.findElement(By.css('.form-group:nth-child(3) > b'));
//Get different versions of the text for debugging
const fullText = await element.getText();
//Check for the expected text in different ways
const expectedText = 'Grade';
const trimmedFullText = fullText.trim();
const firstLine = trimmedFullText.split('\n')[0].trim();
//Try multiple matching strategies
if (firstLine.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found in first line`);
} else if (trimmedFullText.includes(expectedText)) {
console.log(`Passed: "${expectedText}" text found within full text`);
} else {
throw new Error(
`Text validation failed.\nExpected: "${expectedText}"\n` +
`Full text: "${fullText}"\n` +
`First line: "${firstLine}"\n`
);
}
} catch (error) {
console.error('Detailed error during validation:', error);
throw error; //Re-throw after logging
}
console.log('Passed: Grade title matched as expected');
}
},
@@ -1742,11 +1975,34 @@ const steps = [
{
description: 'Validate Filtered Content 1 description',
action: async () => {
const elementText = await driver.findElement(By.css('.card:nth-child(12) .lo-descr')).getText();
if (elementText !== `In this Science Update, from Science NetLinks, you'll hear an interview with Kevin Kelly, co-founder and board chairman of the All Species Foundation in San Francisco. Kelly discusses his mission to discover, identify, and document every species on Earth within the next 25 years. Students then read more information about the project, and conclude by answering some related questions. Science Updates are audio interviews with scientists and are accompanied by a set of questions as well as links to related Science NetLinks lessons and other related resources.`) {
throw new Error(`Expected: Filtered Content 1 description tIn this Science Update, from Science NetLinks, you'll hear an interview with Kevin Kelly, co-founder and board chairman of the All Species Foundation in San Francisco. Kelly discusses his mission to discover, identify, and document every species on Earth within the next 25 years. Students then read more information about the project, and conclude by answering some related questions. Science Updates are audio interviews with scientists and are accompanied by a set of questions as well as links to related Science NetLinks lessons and other related resources.ext did not match; Actual: "${elementText}"`);
try {
const element = await driver.findElement(By.css('.card:nth-child(12) .lo-descr'));
//Get different versions of the text for debugging
const fullText = await element.getText();
//Check for the expected text in different ways
const expectedText = `In this Science Update, from Science NetLinks, you'll hear an interview with Kevin Kelly, co-founder and board chairman of the All Species Foundation in San Francisco. Kelly discusses his mission to discover, identify, and document every species on Earth within the next 25 years. Students then read more information about the project, and conclude by answering some related questions. Science Updates are audio interviews with scientists and are accompanied by a set of questions as well as links to related Science NetLinks lessons and other related resources.`;
const trimmedFullText = fullText.trim();
const firstLine = trimmedFullText.split('\n')[0].trim();
//Try multiple matching strategies
if (firstLine.includes(expectedText)) {
console.log(`Passed: "In this Science Update, from Science NetLinks, you'll hear..." text found in first line`);
} else if (trimmedFullText.includes(expectedText)) {
console.log(`Passed: "In this Science Update, from Science NetLinks, you'll hear..." text found within full text`);
} else {
throw new Error(
`Text validation failed.\nExpected: "${expectedText}"\n` +
`Full text: "${fullText}"\n` +
`First line: "${firstLine}"\n`
);
}
} catch (error) {
console.error('Detailed error during validation:', error);
throw error; //Re-throw after logging
}
console.log('Passed: Filtered Content 1 description text matched as expected');
}
},
@@ -1874,11 +2130,34 @@ const steps = [
{
description: 'Validate Filtered Content 2 description',
action: async () => {
const elementText = await driver.findElement(By.css('.card:nth-child(13) .lo-descr')).getText();
if (elementText !== 'Video. From the Best of NG Live Collection: Get the inside story of the gear and the grit needed by National Geographic grantee Andrew Skurka for his six-month, 4,700-mile expedition through Alaska and the Yukon.') {
throw new Error(`Expected: Filtered Content 2 description text did not match; Actual: "${elementText}"`);
try {
const element = await driver.findElement(By.css('.card:nth-child(13) .lo-descr'));
//Get different versions of the text for debugging
const fullText = await element.getText();
//Check for the expected text in different ways
const expectedText = 'Video. From the Best of NG Live Collection: Get the inside story of the gear and the grit needed by National Geographic grantee Andrew Skurka for his six-month, 4,700-mile expedition through Alaska and the Yukon.';
const trimmedFullText = fullText.trim();
const firstLine = trimmedFullText.split('\n')[0].trim();
//Try multiple matching strategies
if (firstLine.includes(expectedText)) {
console.log('Passed: "Video. From the Best of NG Live Collection: Get the inside story..." text found in first line');
} else if (trimmedFullText.includes(expectedText)) {
console.log('Passed: "Video. From the Best of NG Live Collection: Get the inside story..." text found within full text');
} else {
throw new Error(
`Text validation failed.\nExpected: "${expectedText}"\n` +
`Full text: "${fullText}"\n` +
`First line: "${firstLine}"\n`
);
}
} catch (error) {
console.error('Detailed error during validation:', error);
throw error; //Re-throw after logging
}
console.log('Passed: Filtered Content 2 description text matched as expected');
}
},