页面UI测试

    配置

    1. Usage: torch [options]
    2. Options:
    3. -h, --help output usage information
    4. -V, --version output the version number
    5. -C, --no-colors force disabling of colors
    6. -O, --reporter-options <k=v,k2=v2,...> reporter-specific options
    7. -R, --reporter <name> specify the reporter to use
    8. -S, --sort sort test files
    9. -b, --bail bail after first test failure
    10. -g, --grep <pattern> only run tests matching <pattern>
    11. -f, --fgrep <string> only run tests containing <string>
    12. -i, --invert inverts --grep and --fgrep matches
    13. -r, --require <name> require the given module
    14. -s, --slow <ms> "slow" test threshold in milliseconds [75]
    15. -t, --timeout <ms> set test-case timeout in milliseconds [2000]
    16. -u, --ui <name> specify user-interface (bdd|tdd|exports)
    17. --check-leaks check for global variable leaks
    18. --compile compile with babel
    19. --compilers <ext>:<module>,... use the given module(s) to compile files
    20. --coverage report coverage
    21. --debug enable Electron debugger on port [5858]; for --renderer tests show window and dev-tools
    22. --globals <names> allow the given comma-delimited global [names]
    23. --inline-diffs display actual/expected differences inline within each string
    24. --interactive run tests in renderer process in a visible window that can be reloaded to re-run tests
    25. --interfaces display available interfaces
    26. --no-timeouts disables timeouts
    27. --notify-on-fail notify on failures
    28. --notify-on-success notify on success
    29. --opts <path> specify opts path
    30. --preload <name> preload the given script in renderer process
    31. --recursive include sub directories
    32. --renderer run tests in renderer process
    33. --require-main <name> load the given script in main process before executing tests
    34. --source-pattern <sources> glob pattern of source files
    35. --watch watching source file changes
    36. --watch-aggregate-timeout delay time for re-run test cases after files changed


    使用 UITest

    用法

    页面UI测试 - 图1

    直接引入 uitest-mocha-shim.js 文件即可在浏览器中运行。

    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <title>macaca mocha test</title>
    5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <link rel="stylesheet" href="./node_modules/mocha/mocha.css" />
    8. </head>
    9. <body>
    10. <script src="./node_modules/mocha/mocha.js"></script>
    11. <script src="./node_modules/should/should.js"></script>
    12. <script>
    13. _macaca_uitest.setup({
    14. ui: 'bdd',
    15. timeout: 5000,
    16. slow: 2000
    17. });
    18. </script>
    19. <script>
    20. describe('sample', function() {
    21. beforeEach('init', function() {
    22. });
    23. it('#case_1', function() {
    24. });
    25. });
    26. </script>
    27. <script>
    28. _macaca_uitest.run();
    29. </script>
    30. </body>

    在命令行里运行

    Gulp

    也可以通过 Gulp 引入:

    1. $ npm i gulp-uitest --save-dev