1

我在 Chrome 上的 Protractor 中有一组 Cucumber 测试。但是,当我转到 Firefox 时,页面会加载,但 Angular 没有运行。因此,您可以看到 Angular 标签{{ }}而不是值,并且测试挂起,因为 Angular 永远不会完成。当我手动加载页面、刷新或执行任何页面工作时。从量角器启动它会导致 Angular 无法在 Firefox 中运行。
量角器配置

    exports.config = {
    framework: 'cucumber',
    cucumberOpts: {
        format: 'progress',
//        tags: '@dev',
        require: 'test/e2e/features/step_definitions/steps.js'
    },
    specs: [
        'test/e2e/features/**/*.feature'
    ],



    //framework: 'mocha',
    //specs: [
    //    'test/e2e/**/*.spec.js'
    //],
    //mochaOpts: {
    //    enableTimeouts: false
    //},

    plugins: [{
        path: 'node_modules/protractor/plugins/timeline',

        // Output json and html will go in this folder.
        outdir: 'assets/timelines'

        // Optional - if sauceUser and sauceKey are specified, logs from
        // SauceLabs will also be parsed after test invocation.
        //sauceUser: 'Jane',
        //sauceKey: 'abcdefg'
    }],

    onPrepare: function () {
        process.env.PORT = 3001
        require('./server')
    },

    capabilities: {
        'browserName' : 'firefox'
    }
    //
    //multiplecapabilities: [{
    //    'browserName' : 'firefox'
    //}, {
    //    'browserName' : 'chrome'
    //}]
}

小黄瓜功能文件

Feature: Login to my account
  As a Customer, 
  I want to login into my account, 
  so I can use the application

Scenario: Authorize access for an active and valid account
Given I have a valid and active account
And I am logged out of the system
And I request to authenticate myself
When I provide my credentials
Then I should have access to my account

@negative
Scenario: Deny access for an invalid account
Given I have an invalid account
And I am logged out of the system
And I request to authenticate myself
When I provide my credentials
Then I should be denied access to my account

Gherkin 步骤定义

var db = require('../../../../db')
var User = require('../../../../server/models/user')
var bcrypt = require('bcrypt')
var chai = require('chai')
chai.use( require('chai-as-promised'))
var expect = chai.expect

var username = 'user';
var pass = 'pass'

var steps = function() {

    this.Given(/^I have a valid and active account$/, function (callback) {
        db.connection.db.dropDatabase()
        var user = new User({username: username})
        bcrypt.hash(pass, 10, function (err, hash) {
            if (err) {
                return next(err)
            }
            user.password = hash
            user.save(function (err) {
                if (err) {
                    return next(err)
                }
            })
            callback();
        })
    });

    this.Given(/^I am logged out of the system$/, function (callback) {
        browser.get('http://localhost:3001') 
        expect(element(by.css('nav .login'))).to.exist;
        callback();
    });

    this.Given(/^I request to authenticate myself$/, function (callback) {
        element(by.css('nav .login')).click() // fill out and submit registration form ' +
        callback();
    });

    this.When(/^I provide my credentials$/, function (callback) {
        element(by.model('username')).sendKeys(username)
        element(by.model('password')).sendKeys(pass)
        element(by.css('form .btn')).click() // submit a new post on the posts page
        callback();
    });

    this.Then(/^I should have access to my account$/, function (callback) {
        // Write code here that turns the phrase above into concrete actions
        callback.pending();
    });

    this.Given(/^I have an invalid account$/, function (callback) {
        db.connection.db.dropDatabase()
        callback();
    });

    this.Then(/^I should be denied access to my account$/, function (callback) {
        // Write code here that turns the phrase above into concrete actions
        callback.pending();
    });
};

module.exports = steps;
4

1 回答 1

2

Firefox 35 存在原生事件问题。票证已在 Selenium 社区提交:https ://code.google.com/p/selenium/issues/detail?id= 8390 和 AngularJS 跟踪器: https ://github.com /角度/量角器/问题/1734

解决方法:您可以在等待修复时将浏览器降级到 v34。下载旧版火狐

于 2015-02-21T03:53:56.287 回答