gpt4 book ai didi

javascript - 使用 Angular Scenario 测试 'any web page'

转载 作者:行者123 更新时间:2023-11-29 14:55:16 26 4
gpt4 key购买 nike

我想知道是否可以使用 Angular 场景测试器(和 karma )测试任何网页。

或者它是否设计为仅适用于 Angular 源代码?

换句话说,它是通用的还是不是“真正”与 Angular 相关的?

我正在使用 yeoman 编写一个 angularJs 应用程序,我喜欢 ngResource 完成端到端测试的方式。

我有另一个应用程序,不是用 Angular 编写的,而是在 dojo 中编写的,我想以同样的方式测试它。

您认为这是可能的吗?如果是,您对如何去做有何建议?

谢谢!

注意:实际上测试的网页中是否有一些 Angular 代码,所以这个问题是有道理的。 casperJs 或 selenium 等工具与页面中的 js 技术无关。

最佳答案

所以很容易实现。你只需要

1/安装 karma

npm install -g karma

2/安装ng-scenario 和karma-ng-scenario 的依赖

npm install ng-scenario

npm install karma-ng-scenario --save-dev

3/如果需要代理,则创建/修改 karma e2e 配置。是这样的 通常 dojo 运行在与 karma 不同的服务器上。那么你 为 karma 指定一个特定的端口,然后您代理到您的服务器。这里 是我的配置示例:

module.exports = function(config) { config.set({ // base path, that will be used to resolve files and exclude basePath: '',

// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['ng-scenario'],

// list of files / patterns to load in the browser
files: [
'https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js',
'test/e2e/**/*.js'
],

// list of files / patterns to exclude
exclude: [],

// web server port
port: 8033,

runnerPort : 9100,

// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,


// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Chrome'],


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,

// Uncomment the following lines if you are using grunt's server to run the tests
proxies: {
'/': 'http://localhost:8080/'
}, // URL root prevent conflicts with the site root
urlRoot: '_karma_' }); };
  1. 您使用端到端配置运行 karma
karma start karma-e2e.conf.js

魔术,下面的代码有效 - 测试愉快:)

describe ( 'Publications', function ()
{
beforeEach (
function ()
{
console.log ( "before each" );
browser ().navigateTo ( "yourPageToTestUrl" );
}
);

it ( 'should filter results', function ()
{
expect ( repeater ( '.Publication' ).count () ).toEqual ( 4 );
} );

} );

关于javascript - 使用 Angular Scenario 测试 'any web page',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18803188/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com