我是Intern框架的新手,正在尝试了解如何对服务器生成的代码执行功能测试。实习生文档前面说过这是可能的,但是对此没有提供更多解释。我不知道如何设置项目,以便当内部测试运行器加载我的页面时执行我的php代码。
我有推荐的实习生文件结构,在src目录中有两个文件:test.php和test.html。如果我使用test-runner在test.html上运行功能测试,它就可以通过;但是,如果我针对test.php运行它,则浏览器只会下载该文件而导致测试失败。
我的实习生配置文件:
// tests/intern.js
define({
capabilities: {
'browserstack.selenium_version': '2.45.0'
},
// Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service
maxConcurrency: 2,
tunnel: 'NullTunnel',
environments: [ { browserName: 'chrome' } ],
loaderOptions: {
// Packages that should be registered with the loader in each testing environment
packages: [ { name: 'myPackage', location: '.' } ]
},
// Functional test suite(s) to execute against each browser once non-functional tests are completed
functionalSuites: [ 'tests/functional/index.js' ],
// A regular expression matching URLs to files that should not be included in code coverage analysis
excludeInstrumentation: /^(?:tests|node_modules)\//
});
我的功能测试:
// tests/functional/index.js
define(function (require) {
var registerSuite = require('intern!object');
var assert = require('intern/chai!assert');
registerSuite({
name: 'index',
'get Header': function () {
return this.remote
.get(require.toUrl('src/index.php'))
.setFindTimeout(5000)
.findByTagName('h1')
.setFindTimeout(5000)
.getVisibleText()
.then(function(text) {
assert.equal(text, "Home",
'calling getHeader for home page should return Home');
});
}
});
});
我的PHP页面:
// src/test.php
<?php
// do php stuff
if (isset($_GET["returnJson"])) {
// return php stuff
} else {
?>
<!DOCTYPE html>
<!--[if lte IE 8]> <html class="lte-ie8"> <![endif]-->
<!--[if IE 9]> <html class="lte-ie9"> <![endif]-->
<!--[if gt IE 9]><!--> <html> <!--<![endif]-->
<head></head>
<body>
<h1>Home</h1>
</body>
</html>
}
我的HTML页面:
// src/test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Intern And Server Generated Content</title>
</head>
<body>
<h1>Home</h1>
</body>
</html>
制作get
上无论是提供URL的远程加载简单的通话,就像一个网页浏览器会。这里的问题是您require.toUrl
用来引用PHP文件。这src/index.php
相对于测试文件本身加载。测试文件和其他与Intern相关的资产是通过Intern的测试服务器(称为“代理”)加载的,该服务器不处理PHP,因此浏览器最终只会显示的原始内容index.php
。
要测试PHP应用程序,您需要给get
调用提供支持PHP的服务器的URL。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句