用摩托马和咖啡脚本测试UI测试



我正在设置测试案例环境,并在开始使用selenium webdriver的Node.js

我已经安装了所有依赖项,但仍无法运行上述博客中给出的样本测试案例:

selenium = require 'selenium-webdriver'
chai = require 'chai'
chai.use require 'chai-as-promised'
expect = chai.expect
before ->
    @timeout 10000
@driver = new selenium.Builder()
    .withCapabilities(selenium.Capabilities.chrome())
    .build()
@driver.getWindowHandle()
after ->
    @driver.quit()
describe 'Webdriver tutorial', ->
beforeEach ->
    @driver.get 'http://bites.goodeggs.com/posts/selenium-webdriver-nodejs-tutorial/'
it 'has the title of the post in the window's title', ->
expect(@driver.getTitle()).to.eventually.contain
'Getting started with Selenium Webdriver for node.js'
it 'has publication date', ->
text = @driver.findElement(css: '.post .meta time').getText()
expect(text).to.eventually.equal 'December 30th, 2014'
it 'links back to the homepage', ->
@driver.findElement(linkText: 'Bites').click()
expect(@driver.getCurrentUrl()).to.eventually.equal 'http://bites.goodeggs.com/'

在测试用例上方运行:

mocha JavaScript_test.coffee  --compilers coffee:coffee-script/register

我有以下错误:

module.js:471
    throw err;
    ^
Error: Cannot find module 'coffee-script/register'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at /usr/local/lib/node_modules/mocha/bin/_mocha:337:3
    at Array.forEach (native)
    at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:329:19)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

我遇到了同样的问题,我不知道它何时会改变,但是模块咖啡不再存在。正确的软件包是 Coffeescript ,因此正确的命令是:

mocha JavaScript_test.coffee  --compilers coffee:coffeescript/register

但是 - 兼容者被弃用,因此新的正确语法是:

mocha JavaScript_test.coffee  --require coffeescript/register

相关内容

最新更新