量角器黄瓜测试未运行

时间:2017-01-13 13:32:27

标签: frameworks protractor cucumber

我正在使用量角器 - 黄瓜框架,无法运行我的测试。浏览器已启动但未导航到我的URL,然后收到以下错误:

exports.config = {
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
   //// getPageTimeout: 60000,
    ////allScriptsTimeout: 500000,
    framework: 'custom',
    // path relative to the current config file
    frameworkPath: require.resolve('protractor-cucumber-framework'),
    capabilities: {
        'browserName': 'chrome'
    },

    // Spec patterns are relative to this directory.
    specs: ['Features/*.feature'],

    baseURL: 'http://localhost:/8080',



    cucumberOpts: {
        require: 'Features/step_definitions/homePage.js',
        tags: false,
        format: undefined,
        profile: false,
        'no-source': true
    }
};

Conf.js

#features/test.feature
Feature: App hub home page

  Scenario: First sample
    Given I go to the app hub site
    When the homepage has loaded
    Then I expect to see title app hub

功能文件:

module.exports = function() {       

     this.Given('I go to the app hub site', function (callback) {
        browser.get('http://localhost:8080')
        .then (callback);
     });

};

步骤定义:

目前我只为声明提供步骤定义“鉴于我转到应用中心网站”

step_definitions保存在我在conf.js文件中引用的'Features'文件夹中名为'step_definitions'的文件夹中。

import java.io.IOException;
import java.io.FileInputStream;
import java.io.File;

import java.nio.ByteBuffer;
import javax.xml.bind.DatatypeConverter;


public class parse_Header_JP2 
{
    static File     myFile;     static FileInputStream  fileInStream = null;
    static byte[]   myBytes;    static String           myString = ""; 

    static int myNum = 0; static int myWidth = 0; static int myHeight = 0;
    static ByteBuffer byteBuff;

    public static void main(String[] args) 
    {
        myFile = new File("c:/test/image.jp2");
        myBytes = getBytes_Header_JP2(myFile);
        checkBytes_Header_JP2(myBytes); //# update myWidth & myHeight

        //# Shows HEX of whole bytearray
        System.out.println("First 64 bytes (as HEX) : \n" + bytesToHex( myBytes ) );
    }

    private static byte[] getBytes_Header_JP2(File file)
    {
        myBytes = new byte[64]; //will hold first 64 bytes of file as header bytes

        try
        {
           //# convert file into array of bytes
           fileInStream = new FileInputStream(file);
           fileInStream.read(myBytes, 0, 64); //# Read only first 64 bytes
           fileInStream.close();
        }
        catch (Exception e) { e.printStackTrace(); } //# error catching

        byteBuff = ByteBuffer.wrap(myBytes); //associate ByteBuffer with bytes

        return myBytes;
   }

   public static void checkBytes_Header_JP2(byte[] bytes)
   {
       int offset = 0; myHeight = 0; myWidth = 0; // resets

       while(true)
       {
           //# set as byte value reading from offset
           myNum = bytes[offset]; myString = Integer.toHexString(myNum).toUpperCase();

           //# Check byte as : Hex value
           System.out.println("Byte Value at [" + offset + "] : " + decimalToHex(myNum) );

           //# Check byte as : Decimal value
           //System.out.println("Byte Value at [" + offset + "] : " + myNum ); 

           //# Find byte 0x69 (or Decimal = 105) which is letter "i" from "ihdr"
           if (myNum == 0x69) //# if "i" is found at this offset within bytes
           {
               //# From this offset check if reading 4 bytes gives "ihdr" (as bytes 69-68-64-72)
               if ( byteBuff.getInt(offset) == 0x69686472 ) //# if the 4 bytes make "ihdr"
               {
                   System.out.println("found \"ihdr\" section at offset : " + offset ); 

                   //# extract Width or Height from this offset
                   myHeight = byteBuff.getInt(offset+4); //# +4 from "ihdr" is Height entry
                   myWidth = byteBuff.getInt(offset+8); //# +8 from "ihdr" is Width entry

                   //# check values
                   System.out.println("Image Width  : " + myWidth);
                   System.out.println("Image Height : " + myHeight);

                   break; //# end the While loop (otherwise runs forever)
               }    
           }    

           offset++; //# increment offset during While loop process
       }    
    }

    //# Convert byte values to Hex string for checking
    private static String bytesToHex(byte[] bytes)
    { myString = ""; myString = DatatypeConverter.printHexBinary(bytes); return myString; } 

    private static int bytesToNumber( ByteBuffer input ) //throws IOException 
    { input.rewind(); myNum = input.getInt(); return myNum; }

    private static String decimalToHex(int input) 
    {
        input = input & 0xFF; myString = Integer.toHexString(input);
        if(myString.length() == 1) {myString="0"+myString;} 
        return myString.toUpperCase();
    }
} //end Class

非常感谢任何帮助。

4 个答案:

答案 0 :(得分:2)

