當我使用角度2中的黃瓜+量角器編寫函數測試時,存在一些問題。
這是我的代碼使用黃瓜+量角器+角度2編寫函數測試
cucumberCong.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumServerJar: '../node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar',
framework: 'custom',
frameworkPath: '../node_modules/protractor-cucumber-framework/index.js',
// Spec patterns are relative to this directory.
specs: [
'spec/**/*.feature'
],
capabilities: {
'browserName': 'chrome',
'version': 'ANY'
},
baseUrl: 'http://' + (process.env.HTTP_HOST || 'localhost') + ':' + (process.env.HTTP_PORT || webServerDefaultPort),
cucumberOpts: {
require: 'spec/**/*.js',
tags: '@dev',
format: undefined,
profile: false,
'no-source': true
}
};
login.feature
Feature: Login
@dev
Scenario: Login funtion
Given go login page "http://localhost:8080/#/login"
Then input userName "username", password "password"
Then click login
Then see About page "http://localhost:8080/#/home"
loginSpec.ts
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var HttpBackend = require('http-backend-proxy');
var proxy = new HttpBackend(browser);
module.exports = function loginPage() {
var expect = chai.expect;
this.setDefaultTimeout(500 * 1000);
this.Given(/^go login page "([^"]*)"$/, function (url, next) {
browser.driver.get(url);
next();
});
this.Then(/^input userName "([^"]*)", password "([^"]*)"$/, function (userName, password, next) {
browser.driver.findElement(by.id('userName')).sendKeys(userName);
browser.driver.findElement(by.id('pass')).sendKeys(password);
next();
});
this.Then(/^click login$/, function (next) {
proxy.whenGET('http://localhost:3000/login').respond(function(method, url) {
return [200, {"data": "test"}];
});
browser.driver.findElement(by.id('login')).click();
next();
});
this.Then(/^see About page "([^"]*)"$/, function (url, next) {
expect(browser.getLocationAbsUrl()).to.equal(url);
next();
});
};
我的問題是:
1.有時用戶名和密碼不能輸入到元素中,但解析仍然是通過。我不知道爲什麼。
2.我想用'http-backend-proxy'
模擬數據而不發送請求到服務器,但它不起作用,錯誤是angular is not defined
。發送請求時如何模擬數據?
請幫助我,謝謝。關於1
你有沒有發現任何這個決議?請用答案更新你的問題。 –