Javascript Testcafe-页面对象结构和默认类
我正在为一个包含很多项目的网页建模。来自Ruby背景,我为页面上的每个大项及其子项都设置了一个类。例如,Javascript Testcafe-页面对象结构和默认类,javascript,testing,automated-tests,e2e-testing,testcafe,Javascript,Testing,Automated Tests,E2e Testing,Testcafe,我正在为一个包含很多项目的网页建模。来自Ruby背景,我为页面上的每个大项及其子项都设置了一个类。例如,navbar将是它自己的类: import { Selector, t } from 'testcafe'; export class NavBar { constructor () { this.home = Selector('#home') this.intro = Selector('#intro') ... } } export class Hea
navbar
将是它自己的类:
import { Selector, t } from 'testcafe';
export class NavBar {
constructor () {
this.home = Selector('#home')
this.intro = Selector('#intro')
...
}
}
export class HeaderSection {
...
}
问题:
index
,然后使用多个子类(Navbar
和headerssection
,在我的示例中)从index类继承
import { Selector, t } from 'testcafe';
export default class Index {
}
export class NavBar extends Index {
constructor () {
super ();
this.home = Selector('#home')
this.intro = Selector('#intro')
...
}
}
export class HeaderSection extends Index {
constructor () {
super ();
...
}
}
因此,当我将页面模型导入测试用例时,我可以调用import Index from../pages/Index_page.js
我需要一个默认类吗?我的IDE正在抱怨,但是测试工作正常。我相信答案是否定的,但这是一个很好的实践(?)
没必要。default
关键字确定JavaScript中的。可以根据需要组织页面对象
用JavaScript编写复杂页面模型的推荐方法是什么?我倾向于使用一个page类,比如index,然后使用多个子类(在我的示例中是Navbar和HeaderSection),这些子类继承自index类
这取决于页面的复杂性。若测试页面很简单,那个么一个页面的一个页面对象类就足够了。若测试页面很复杂,那个么为复杂的控件创建单独的类是一个很好的方法