在使用 chai 的 webdriver 時出現了一點問題,其 demo code 如下,基本上同官方網站:
然而在執行的時候出現這個問題:
後來在 stackoverflow 找到了這個解法,還蠻有用的:
http://stackoverflow.com/questions/27733731/passing-requirechromedriver-path-directly-to-selenium-webdriver
修改結果如下:
FYI.
// test/index.js
var sw = require('selenium-webdriver');
var chai = require('chai');
var chaiWebdriver = require('chai-webdriver');
// Start with a webdriver instance:
var driver = new sw.Builder()
.withCapabilities(sw.Capabilities.chrome())
.build();
// And then...
chai.use(chaiWebdriver(driver));
// And you're good to go!
driver.get('http://github.com');
chai
.expect('#site-container h1.heading')
.dom.to.not.contain.text("I'm a kitty!");
var sw = require('selenium-webdriver');
var chai = require('chai');
var chaiWebdriver = require('chai-webdriver');
// Start with a webdriver instance:
var driver = new sw.Builder()
.withCapabilities(sw.Capabilities.chrome())
.build();
// And then...
chai.use(chaiWebdriver(driver));
// And you're good to go!
driver.get('http://github.com');
chai
.expect('#site-container h1.heading')
.dom.to.not.contain.text("I'm a kitty!");
然而在執行的時候出現這個問題:
node test/index.js
XXXX/node_modules/selenium-webdriver/chrome.js:54
'http://chromedriver.storage.googleapis.com/index.html and ensure ' +
^
Error: The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver from http://chromedriver.storage.googleapis.com/index.html and ensure it can be found on your PATH.
at Error (native)
而且其實我的 chromeDriver 已經是最新版了...XXXX/node_modules/selenium-webdriver/chrome.js:54
'http://chromedriver.storage.googleapis.com/index.html and ensure ' +
^
Error: The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver from http://chromedriver.storage.googleapis.com/index.html and ensure it can be found on your PATH.
at Error (native)
後來在 stackoverflow 找到了這個解法,還蠻有用的:
http://stackoverflow.com/questions/27733731/passing-requirechromedriver-path-directly-to-selenium-webdriver
修改結果如下:
var sw = require('selenium-webdriver');
var chai = require('chai');
var chaiWebdriver = require('chai-webdriver');
// Start with a webdriver instance:
var chrome = require('selenium-webdriver/chrome');
var path = require('chromedriver').path;
var service = new chrome.ServiceBuilder(path).build();
chrome.setDefaultService(service);
var driver = new sw.Builder()
.withCapabilities(sw.Capabilities.chrome())
.build();
// And then...
chai.use(chaiWebdriver(driver));
// And you're good to go!
driver.get('http://github.com');
chai
.expect('#site-container h1.heading')
.dom.to.not.contain.text("I'm a kitty!");
var chai = require('chai');
var chaiWebdriver = require('chai-webdriver');
// Start with a webdriver instance:
var chrome = require('selenium-webdriver/chrome');
var path = require('chromedriver').path;
var service = new chrome.ServiceBuilder(path).build();
chrome.setDefaultService(service);
var driver = new sw.Builder()
.withCapabilities(sw.Capabilities.chrome())
.build();
// And then...
chai.use(chaiWebdriver(driver));
// And you're good to go!
driver.get('http://github.com');
chai
.expect('#site-container h1.heading')
.dom.to.not.contain.text("I'm a kitty!");
FYI.
附上我的 package.json 的 dev
回覆刪除"devDependencies": {
"chai": "^1.10.0",
"chai-webdriver": "^1.1.1",
"chromedriver": "^2.16.0",
"mocha": "^2.2.5",
},