量角器黄瓜配置文件即使出现我的情况也会抛出未定义的警告

问题描述 投票:0回答:1

我的配置文件无法找到规格文件,即使它存在于我在cucumberOpts中提供的路径中。我尝试了所有解决方案,但均无用。

配置文件

const log4js = require('log4js');
var fs=require('fs');
global.screenshots = require('protractor-take-screenshots-on-demand');
global.browser2;
var propertiesReader=require('properties-reader');
var env=require("../../env.js");
const {Given, Then, When, Before} = require('cucumber');

exports.config = {

//seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect:true,

framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
    'browserName': 'chrome',
    metadata: {
        browser: {
            name: 'chrome',
            version: '79'
        },
        device: 'MacBook Pro 15',
        platform: {
            name: 'OSX',
            version: '10.12.6'
        },
       disableLog:true,
       durationInMS:true,
       openReportInBrowser:true
    }
},
ignoreUncaughtExceptions:false,
// Spec patterns are relative to this directory.
specs: [
    '../../Test_modules/features/'
],

beforeLaunch:function(){
    if (fs.existsSync('./logs/ExecutionLog.log')) {
        fs.unlink('./logs/ExecutionLog.log')
    }
    log4js.configure({
        appenders: {
            out: { type: 'console' }, 
            info:{ type: 'dateFile', filename: "../Reports/logs/info", "pattern":"-dd.log",alwaysIncludePattern:false},
            "console" : {
                "type": "console",
                "category": "console"
            },
            "file" : {
                "category": "test-file-appender",
                "type": "file",
                "filename": "../../Reports/logs/log_file.log",
                "maxLogSize": 10240,
               // "backups": 3,
              //  "pattern": "%d{dd/MM hh:mm} %-5p %m"
            }
          },
         categories: {
               "info" :{"appenders": ["console"], "level": "info"},
               "default" :{"appenders": ["console", "file"], "level": "DEBUG"},
              //"file" : {"appenders": ["file"], "level": "DEBUG"}
        }
    });
},
cucumberOpts: {
    require:['../../Test_modules/utilities/timeOutConfig.js','../../Test_modules/stepDefinition/spec.js'],
    tags: false,
    profile: false,
    format:'json:../../Reports/jsonResult/results.json',
    'no-source': true
},
 onPrepare: function () {
     const logDefault = log4js.getLogger('default');
     const logInfo=log4js.getLogger('info');
     screenshots.browserNameJoiner = ' - '; //this is the default
     //folder of screenshot
     screenshots.screenShotDirectory = '../../Screenshots';
     global.openNewBrowser=require('../../Test_modules/utilities/newBrowserinstance.js');
     global.testData=require('../../TestData/testData.json');
     browser.logger = log4js.getLogger('protractorLog4js');
     global.firstBrowser=browser;
     global.properties=propertiesReader('../../TestData/propertyConfig.properties');
     browser.waitForAngularEnabled(false);
     browser.manage().window().maximize();
     global.facebook=require('../../Test_modules/pages/fbPageObjects.js');
     global.utility=require('../../Test_modules/utilities/testFile.js');
  },
  plugins: [{
      package: 'H:/workspace/Proc-UI/node_modules/protractor-multiple-cucumber-html-reporter-plugin',
      options:{
          // read the options part for more options
          automaticallyGenerateReport: true,
          removeExistingJsonReportFile: true,
          reportPath:'../../Reports/HtmlReports',
          reportName:"test.html"
      },
      customData: {
            title: 'Run info',
            data: [
                {label: 'Project', value: 'Framework Setup'},
                {label: 'Release', value: '1.2.3'},
                {label: 'Cycle', value: 'Test Cycle'}
            ]
        },
  }]
};

规格文件



var utilityInit,page2;//browser2;
page1=new facebook(firstBrowser);
module.exports=function(){
    this.Given(/^Open the browser and Load the URL$/,async function(){
        await firstBrowser.get(properties.get("url1"));
        browser.logger.info("Title of the window is :"+await browser.getTitle());
        //screenshots.takesScreenshot("filename");
    });

    this.When(/^User entered the text in the search box$/,async function(){
        firstBrowser.sleep(3000);
        await page1.email().sendKeys(testData.Login.CM[0].Username);
        browser.sleep(3000);
        await page1.password().sendKeys(testData.Login.CM[0].Password);
    });

    this.Then(/^click on login button$/,async function(){
        browser.sleep(3000);
        await facebook.submit().click();
    });

    this.Then(/^User tried to open in new browser instance$/,async function(){
        browser2=await openNewBrowser.newBrowserInit(firstBrowser);
        utilityInit=new utility(browser2);
        utilityInit.ignoreSync(properties.get("url2"));
        browser2.manage().window().maximize();
        console.log(await utilityInit.title()+" title");
        browser2.sleep(5000);
    });

    this.When(/^User entered the text in the email field$/,async function(){
        page2=new facebook(browser2);
        console.log(await page2.title()+" browser2");
        await page2.search().sendKeys("testing");
        browser2.sleep(3000);
        page1=new facebook(firstBrowser);
        console.log(await page1.title()+" browser1");
        await page1.email().sendKeys(testData.Login.CM[0].Username);
        screenshots.takeScreenshot("newScreenshot");
        firstBrowser.sleep(5000);
    });
};

执行日志

1) Scenario: Title of your scenario # ..\features\test.feature:24
   ? Given Open the browser and Load the URL
       Undefined. Implement with the following snippet:

         Given('Open the browser and Load the URL', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

   ? Then User tried to open in new browser instance
       Undefined. Implement with the following snippet:

         Then('User tried to open in new browser instance', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

   ? And User entered the text in the email field
       Undefined. Implement with the following snippet:

         Then('User entered the text in the email field', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

   √ After # ..\..\node_modules\protractor-cucumber-framework\lib\resultsCapturer.js:27

1 scenario (1 undefined)
3 steps (3 undefined)
0m00.004s

我尝试通过添加黄瓜依赖项,从相对路径更新为绝对路径,我所做的一切..但没有解决。.以前它运行良好,但是在将其更新为公共框架文件的过程中。.我更新了路径从绝对路径到相对路径。就是这样,我失去了我的整个框架,并且一直在说不确定的情况。

**为了使我确定我通过在黄瓜opts中传递错误的规范文件名来运行脚本,并且仍然给出Undefined,这确认了我什至没有考虑我通过的规范文件。

Framework structure for your path references

javascript node.js protractor cucumberjs
1个回答
0
投票

简单安装使我的框架有效

npm install [email protected] --save-dev

© www.soinside.com 2019 - 2024. All rights reserved.