量角器黄瓜配置文件为我的场景抛出未定义的警告,即使它们存在 [英] Protractor Cucumber Configuration file throwing undefined warning for my scenarios even though those are present

查看:72
本文介绍了量角器黄瓜配置文件为我的场景抛出未定义的警告,即使它们存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的配置文件无法找到规范文件,即使它存在于我在 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');出口.config = {//seleniumAddress: 'http://localhost:4444/wd/hub',直接连接:真,框架:'自定义',//相对于当前配置文件的路径frameworkPath: require.resolve('protractor-cucumber-framework'),能力:{'浏览器名称':'铬',元数据:{浏览器:{名称:'铬',版本:'79'},设备:MacBook Pro 15",平台: {名称:'OSX',版本:'10.12.6'},禁用日志:真,持续时间InMS:真,openReportInBrowser:true}},忽略未捕获的异常:假,//规范模式是相对于这个目录的.眼镜: ['../../Test_modules/features/'],启动前:功能(){如果(fs.existsSync('./logs/ExecutionLog.log')){fs.unlink('./logs/ExecutionLog.log')}log4js.configure({附加程序:{出:{类型:'控制台'},info:{ type: 'dateFile', filename: "../Reports/logs/info", "pattern":"-dd.log",alwaysIncludePattern:false},控制台":{类型":控制台",类别":控制台"},文件":{类别":测试文件附加程序",类型":文件",文件名":../../Reports/logs/log_file.log",maxLogSize":10240,//备份":3,//模式":%d{dd/MM hh:mm} %-5p %m";}},类别:{信息":{"appenders": ["console"], "level": "info"},默认":{"appenders": ["console", "file"], "level": "DEBUG"},//文件":{附加程序":[文件"],级别":调试"}}});},黄瓜选项:{要求:['../../Test_modules/utilities/timeOutConfig.js','../../Test_modules/stepDefinition/spec.js'],标签: 假的,简介:假的,格式:'json:../../Reports/jsonResult/results.json','无来源':真的},onPrepare: 函数 () {const logDefault = log4js.getLogger('default');const logInfo=log4js.getLogger('info');screenshots.browserNameJoiner = ' - ';//这是默认的//截图文件夹screenshots.screenShotDirectory = '../../Screenshots';global.openNewBrowser=require('../../Test_modules/utilities/newBrowserinstance.js');global.testData=require('../../TestData/testData.json');browser.logger = log4js.getLogger('protractorLog4js');global.firstBrowser=浏览器;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');},插件:[{包:'H:/workspace/Proc-UI/node_modules/protractor-multiple-cucumber-html-reporter-plugin',选项:{//阅读选项部分以获得更多选项自动生成报告:真,removeExistingJsonReportFile: 真,reportPath:'../../Reports/HtmlReports',报告名称:test.html"},自定义数据:{title: '运行信息',数据: [{标签:'项目',值:'框架设置'},{标签:'发布',值:'1.2.3'},{标签:'周期',值:'测试周期'}]},}]};

规范文件

<预><代码>var UtilityInit,page2;//browser2;第1页=新的脸书(第一浏览器);module.exports=function(){this.Given(/^打开浏览器并加载URL$/,async function(){等待 firstBrowser.get(properties.get("url1"));browser.logger.info("窗口标题是:"+await browser.getTitle());//screenshots.takesScreenshot(文件名");});this.When(/^用户在搜索框中输入文本$/,async function(){firstBrowser.sleep(3000);等待 page1.email().sendKeys(testData.Login.CM[0].Username);浏览器睡眠(3000);等待 page1.password().sendKeys(testData.Login.CM[0].Password);});this.Then(/^点击登录按钮$/,async function(){浏览器睡眠(3000);等待 facebook.submit().click();});this.Then(/^User 试图在新的浏览器中打开实例$/,async function(){browser2=await openNewBrowser.newBrowserInit(firstBrowser);实用程序初始化=新实用程序(浏览器2);UtilityInit.ignoreSync(properties.get(url2"));browser2.manage().window().maximize();console.log(await utilityInit.title()+title");browser2.sleep(5000);});this.When(/^用户在电子邮件字段中输入文本$/,async function(){第2页=新的脸书(浏览器2);console.log(await page2.title()+browser2");等待 page2.search().sendKeys(testing");browser2.sleep(3000);第1页=新的脸书(第一浏览器);console.log(await page1.title()+browser1");等待 page1.email().sendKeys(testData.Login.CM[0].Username);screenshots.takeScreenshot("newScreenshot");firstBrowser.sleep(5000);});};

执行日志

1) 场景:场景的标题 # ..\features\test.feature:24?给定 打开浏览器并加载 URL不明确的.使用以下代码段实现:Given('打开浏览器并加载 URL', function () {//在这里写代码,把上面的短语变成具体的动作返回待定";});?然后用户尝试在新的浏览器实例中打开不明确的.使用以下代码段实现:然后('用户试图在新的浏览器实例中打开',函数(){//在这里写代码,把上面的短语变成具体的动作返回待定";});?并且用户在电子邮件字段中输入了文本不明确的.使用以下代码段实现:然后('用户在电子邮件字段中输入了文本',函数(){//在这里写代码,把上面的短语变成具体的动作返回待定";});√ 在 # ..\..\node_modules\protractor-cucumber-framework\lib\resultsCapturer.js:27 之后1 个场景(1 个未定义)3 个步骤(3 个未定义)0m00.004s

我尝试通过添加黄瓜依赖项,从相对路径更新到绝对路径我所做的一切..但没有解决..以前它工作正常,但在将其更新为公共框架文件的过程中..我更新了从绝对路径到相对路径.就是这样,我失去了我的整个框架,它一直在说未定义的场景.

**因为只是让我确定我通过在黄瓜 opts 中传递错误的规范文件名来运行脚本,但它仍然给出未定义,这证实了我它甚至没有考虑我通过的规范文件.

解决方案

简单的安装让我的框架有效

npm install Cucumber@1.3.3 --save-dev

my Configuration file is not able to find the spec file even though it is present in the path that i provided in the cucumberOpts..i tried all the resolutions but none of them is worked.

Config File

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'}
            ]
        },
  }]
};

Spec File



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);
    });
};

Execution log

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

i tried by adding cucumber dependencies, updating from relative path to absolute path everything i did.. but none it is resolved.. previously it worked fine but in the process of updating it in to public framework file.. i updated the paths from absolute to relative path. that's it i lost my whole framework and it is continuesly saying undefined scenarios.

**For Just made me sure i ran the script by passing wrong spec file name in the cucumber opts and still it giving Undefined and that confirmed me that it is not even considering that spec file that i passed.

解决方案

Simple installation makes my framework works

npm install cucumber@1.3.3 --save-dev

这篇关于量角器黄瓜配置文件为我的场景抛出未定义的警告,即使它们存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