AssertionError: ожидается, что undefined будет равно «Отмена»

Я автоматизирую приложение Angular 4. с транспортиром, машинописным текстом, огурцом и чаем для утверждения.

Получение ошибки ниже:

AssertionError: expected undefined to equal 'Cancel'
     at getBasePromise.then.then.newArgs (D:\Vinni\ProtractorWorkspace\protractor-cucumber-final\node_modules\chai-as-promised\lib\chai-as-promised.js:302:22)
     at process._tickCallback (internal/process/next_tick.js:109:7)

Не удалось найти решение по другим вопросам, подобным этому

ниже приведены сведения о моем коде: Версия узла: 7.10.1, версия транспортира 5.1.2

config.ts

import {browser} from "protractor";
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);

exports.config = {
 seleniumAddress: "http://localhost:4444/wd/hub",
 SELENIUM_PROMISE_MANAGER: false,
 baseUrl: "http://localhost:4200/",
 framework: "custom",
 frameworkPath: require.resolve("protractor-cucumber-framework"),
 specs: ["../features/*.feature"],
 exclude: "../features/database.feature",
 resultJsonOutputFile: "./reports/json/protractor_report.json",
 onPrepare: () => {
   browser.ignoreSynchronization = true;
   browser.manage().window().maximize();
   global.expect = chai.expect;
 },
 cucumberOpts: {
   strict: true,
   format: ["pretty"],
   require: ["../stepDefinitions/*.js", "../support/*.js"],
   tags: "@smoke"
 }
};

ManageRecipeStep.ts

import {defineSupportCode} from 'cucumber';
import {ManageRecipePage} from "../pages/ManageRecipePage";
import {ActionUtil} from "../utils/ActionUtil";
import {browser} from "protractor";
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
let expect = chai.expect;

defineSupportCode(({Given, When, Then}) => {
  let manageRecipePage = new ManageRecipePage();
  let actionUtil = new ActionUtil();

 Given(/^Navigate to the Recipes page$/, async () => {
    browser.ignoreSynchronization = true;
    await manageRecipePage.clickFirstRecipe();
 });

 When(/^click manage recipe$/, async () => {
    await manageRecipePage.manageRecipe();
 });

 When(/^click edit$/, async () => {
    await manageRecipePage.clickEdit();
 });

 Then(/^Cancel button should be displayed$/, async () => {
    await expect(manageRecipePage.getCancelButton()).to.eventually.equal('Cancel');
 }); // This assertion should pass but getting error here

 Then(/^Cancel button should be enabled/, async () => {
    await expect(manageRecipePage.isCancelEnabled()).to.eventually.be.true;
 });

});

ManageRecipePage.ts

import {BasePage, IdentificationType} from "../utils/BasePage";
import {ActionUtil} from "../utils/ActionUtil";

const Locators = {
    firstRecipe: {
        type:IdentificationType[IdentificationType.Xpath],
        value: "//A[@ng-reflect-router-link='0']"
    },
    manageRecipeByText: {
        type:IdentificationType[IdentificationType.PartialButtonText],
        value: "Manage Recipe"
    },
    edit: {
        type: IdentificationType[IdentificationType.PartialButtonText],
        value: "edit"
    },
    cancelByText: {
        type:IdentificationType[IdentificationType.PartialButtonText],
        value: "Cancel"
    }
};

let actionUtil = new ActionUtil();

export class ManageRecipePage extends BasePage {

    async clickFirstRecipe() {
        await actionUtil.clickElement(Locators.firstRecipe);
    }

    async manageRecipe() {
        await actionUtil.clickElement(Locators.manageRecipeByText);
    }

    async clickEdit() {
        await actionUtil.clickElement(Locators.edit);
    }

    async getCancelButton() {
        await actionUtil.getElementText(Locators.cancelByText);
    }

    async isCancelEnabled() {
        await actionUtil.isElementEnabled(Locators.cancelByText);
    }
}

ActionUtils.ts

async getElementText(obj) {
        let attempts = 0;

        while(attempts < 2) {
            try {
                await this.basePage.ElementLocator(obj).getText();
            } catch(StaleElementException) {
                console.log("EXCEPTION while getting Text" + StaleElementException);
            }
            attempts++;
        }
    }

package.json

"dependencies": {
    "chai": "^4.0.2",
    "cucumber": "^2.3.0",
    "mkdirp": "^0.5.1",
    "protractor": "^5.1.1",
    "protractor-cucumber-framework": "^3.1.0",
    "ts-node": "^3.1.0",
    "typescript": "^2.2.1"
  },
  "devDependencies": {
    "@types/cucumber": "^2.0.3",
    "@types/node": "^8.0.25",
    "@types/selenium-webdriver": "^3.0.0",
    "chai": "^4.0.2",
    "chai-as-promised": "^7.0.0",
    "cucumber": "^2.3.0",
    "cucumber-html-report": "^0.6.0",
    "cucumber-html-reporter": "^0.5.2",
    "cucumberjs-allure-reporter": "^1.0.3",
    "mkdirp": "^0.5.1",
    "pg": "^6.0.3"
  }

Заранее спасибо. @Ram Pasala у вас есть предложения!


person Vinni    schedule 28.08.2017    source источник


Ответы (1)


Ваш тестовый метод оценивает результат до того, как обещание будет разрешено. Вам нужно вернуть обещание в методе тестирования.

person Troopers    schedule 28.08.2017