【问题标题】:Pass class as parameter to nightmare evaluate将类作为参数传递给噩梦评估
【发布时间】:2018-01-10 10:46:17
【问题描述】:

class 作为参数传递以访问静态方法。 Evaluate 似乎没有按应有的方式通过它。我已经调试了这个似乎有有效参数的line,但是当我在里面调用resolve method时它会抛出错误

无法读取未定义的属性“解析”

该类只包含简单的静态方法

class App { 
    public static resolve() { return true }; 
}

测试如下

//abc.test.ts
it('should contain "abc" text in Href', (done) => {
        nightmare
            .goto("abc.com")
            .evaluate((driver: any) => {
                console.log('driver', driver.resolve()); also is there a way to console.log in evaluate?
                return document.getElementById("a").textContent;
            }, App)
            .end()
            .then((response: any) => {
                expect(response).to.have.containIgnoreSpaces("abc");
                done();
            })
            .catch((error: any) => console.log("Error", error));
    });

运行测试的 npm 命令

set DEBUG=nightmare && mocha --recursive --require jsdom-global/register --require ts-node/register --require babel-core/register tests/*

【问题讨论】:

    标签: javascript typescript mocha.js electron nightmare


    【解决方案1】:

    Evaluate 会将所有内容字符串化,您将失去您的课程或任何类型的功能。

    here 是另一个名为 Puppeteer 的库的答案,但它也可以用于你的噩梦脚本。

    你应该

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      • 1970-01-01
      • 1970-01-01
      • 2022-11-25
      • 1970-01-01
      • 2015-02-17
      • 2023-03-14
      相关资源
      最近更新 更多