这是错误很可能是因为你正在使用带有量角器 - 黄瓜 - 框架的黄瓜2.0。目前它们是不兼容的,请将您的黄瓜版本降级到1.3.1,这应该可以解决您的问题。

与此同时,正在利用量角器 - 黄瓜 - 框架支持黄瓜2.0取得了良好的进展。您可以查看此repo- protractor-cucumber-frameowrk了解更多详情。

答案 1 :(得分:0)

可能是不匹配的软件包版本导致了问题。当你运行npm list <package-name>时你会得到什么?

我目前在package.json中有以下内容:

"devDependencies": {
    "chai": "^3.5.0",
    "chai-as-promised": "^5.3.0",
    "chai-string": "^1.2.0",
    "cucumber": "^1.0.0",
    "gulp": "^3.9.1",
    "gulp-angular-protractor": "^0.1.1",
    "protractor": "^3.3.0",
    "protractor-cucumber-framework": "^0.6.0"
  },

有了这个,我正在使用这些版本而没有任何麻烦:

  • 黄瓜 - 1.3.1
  • 量角器 - 黄瓜 - 框架 - 0.6.0
  • 量角器 - 3.3.0

答案 2 :(得分:0)

太好了,谢谢你的帮助。我正在使用黄瓜2.0。我在量角器网站上找到了一个解决方法,并更改了我的config.js文件,因此frameworkPath现在引用了index.js文件,这很有效。

<强> Config.js

/protractor.conf.js

exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: 'custom',
// path relative to the current config file
frameworkPath: './index.js',
//frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
    'browserName': 'chrome'
},
useAllAngular2AppRoots: true,
// Spec patterns are relative to this directory.
specs: ['Features/*.feature'],

baseURL: 'http://localhost/',

cucumberOpts: {
    require: 'Features/step_definitions/homePage.js',
    tags: false,
    format: undefined,
    profile: false,
    'no-source': true
}};

答案 3 :(得分:0)

这是我的index.js文件

<强> index.js `

var q = require('q'),
path = require('path'),
glob = require('glob'),
assign = require('object-assign'),
debug = require('debug')('protractor-cucumber-framework'),
Cucumber = require('cucumber'),
state = require('./lib/runState');

/*** Execute the Runner's test cases through Cucumber.
 * @param {Runner} runner The current Protractor Runner.
 * @param {Array} specs Array of Directory Path Strings.
 * @return {q.Promise} Promise resolved with the test results
 */
exports.run = function(runner, specs) {
var results = {};

return runner.runTestPreparer().then(function() {
    var config = runner.getConfig();
    var opts = assign({}, config.cucumberOpts, config.capabilities.cucumberOpts);
    state.initialize(runner, results, opts.strict);

    return q.promise(function(resolve, reject) {
        var cliArguments = convertOptionsToCliArguments(opts);
        cliArguments.push('--require', path.resolve(__dirname, 'lib', 'resultsCapturer.js'));
        cliArguments = cliArguments.concat(specs);

        debug('cucumber command: "' + cliArguments.join(' ') + '"');

        Cucumber.Cli(cliArguments).run(function (isSuccessful) {
            try {
                var complete = q();
                if (runner.getConfig().onComplete) {
                    complete = q(runner.getConfig().onComplete());
                }
                complete.then(function() {
                    resolve(results);
                });
            } catch (err) {
                reject(err);
            }
        });
    });
});

function convertOptionsToCliArguments(options) {
    var cliArguments = ['node', 'cucumberjs'];

    for (var option in options) {
        var cliArgumentValues = convertOptionValueToCliValues(option, options[option]);

        if (Array.isArray(cliArgumentValues)) {
            cliArgumentValues.forEach(function (value) {
                cliArguments.push('--' + option, value);
            });
        } else if (cliArgumentValues) {
            cliArguments.push('--' + option);
        }
    }

    return cliArguments;
}

function convertRequireOptionValuesToCliValues(values) {
    var configDir = runner.getConfig().configDir;

    return toArray(values).map(function(path) {
        // Handle glob matching
        return glob.sync(path, {cwd: configDir});
    }).reduce(function(opts, globPaths) {
        // Combine paths into flattened array
        return opts.concat(globPaths);
    }, []).map(function(requirePath) {
        // Resolve require absolute path
        return path.resolve(configDir, requirePath);
    }).filter(function(item, pos, orig) {
        // Make sure requires are unique
        return orig.indexOf(item) == pos;
    });
}

function convertGenericOptionValuesToCliValues(values) {
    if (values === true || !values) {
        return values;
    } else {
        return toArray(values);
    }
}

function convertOptionValueToCliValues(option, values) {
    if (option === 'require') {
        return convertRequireOptionValuesToCliValues(values);
    } else {
        return convertGenericOptionValuesToCliValues(values);
    }
}

function toArray(values) {
    return Array.isArray(values) ? values : [values];
}};

这不是一个解决方案,但是一种解决方法,使我能够成功运行我的测试。