【问题标题】:How to use the intern testing framework for functional testing on dynamically generated server content如何使用实习生测试框架对动态生成的服务器内容进行功能测试
【发布时间】: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


    【解决方案1】:

    在远程调用get 只需加载提供的任何 URL,就像 Web 浏览器一样。这里的问题是您使用require.toUrl 来引用PHP 文件。这将加载 src/index.php 相对于测试文件本身。测试文件和其他与 Intern 相关的资产是通过 Intern 的测试服务器(称为“代理”)加载的,该服务器不处理 PHP,因此浏览器最终会得到 index.php 的原始内容。

    要测试 PHP 应用程序,您需要为 get 调用提供支持 PHP 的服务器的 URL。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      • 2015-06-18
      • 1970-01-01
      • 2014-05-21
      • 2016-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多