-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selenium WebDriver driver.getSession() wait a long time #86
Comments
maybe cause by the latest version Selenium WebDriver ? it seems time out take place more frequently after upgrade from 3.0.0-beta-1 to 3.0.0 |
it's strange , set SELENIUM_PROMISE_MANAGER=1 have no effect on code : /**
*
* Wechaty - Wechat for Bot
*
* Connecting ChatBots
* https://github.com/wechaty/wechaty
*
*/
/* tslint:disable:variable-name */
const QrcodeTerminal = require('qrcode-terminal')
import {
Wechaty
, Config
, log
} from '../'
const welcome = `
| __ __ _ _
| \\ \\ / /__ ___| |__ __ _| |_ _ _
| \\ \\ /\\ / / _ \\/ __| '_ \\ / _\` | __| | | |
| \\ V V / __/ (__| | | | (_| | |_| |_| |
| \\_/\\_/ \\___|\\___|_| |_|\\__,_|\\__|\\__, |
| |___/
=============== Powered by Wechaty ===============
-------- https://github.com/zixia/wechaty --------
I'm a bot, my super power is talk in Wechat.
If you send me a 'ding', I will reply you a 'dong'!
__________________________________________________
Hope you like it, and you are very welcome to
upgrade me for more super powers!
Please wait... I'm trying to login in...
`
console.log(welcome)
console.log('SELENIUM_PROMISE_MANAGER:' + process.env.SELENIUM_PROMISE_MANAGER)
const bot = Wechaty.instance({ profile: Config.DEFAULT_PROFILE })
bot
.on('login' , user => {
log.info('Bot', `${user.name()} logined`)
console.log('SELENIUM_PROMISE_MANAGER:' + process.env.SELENIUM_PROMISE_MANAGER)
})
.on('logout' , user => log.info('Bot', `${user.name()} logouted`))
.on('error' , e => log.info('Bot', 'error: %s', e))
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
let loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code in above url to login: `)
})
.on('message', m => {
try {
const room = m.room()
console.log((room ? '[' + room.topic() + ']' : '')
+ '<' + m.from().name() + '>'
+ ':' + m.toStringDigest()
)
if (/^(ding|ping|bing)$/i.test(m.content()) && !m.self()) {
m.say('dong')
log.info('Bot', 'REPLY: dong')
}
} catch (e) {
log.error('Bot', 'on(message) exception: %s' , e)
}
})
bot.init()
.catch(e => {
log.error('Bot', 'init() fail: %s', e)
bot.quit()
process.exit(-1)
})
function logToFile(data) {
require('fs').appendFile('message.log', data + '\n\n#############################\n\n', err => {
if (err) { log.error('LogToFile: %s', err) }
})
}
if (typeof logToFile === 'fasdfsd') {
console.log('disable linting warning')
} run && output:
|
found it hardcode in /**
* ISSUE #72
* Introduce the SELENIUM_PROMISE_MANAGER environment variable.
* When set to 1, selenium-webdriver will use the existing ControlFlow scheduler.
* When set to 0, the SimpleScheduler will be used.
*/
process.env['SELENIUM_PROMISE_MANAGER'] = 0 will try to change it in code |
changed it in code . |
code private async getChromeDriver(): Promise<WebDriver> {
log.verbose('PuppetWebBrowserDriver', 'getChromeDriver()')
......
console.time('valid')
const valid = await this.valid(driver)
console.timeEnd('valid')
......
return driver
}
private async valid(driver: WebDriver): Promise<boolean> {
log.verbose('PuppetWebBrowserDriver', 'valid()')
try {
......
console.time('getSession')
// resolve
driver.getSession()
.then(session => {
clearTimeout(timer)
resolve(session)
})
console.timeEnd('getSession')
})
......
} outputSELENIUM_PROMISE_MANAGER:0
SELENIUM_PROMISE_MANAGER:1
it looks everything all right. |
@zixia another problem, on starting robot. opening the in my case ,the native chrome popup and qrcode show fast(immediately), but the qrcode in the terminator was show after about 26s. time trace: in codeexport class Browser extends EventEmitter {
......
public async init(): Promise<void> {
log.verbose('PuppetWebBrowser', 'init()')
......
try {
await this.driver.init()
log.verbose('PuppetWebBrowser', 'init() driver.init() done')
console.time('browser.openJumpUrl')
await this.open(jumpUrl)
console.timeEnd('browser.openJumpUrl')
await this.loadCookie()
.catch(e => { // fail safe
log.verbose('PuppetWebBrowser', 'browser.loadSession(%s) exception: %s'
, this.setting.sessionFile
, e && e.message || e
)
})
console.time('browser.open')
await this.open()
console.timeEnd('browser.open')
......
}
}
public async open(url: string = 'https://wx.qq.com'): Promise<void> {
log.verbose('PuppetWebBrowser', `open(${url})`)
try {
console.time('driver.get')
await this.driver.get(url)
console.timeEnd('driver.get')
} catch (e) {
log.error('PuppetWebBrowser', 'open() exception: %s', e.message)
throw e
}
}
......
} output (ran it several times )
only this times is fast a little
Also: performance effect on |
Thanks for the benchmark. About the |
Still experiencing this issue recently. https://travis-ci.org/Chatie/wechaty/jobs/237692304#L1626 |
This bug is still paining me time and again. |
This issue should be fixed at v0.10 or above. |
In our case, the timeout is
67
seconds:wechaty/src/puppet-web/browser-driver.ts
Line 254 in 41b29e7
Detail: https://travis-ci.org/wechaty/wechaty/jobs/175139957
I don't know why yet.
And it seems if we had an invalid WebDriver, then we will have a browser leak.
need to use
process.kill
to kill it, inclean()
.A unit test fail log like this:
The text was updated successfully, but these errors were encountered: