提交 b2fd5d1b 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

compatible phantomjs-prebult executable path

上级 a84cc666
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Wechaty [![Circle CI](https://circleci.com/gh/zixia/wechaty.svg?style=svg)](https://circleci.com/gh/zixia/wechaty) # Wechaty [![Circle CI](https://circleci.com/gh/zixia/wechaty.svg?style=svg)](https://circleci.com/gh/zixia/wechaty)
Wechaty is Wechat for Bot. Wechaty is Wechat for Bot.
It's a library/framework for easy creating wechat bot in 10 lines of code. > Easy creating wechat robot code in 10 lines.
[![Join the chat at https://gitter.im/zixia/wechaty](https://badges.gitter.im/zixia/wechaty.svg)](https://gitter.im/zixia/wechaty?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Join the chat at https://gitter.im/zixia/wechaty](https://badges.gitter.im/zixia/wechaty.svg)](https://gitter.im/zixia/wechaty?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![npm version](https://badge.fury.io/js/wechaty.svg)](https://badge.fury.io/js/wechaty) [![npm version](https://badge.fury.io/js/wechaty.svg)](https://badge.fury.io/js/wechaty)
......
...@@ -4,3 +4,10 @@ machine: ...@@ -4,3 +4,10 @@ machine:
dependencies: dependencies:
post: post:
notify:
webhooks:
# A list of hook hashes, containing the url field
# gitter hook
- url: https://webhooks.gitter.im/e/537e61e880e78bc0b271
...@@ -36,22 +36,40 @@ class Browser { ...@@ -36,22 +36,40 @@ class Browser {
const WX_URL = 'https://wx.qq.com' const WX_URL = 'https://wx.qq.com'
log.verbose('Browser', `init ${this.browser}:${this.port}`) log.verbose('Browser', `init ${this.browser}:${this.port}`)
this.driver = new WebDriver.Builder().forBrowser(this.browser).build() this.driver = this.getDriver()
/*
this.driver = new WebDriver.Builder()//.forBrowser(this.browser).build()
.withCapabilities(
WebDriver.Capabilities.phantomjs()
.set('phantomjs.binary.path', 'D:\\cygwin64\\home\\zixia\\git\\wechaty\\node_modules\\phantomjs-prebuilt\\lib\\phantom\\bin\\phantomjs.exe')
).build()
*/
return this.driver.get(WX_URL) return this.driver.get(WX_URL)
} }
getInjectio() { getDriver() {
return fs.readFileSync( var driver
path.join(path.dirname(__filename), 'puppet-web-injectio.js') switch(this.browser) {
case 'phantomjs':
driver = getPhantomJsPreBuilt()
break
default:
driver = new WebDriver.Builder().forBrowser(this.browser).build()
break
}
return driver
function getPhantomJsPreBuilt() {
// https://github.com/SeleniumHQ/selenium/issues/2069
//setup custom phantomJS capability
const phantomjs_exe = require('phantomjs-prebuilt').path
var customPhantom = selenium.Capabilities.phantomjs()
.set("phantomjs.binary.path", phantomjs_exe)
//build custom phantomJS driver
return new selenium.Builder()
.withCapabilities(customPhantom)
.build()
}
}
getInjectio() {
return fs.readFileSync(
path.join(path.dirname(__filename), 'puppet-web-injectio.js')
, 'utf8' , 'utf8'
) )
} }
...@@ -72,16 +90,16 @@ class Browser { ...@@ -72,16 +90,16 @@ class Browser {
}) })
} }
quit() { quit() {
log.verbose('Browser', 'Browser.quit') log.verbose('Browser', 'Browser.quit')
if (!this.driver) { if (!this.driver) {
log.verbose('Browser', 'no need to quite because no driver') log.verbose('Browser', 'no need to quite because no driver')
return new Promise((resolve, reject) => resolve('no driver')) return new Promise((resolve, reject) => resolve('no driver'))
} }
log.verbose('Browser', 'Browser.driver.quit') log.verbose('Browser', 'Browser.driver.quit')
return this.execute('return (typeof Wechaty)!=="undefined" && Wechaty.quit()').then(() => { return this.execute('return (typeof Wechaty)!=="undefined" && Wechaty.quit()').then(() => {
this.driver.quit() this.driver.quit()
this.driver = null this.driver = null
return new Promise((resolve, reject) => resolve()) return new Promise((resolve, reject) => resolve())
}) })
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册