茉莉花不和木偶戏工作

时间:2018-01-29 09:26:30

标签: node.js jasmine puppeteer

我试图使用木偶操作员在茉莉花中进行一个简单的测试,但是当我在测试脚本中使用它时,我无法让木偶操作者工作:

Dim kolQ as Range
Set kolQ = (here is range in column Q)
With kolQ.Validation
.Delete
.Add Type:=xlValidateList, Formula1:="=IF(AND($L2<DATE(2014;5;1);$M2>DATE(2015;4;30));list_a;list_b)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "No valid status!"
.InputMessage = ""
.ErrorMessage = "Chose option from drop-down list!"
.ShowInput = True
.ShowError = True
End With

在运行此脚本时,我得到:

const puppeteer = require('puppeteer');

describe("Jasmine puppeteer", function() {

  let browser;
  let page;

  beforeAll(() => {
    browser = await puppeteer.launch({headless: false});
    page = await browser.newPage();
    await page.goto('chrome://newtab');
    await page.screenshot({path: 'a.png'});
  })

  it("jasmine puppeteer", () => {
    expect(await page.title()).toBe("");
    done();
  });

  afterAll(() => {
  })
});

$ npm test spec/testspec.js > test@0.0.1 test D:\sample > jasmine "spec/testspec.js" D:\sample\spec\testspec.js:10 browser = await puppeteer.launch({headless: false}); ^^^^^^^^^ SyntaxError: Unexpected identifier at createScript (vm.js:80:10) at Object.runInThisContext (vm.js:139:10) at Module._compile (module.js:607:28) at Object.Module._extensions..js (module.js:654:10) at Module.load (module.js:556:32) at tryModuleLoad (module.js:499:12) at Function.Module._load (module.js:491:3) at Module.require (module.js:587:17) at require (internal/module.js:11:18) at D:\sample\node_modules\jasmine\lib\jasmine.js:93:5 npm ERR! Test failed. See above for more details. 只是指向npm test。如果我对puppeteer相关的代码发表评论,那么测试工作正常。

3 个答案:

答案 0 :(得分:3)

await仅适用于async function

beforeAll((done) => {
    let screenshot = async function() {
        browser = await puppeteer.launch({ headless: false });
        page = await browser.newPage();
        await page.goto('chrome://newtab');
        await page.screenshot({ path: 'a.png' });
    }
    screenshot().then(done)
})

答案 1 :(得分:1)

在第一个回答后,我将所有awaits放在async个函数中。但是我仍然无法运行测试脚本。根据{{​​3}},jasmine不支持async / await,一些注释确实提出了解决此问题的解决方法。

导致工作脚本:

const puppeteer = require('puppeteer');

function testAsync(specFunction) {
  return (done) => {
      specFunction().then(() => {
          done();
      }).catch((error) => {
          done.fail(error);
      });
  };
}

describe("Jasmine puppeteer", function() {

  let browser;
  let page;

  beforeAll(testAsync(async () => {
    browser = await puppeteer.launch({headless: false});
    page = await browser.newPage();
    await page.goto('https://example.com');
    await page.screenshot({path: 'a.png'});
  }));

  it("jasmine puppeteer", testAsync(async () => {
    expect(await page.title()).toBe("");
  }));

  afterAll(() => {
  })
});

答案 2 :(得分:0)

你的代码应该是这样的 “”” 它(“jasmine puppeteer”,async()=&gt; {     expect(等待page.title())。toBe(“”);     ()完成;   }); “””