我正在尝试使用 TestCafe/JavaScript 创建一个测试,它将网站的顶级菜单文本/链接与存储在配置中的预期数据进行比较。我有一些使用 TestCafe 的经验,但仍在学习中。
当我设置函数并调用它时,我进入函数而不是其中的循环,正如 FOR 循环内的 console.log 未打印到控制台所证明的那样。我已经调试了一段时间,无法弄清楚。
网址:https ://wdwthemeparks.com
配置文件(位于项目中的./config/default.json5)
// Expected Desktop top menu links
"top_menu_nav": {
"All": "/all/",
"News": "/news/",
"Press Releases": "/press/",
"Rumors": "/rumors/",
"About": "/about/",
"Contact": "/contact/",
"Refurbishments": "/refurbishments/",
},
}
选择器和相关函数(位于项目中的 ./page-objects/header.js)
const config = require('../config/config.js');
import { Selector, t } from 'testcafe';
class Header {
// Top Menu Selectors
topMenu = Selector('.td-header-top-menu');
topMenuPageLinksSection = Selector('.td-header-sp-top-menu');
topMenuSocialIconsSection = Selector('.td-header-sp-top-widget');
topMenuNavItem = Selector('.top-header-menu').child().find('a').withAttribute('href');
// Logo
headerLogo = Selector('.td-header-sp-logo');
// Nav Menu
mainNavMenu = Selector('#td-header-menu');
/////////////////////////
/////// Functions ///////
/////////////////////////
async checkDesktopTopMenuBarTextLinks() {
console.log('Inside function');
for (let navText in config.top_menu_nav ) {
console.log('inside for loop');
await t.expect(await this.topMenuNavItem.withText(navText).exists).ok(`"${navText}" top navigation menu do not exists.`);
await t.expect(await this.topMenuNavItem.withText(navText).getAttribute('href')).contains(config.top_menu_nav[navText]);
}
}
}
export let header = new Header();
因此,我再次想做的是测试前端是否显示文本并为顶部菜单中的每个项目提供正确的 href 值。这些预期值存储在配置文件中。
泛舟湖上清波郎朗
相关分类