1

我对 Jasmine 很陌生,我正在使用 Protractor 和页面对象。这是显示的页面对象,包含规范调用的函数:

'use strict';

module.exports = {
    structure: {
        cliButton: element(by.id('cliSubmit')),
        cliInput: element(by.id('commandLineInterface')),
        casDrawButton: element(by.id('casdrawTrigger')),
        benzeneIcon: element(by.id('cdBenzene')),
        casDrawCanvas: element(by.id('cdCanvasContainer')),
        saveUploadButton: element(by.id('cdOK')),
        lastCommandResponse: element(by.id('commandResponse3')),
        myFilesLink: element(by.id('my-stn-toggle')),
        structuresLink: element(by.id('structureOptionsToggle')),
        firstStructureName: element(by.id('structureNameLabel-0')),
        returnHome: element(by.className('return-link')),
        importStructure: element(by.id('importStructure')),
        importBrowse: element(by.id('structureImportBrowse')),
        importOK: element(by.id('structureImportModalOk')),
        editStructureName: element(by.id('editStructureNameSave-0')),
        structureDateTime: element(by.id('structureDate-0')),
        structureSnippet: element(by.id('structureImage-0')),
        firstEditButton: element(by.id('editStructure-0')),
        firstUploadButton: element(by.id('uploadStructure-0')),
        firstActionsButton: element(by.id('scriptActions-0')),
        firstDeleteButton: element(by.id('confirmDelete-0')),
        selectAll: element(by.id('selectAll')),
        deleteAll: element(by.id('deleteStructures')),
        selectCheckboxes: element(by.xpath("//*[contains(@id,'selectStructure')]"))
    },

    casDrawSteps: function () {
        var structure = this.structure;
        var today = new Date();
        var year = today.getFullYear();

        structure.cliInput.sendKeys('fil reg');
        structure.cliButton.click();
        structure.casDrawButton.click();
        browser.sleep(6000);
        structure.benzeneIcon.isEnabled();
        structure.casDrawCanvas.isEnabled();
        structure.benzeneIcon.click();
        structure.casDrawCanvas.click();
        structure.saveUploadButton.click();
        structure.cliButton.isEnabled();
        browser.sleep(6000);
        expect(structure.lastCommandResponse.getText()).toContain('STRUCTURE UPLOADED');
        structure.myFilesLink.click();
        structure.structuresLink.click();
        expect(structure.firstStructureName.getText()).toMatch(year + '_' + /\d*/ + '_Structure');
        structure.returnHome.click();
        structure.cliButton.isEnabled()

    },
};

问题是 getText 之后的 toMatch 与正则表达式不匹配,根据我能找到的所有正则表达式引用,它应该。我安装了 jasmine-matchers,所以我不确定为什么会这样。这是我使用此函数运行规范时收到的堆栈:

Failures:
1) Protractor STNext Smoke Test - Structure: CASDraw creates a structure in CasDraw and verifies the response in Messenger
  Message:
    Expected '2017_0013_Structure' to match '2017_/\d*/_Structure'.
  Stack:
    Error: Failed expectation
        at Object.casDrawSteps (/home/heb29/Desktop/casnc/repos/stn-kraken-qa/spec/pages/structure_page.js:50:56)
        at UserContext.<anonymous> (/home/heb29/Desktop/casnc/repos/stn-kraken-qa/spec/smoke_spec.js:93:23)
        at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:112:25
        at new ManagedPromise (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1067:7)
        at ControlFlow.promise (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2396:12)
        at schedulerExecute (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:95:18)
        at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2970:14)
        at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2953:27)
        at asyncRun (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2860:25)

我错过了什么?

4

1 回答 1

1

您需要正确连接正则表达式和正则字符串

var text = structure.firstStructureName.getText();
expect(text).toMatch(year + /_\d*_Structure/.source);
于 2017-11-08T16:21:33.347 回答