Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Testcafe-页面对象结构和默认类_Javascript_Testing_Automated Tests_E2e Testing_Testcafe - Fatal编程技术网

Javascript Testcafe-页面对象结构和默认类

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

我正在为一个包含很多项目的网页建模。来自Ruby背景,我为页面上的每个大项及其子项都设置了一个类。例如,
navbar
将是它自己的类:

import { Selector, t } from 'testcafe';

export class NavBar {
  constructor () {
    this.home = Selector('#home')
    this.intro = Selector('#intro')
    ...
  }
}

export class HeaderSection {
  ...
}
问题:

  • 我需要一个默认类吗?我的IDE正在抱怨,但是测试工作正常。我相信答案是否定的,但这是一个很好的实践(?)
  • 用JavaScript编写复杂页面模型的推荐方法是什么?我倾向于使用一个页面类,比如说
    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类

    这取决于页面的复杂性。若测试页面很简单,那个么一个页面的一个页面对象类就足够了。若测试页面很复杂,那个么为复杂的控件创建单独的类是一个很好的方法