Javascript 使用量角器和打字脚本的流畅界面

Javascript 使用量角器和打字脚本的流畅界面,javascript,typescript,protractor,automated-tests,Javascript,Typescript,Protractor,Automated Tests,我正在用量角器/打字稿/茉莉花准备项目。在另一个项目中,我们使用带有fluent接口的java。我尝试在这个新项目中使用它,但我有一个问题。底部是我得到的错误。 这是它的结构 -Core --BasePage.ts -pages --LoginPage.ts -> extends LEPPage.ts --HomePage.ts -> extends LEPPage.ts --SearchPage.ts -> extends LEPPage.ts -LEPPage.ts (th

我正在用量角器/打字稿/茉莉花准备项目。在另一个项目中,我们使用带有fluent接口的java。我尝试在这个新项目中使用它,但我有一个问题。底部是我得到的错误。 这是它的结构

-Core
--BasePage.ts
-pages
--LoginPage.ts -> extends LEPPage.ts
--HomePage.ts -> extends LEPPage.ts
--SearchPage.ts -> extends LEPPage.ts
-LEPPage.ts (this is the part of page which is always displayed on each page - top menu and footer) -> extends BasePage.ts 
-tests
--e2e
--smoke
现在,示例代码:

基本页

    export class BaseMeTimePage {
    protected BASE_URL : string = browser.baseUrl;
}
莱佩奇

export class LEPPage extends BaseMeTimePage {
    constructor() {
        super();
    }
    searchFor(value): SearchPage {
        new WaitFor().visibilityOf(searchIcon);
        searchInput.sendKeys(value)
        searchInput.sendKeys(protractor.Key.ENTER);
        return new SearchPage();
    }
     navigateToWishlist(): Wishlist {
        wishlist.click()
        return new WishlistPage();
    }
登录页

export class LoginPage extends BaseMeTimePage {
public URL: string = this.BASE_URL + '/auth';
constructor() {
    super();
    browser.get(this.URL);
}
     login(email?: string, password?: string): HomePage {
            browser.get(browser.baseUrl);
            email = email || EMAIL;
            password = password || PASSWORD
            email = EMAIL;
            password = PASSWORD;
            usernameInput.sendKeys(email);
            passwordInput.sendKeys(password);
            loginBtn.click();
            new WaitFor().visibilityOf($('.lep-header'));
            return new HomePage();
        }
主页

export class HomePage extends LEPPage {
    constructor() {
        super();
    }
}
搜索页面

export class SearchPage extends LEPPage {
    constructor() {
        super();
    }
   clickFirstAddToWishlist() : SearchPage {
        wishListButton.click();
        return this;
    }
示例测试:

describe('SearchTest', function () {

    it('add to wishlist', function () {
        new LoginPage()
            .login()
            .searchFor('some item')
            .clickFirstAddToWishlist()
            .navigateToWishlist()
    });
运行测试后,我发现错误:

E/launcher - Error: TypeError: Object prototype may only be an Object or null: undefined
    at setPrototypeOf (<anonymous>)
    at __extends (/home/kamil/Projects/automatedmt/tmp/LearnerApp/pages/SearchPage.js:7:9)
    at /home/kamil/Projects/automatedmt/tmp/LearnerApp/pages/SearchPage.js:28:5
    at Object.<anonymous> (/home/kamil/Projects/automatedmt/tmp/LearnerApp/pages/SearchPage.js:152:2)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
[10:41:32] E/launcher - Process exited with error code 100
E/launcher-错误:TypeError:对象原型只能是对象或null:未定义
在setPrototypeOf()处
at_uu扩展(/home/kamil/Projects/automatedmt/tmp/LearnerApp/pages/SearchPage.js:7:9)
at/home/kamil/Projects/automatedmt/tmp/LearnerApp/pages/SearchPage.js:28:5
反对。(/home/kamil/Projects/automatedmt/tmp/LearnerApp/pages/SearchPage.js:152:2)
编译(Module.js:652:30)
在Object.Module.\u extensions..js(Module.js:663:10)
在Module.load(Module.js:565:32)
在tryModuleLoad时(module.js:505:12)
在Function.Module.\u加载(Module.js:497:3)
at Module.require(Module.js:596:17)
[10:41:32]E/launcher-进程退出,错误代码为100
将元素添加到wishlist(表单搜索页面)后,我无法使用从LEPPage(.navigateToWishlist()扩展的方法导航到WishlistPage
我不知道怎么解决,我需要你的帮助。我应该在课间通过一些驾驶考试吗?我试图这样做,但没有结果。

我发现typescript允许用返回参数
this
标记类方法

例如:

类基本计算器{
公共构造函数(受保护的值:number=0){}
public currentValue():编号{
返回此.value;
}
公共加法(操作数:number):此{
this.value+=操作数;
归还这个;
}
公共乘法(操作数:数字):此{
this.value*=操作数;
归还这个;
}
//……其他行动都在这里。。。
}
设v=新的基本计算器(2)
.乘(5)
.add(1)
.currentValue();
然后


看,多态性这类人

没人能帮我吗?
class ScientificCalculator extends BasicCalculator {
    public constructor(value = 0) {
        super(value);
    }
    public sin() {
        this.value = Math.sin(this.value);
        return this;
    }
    // ... other operations go here ...
}

let v = new ScientificCalculator(2)
        .multiply(5)
        .sin()
        .add(1)
        .currentValue();