如何使用实习生测试框架对动态生成的服务器内容进行功能测试
How to use the intern testing framework for functional testing on dynamically generated server content
我是 Intern 框架的新手,正在尝试了解如何对服务器生成的代码执行功能测试。实习生文档前面说这是可能的,但没有提供更多解释。我不知道如何设置项目,以便在实习生测试 运行 加载我的页面时执行我的 php 代码。
我有推荐的实习生文件结构,src 目录中有两个文件:test.php 和 test.html。如果我 运行 使用 test-运行ner 在 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
。测试文件和其他与实习生相关的资产是通过实习生的测试服务器(称为其 "proxy")加载的,该服务器不处理 PHP,因此浏览器将以 index.php
.
要测试 PHP 应用程序,您需要对支持 PHP.
的服务器进行 get
调用 URL
我是 Intern 框架的新手,正在尝试了解如何对服务器生成的代码执行功能测试。实习生文档前面说这是可能的,但没有提供更多解释。我不知道如何设置项目,以便在实习生测试 运行 加载我的页面时执行我的 php 代码。
我有推荐的实习生文件结构,src 目录中有两个文件:test.php 和 test.html。如果我 运行 使用 test-运行ner 在 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
。测试文件和其他与实习生相关的资产是通过实习生的测试服务器(称为其 "proxy")加载的,该服务器不处理 PHP,因此浏览器将以 index.php
.
要测试 PHP 应用程序,您需要对支持 PHP.
的服务器进行get
调用 URL