asdfsdf
This commit is contained in:
@@ -2,6 +2,7 @@ const logger = require("logops")
|
||||
, { By, until } = require('selenium-webdriver')
|
||||
, captcha = require('../component/CaptchaComp')
|
||||
, poolingService = require('../service/PoolingService')
|
||||
, navigateService = require('../service/NavigateService')
|
||||
|
||||
|
||||
class SeleniumBrowser {
|
||||
@@ -10,6 +11,10 @@ class SeleniumBrowser {
|
||||
this.pool = poolingService.pool
|
||||
}
|
||||
|
||||
navigate(params) {
|
||||
return navigateService.rowing(params)
|
||||
}
|
||||
|
||||
async request(params) {
|
||||
let uri = params.uri
|
||||
logger.info('URL %s', uri)
|
||||
|
||||
@@ -9,7 +9,7 @@ class HeadlessService {
|
||||
}
|
||||
|
||||
get(params) {
|
||||
return browser.request(params)
|
||||
return params.hasOwnProperty('sessionId') ? browser.navigate(params) : browser.request(params)
|
||||
}
|
||||
|
||||
close() {
|
||||
|
||||
60
src/service/NavigateService.js
Normal file
60
src/service/NavigateService.js
Normal file
@@ -0,0 +1,60 @@
|
||||
const logger = require("logops")
|
||||
, { Builder, Capabilities, WebDriver, By } = require('selenium-webdriver')
|
||||
, _http = require('selenium-webdriver/http')
|
||||
, { Options } = require('selenium-webdriver/chrome');
|
||||
|
||||
|
||||
class NavigateService {
|
||||
constructor() {
|
||||
this.config = {
|
||||
browser: 'chrome',
|
||||
hub: 'http://spiduler-chrome:4444/wd/hub',
|
||||
browserArgs: ['--no-sandbox', '--headless', '--disable-dev-shm-usage']
|
||||
}
|
||||
}
|
||||
|
||||
rowing(params) {
|
||||
return this[params.anchor](params)
|
||||
}
|
||||
|
||||
login(params) {
|
||||
this._getDriver(params.sessionId).then(driver => {
|
||||
driver.get(params.uri).then(() => {
|
||||
let username = driver.findElement(By.name(param.name.username))
|
||||
let password = driver.findElement(By.name(param.name.password))
|
||||
// let username = driver.findElement(By.xpath(param.xpath.username))
|
||||
// let password = driver.findElement(By.xpath(param.xpath.password))
|
||||
let submit = driver.findElement(By.xpath(param.xpath.submit))
|
||||
username.sendKeys(params.key.username)
|
||||
password.sendKeys(params.key.password)
|
||||
return submit.click()
|
||||
//*[@id="container_sub"]/div[2]/table/tbody/tr/td[1]/table/tbody/tr[2]/td/table/tbody/tr[1]/td[3]/input
|
||||
}).then(signed => {
|
||||
return { currentUrl: driver.getCurrentUrl(), sessionId: driver.getSession() }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
_getDriver(params) {
|
||||
return params.sessionId ? this.getDriverExists(params) : this.getNewDriver()
|
||||
}
|
||||
|
||||
_getDriverBySessionId(params) {
|
||||
return new WebDriver(params.sessionId, new _http.Executor(Promise.resolve(this.config.hub)
|
||||
.then(url => new _http.HttpClient(url, null, null))))
|
||||
}
|
||||
|
||||
_getNewDriver() {
|
||||
let capabilities = Capabilities.chrome()
|
||||
let opts = new Options;
|
||||
opts.addArguments(this.config.browserArgs)
|
||||
return new Builder()
|
||||
.usingServer(this.config.hub)
|
||||
.withCapabilities(capabilities)
|
||||
.forBrowser(this.config.browser)
|
||||
.setChromeOptions(opts)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new NavigateService
|
||||
@@ -1,6 +1,7 @@
|
||||
const logger = require("logops")
|
||||
, config = require('../../config')
|
||||
, { Builder, Capabilities } = require('selenium-webdriver')
|
||||
, { Builder, Capabilities, WebDriver } = require('selenium-webdriver')
|
||||
, _http = require('selenium-webdriver/http')
|
||||
, pool = require('generic-pool')
|
||||
, { Options } = require('selenium-webdriver/chrome');
|
||||
|
||||
@@ -26,10 +27,10 @@ class PoolingService {
|
||||
validate: (driver) => this.validate(driver)
|
||||
}, this.config.pool);
|
||||
genericPool.on("factoryCreateError", function (err) {
|
||||
logger.debug({reason: err.message}, 'factoryCreateError');
|
||||
logger.debug({ reason: err.message }, 'factoryCreateError');
|
||||
});
|
||||
genericPool.on("factoryDestroyError", function (err) {
|
||||
logger.debug({reason: err.message}, 'factoryDestroyError');
|
||||
logger.debug({ reason: err.message }, 'factoryDestroyError');
|
||||
});
|
||||
return genericPool
|
||||
}
|
||||
@@ -57,6 +58,11 @@ class PoolingService {
|
||||
})
|
||||
}
|
||||
|
||||
getDriverBySessionId(sessionId) {
|
||||
new WebDriver(sessionId, new _http.Executor(Promise.resolve(url)
|
||||
.then(url => new _http.HttpClient(url, null, null))))
|
||||
}
|
||||
|
||||
getDriver() {
|
||||
let opts = new Options;
|
||||
let capabilities = Capabilities.chrome()
|
||||
|
||||
Reference in New Issue
Block a user