1

I'm fairly new to Jasmine, and I'm using Protractor with page object. Here's the page object as it appears, complete with function called by the spec:

'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()

    },
};

The problem is that the toMatch after the getText is not matching the regex, and according to all regex references I can find, it should. I have jasmine-matchers installed, so I'm uncertain why this is happening. Here's the stack I receive when I run the spec with this function:

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)

What am I missing?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195

1 Answers1

1

You need to concatenate regular expressions and regular strings correctly:

var text = structure.firstStructureName.getText();
expect(text).toMatch(year + /_\d*_Structure/.source);
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195