2017-08-28 1 views
0

J'automatise une application Angular 4. avec rapporteur, dactylographe, concombre & Chai for assertion.AssertionError: attendu non défini égal à 'Annuler'

Obtenir ci-dessous erreur:

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) 

Impossible de trouver la solution dans d'autres similar to this des questions

ci-dessous sont les détails de mon code: Version Noeud: 7.10.1, version 5.1.2 protractor

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" 
    } 

Merci à l'avance. @Ram Pasala avez-vous des suggestions!

Répondre

0

Votre méthode de test évalue le résultat avant que la promesse ne soit résolue. Vous devez return the promise dans votre méthode de test