【发布时间】:2015-12-08 03:45:47
【问题描述】:
我是 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>
【问题讨论】:
标签: php functional-testing intern