0

我想做的是在我的机器上运行小型单元测试。我已将所有必需的节点包和 phantomjs 驱动程序安装到我的 PATH 中。

var sw = require('selenium-webdriver');
var driver = new sw.Builder()
.withCapabilities(sw.Capabilities.phantomjs())
.build()

var chai = require('chai');
var chaiWebdriver = require('chai-webdriver');
chai.use(chaiWebdriver(driver));

driver.get("https://www.npmjs.org/package/chai-webdriver");
setTimeout(function(){
    chai.expect('#content').dom.to.be.visible().then(function(){
        console.log("content visible");
    });
driver.quit();
},3000);

运行上面的代码,

 node fileName.js

给我这样的结果。

 /Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/webdriver/promise.js:1643
  throw error;
        ^
Error: Selector #content matches nothing
at /Users/r558268/Documents/sandbox/node_modules/chai-webdriver/node_modules/webdriver-sizzle/lib/webdriver_sizzle.js:17:13
at /Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/goog/base.js:1243:15
at webdriver.promise.ControlFlow.runInNewFrame_ (/Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/webdriver/promise.js:1539:20)
at notify (/Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/webdriver/promise.js:362:12)
at notifyAll (/Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/webdriver/promise.js:331:7)
at resolve (/Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/webdriver/promise.js:309:7)
at reject (/Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/webdriver/promise.js:439:5)
at /Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/goog/base.js:1243:15
at webdriver.promise.ControlFlow.runInNewFrame_ (/Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/webdriver/promise.js:1539:20)
at notify (/Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/webdriver/promise.js:362:12)
==== async task ====
WebDriver.call(function)
at webdriver.WebDriver.call (/Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:517:15)
at webdriver.WebDriver.findElementInternal_ (/Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:728:15)
at webdriver.WebDriver.findElement (/Users/r558268/Documents/sandbox/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:706:17)
at one (/Users/r558268/Documents/sandbox/node_modules/chai-webdriver/node_modules/webdriver-sizzle/lib/webdriver_sizzle.js:15:22)
at /Users/r558268/Documents/sandbox/node_modules/chai-webdriver/lib/index.js:58:18
at Assertion.<anonymous> (/Users/r558268/Documents/sandbox/node_modules/chai-webdriver/lib/index.js:72:16)
at Assertion.ctx.(anonymous function) [as visible] (/Users/r558268/Documents/sandbox/node_modules/chai/lib/chai/utils/addMethod.js:40:25)
at null._onTimeout (/Users/r558268/Documents/sandbox/assertionExample.js:30:43)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

现在事情就是这样.. 如果我将 url npmjs.org/chai-webdriver保存到我的机器上并运行相同的测试,那么它会通过而没有任何错误。

我不知道为什么..有人可以帮我解决这个问题..非常感谢!谢谢你。

4

0 回答 0