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

issue #21 switch back to phantomjs, and headless & head will all be tested

上级 e82be8c8
{
"name": "wechaty",
"version": "0.3.15",
"version": "0.3.16",
"description": "Wechat for Bot (Personal Account)",
"main": "index.js",
"wechaty": {
"DEFAULT_HEAD": "chrome",
"DEFAULT_HEAD": "phantomjs",
"DEFAULT_PUPPET": "web",
"DEFAULT_PROFILE": "default-profile-name",
"DEFAULT_PORT": 18788,
......@@ -16,11 +16,13 @@
"eslint": "eslint \"{src,test}/**/*.js\"",
"tslint": "tslint \"{src,test}/**/*.ts\"",
"pretest": "npm run lint",
"test": "npm run test:phantomjs && npm run test:chrome",
"test:phantomjs": "cross-env LC_ALL=C WECHATY_LOG=info WECHATY_HEAD=phantomjs ava --timeout=10m \"{src,test}/**/*.spec.js\"",
"test:chrome": "cross-env LC_ALL=C WECHATY_LOG=info WECHATY_HEAD=chrome ava --timeout=10m \"{src,test}/**/*.spec.js\"",
"testdev": "cross-env LC_ALL=C WECHATY_LOG=silly ava --serial --verbose --fail-fast --timeout=3m"
"ava": "cross-env LC_ALL=C WECHATY_LOG=verbose ava \"{src,test}/**/*.spec.js\"",
"start": "node bin/io-bot",
"demo": "node example/ding-dong-bot.js",
"test": "cross-env LC_ALL=C WECHATY_LOG=info ava --timeout=10m \"{src,test}/**/*.spec.js\"",
"ava": "cross-env LC_ALL=C WECHATY_LOG=verbose ava \"{src,test}/**/*.spec.js\"",
"testdev": "cross-env LC_ALL=C WECHATY_LOG=silly ava --serial --verbose --fail-fast --timeout=3m"
},
"repository": {
"type": "git",
......
const Config = {
isDocker: !!process.env.WECHATY_DOCKER
}
const Config = require('../package.json').wechaty
Object.assign(Config, require('../package.json').wechaty)
Object.assign(Config, {
isDocker: !!process.env.WECHATY_DOCKER
, head: process.env.WECHATY_HEAD || Config.DEFAULT_HEAD
})
module.exports = Config.default = Config.Config = Config
......@@ -38,7 +38,7 @@ const Config = require('../config')
class PuppetWeb extends Puppet {
constructor({
head = Config.DEFAULT_HEAD
head = Config.head
, profile = null // if not set profile, then do not store session.
} = {}) {
super()
......
......@@ -23,6 +23,11 @@ test('Puppet Web Self Message Identification', t => {
t.truthy(p.self(m), 'should identified self for message which from is self')
})
/**
* the reason why use `test.serial` here is:
* static variable `Contact.puppet` will be changed
* when `PuppteWeb.init()` and `PuppteWeb.quit()`
*/
test.serial('PuppetWeb login/logout events', async t => {
let pw = new PuppetWeb()
t.truthy(pw, 'should instantiated a PuppetWeb')
......
......@@ -3,38 +3,38 @@ import express from 'express'
import * as http from 'http'
import * as url from 'url'
import Phantomjs from 'phantomjs-prebuilt'
import { test } from 'ava'
import { UtilLib, log } from '../'
test('Phantomjs smoking test', t => {
const phantomjsExe = require('phantomjs-prebuilt').path
test.todo('Phantomjs replace javascript source file content test', async t => {
const phantomjsArgs = [
'--load-images=false'
, '--ignore-ssl-errors=true' // this help socket.io connect with localhost
, '--web-security=false' // https://github.com/ariya/phantomjs/issues/12440#issuecomment-52155299
, '--ssl-protocol=TLSv1' // https://github.com/ariya/phantomjs/issues/11239#issuecomment-42362211
, '--webdriver-loglevel=WARN'
// , '--webdriver-loglevel=DEBUG'
// , '--webdriver-logfile=webdriver.debug.log'
// , '--remote-debugger-port=8080'
]
phantomjsArgs.push('--remote-debugger-port=8080') // XXX: be careful when in production env.
phantomjsArgs.push('--webdriver-loglevel=DEBUG')
// phantomjsArgs.push('--webdriver-logfile=webdriver.debug.log')
const customPhantom = WebDriver.Capabilities.phantomjs()
.setAlertBehavior('ignore')
.set('phantomjs.binary.path', phantomjsExe)
.set('phantomjs.cli.args', phantomjsArgs)
.set('phantomjs.page.settings.userAgent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0')
// .setAlertBehavior('ignore')
.set('phantomjs.binary.path', Phantomjs.path)
.set('phantomjs.cli.args', phantomjsArgs)
const driver = new WebDriver.Builder()
.withCapabilities(customPhantom)
.build()
.withCapabilities(customPhantom)
.build()
// http://stackoverflow.com/questions/24834403/phantomjs-change-webpage-content-before-evaluating
driver.executePhantomJS(`
this.onResourceRequested = function(request, net) {
console.log('REQUEST ' + request.url);
alert('REQUEST ' + request.url);
// blockRe = /wx\.qq\.com\/\?t=v2\/fake/i
// https://res.wx.qq.com/zh_CN/htmledition/v2/js/webwxApp2fd632.js
var webwxAppRe = /res\.wx\.qq\.com\/zh_CN\/htmledition\/v2\/js\/webwxApp.+\.js$/i
......@@ -70,7 +70,8 @@ this.onResourceRequested = function(request, net) {
}
}
`)
driver.get('https://wx.qq.com')
await driver.get('https://wx.qq.com')
// console.log(await driver.getTitle())
// t.end()
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册