index.js 942 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const webdriverio = require('webdriverio');
  2. const chromedriver = require('chromedriver');
  3. const kill = require('tree-kill');
  4. // todo: stop works only with 9515
  5. const port = 9515;
  6. const args = [
  7. // '--url-base=/wd/hub',
  8. `--port=${port}`,
  9. ];
  10. console.log('start chromedriver');
  11. const service = chromedriver.start(args);
  12. console.log('after start')
  13. const options = {
  14. port,
  15. path: '/',
  16. desiredCapabilities: {
  17. browserName: 'chrome',
  18. chromeOptions: {
  19. args: ['--headless', '--disable-gpu'],
  20. }
  21. },
  22. };
  23. const client = webdriverio
  24. .remote(options)
  25. .init()
  26. .on('error', (e) => console.error(e))
  27. .once('end', () => {
  28. console.log('end');
  29. process.nextTick(function () {
  30. console.log('stopping');
  31. kill(service.pid);
  32. console.log('done');
  33. });
  34. })
  35. .url('https://www.google.com')
  36. .getTitle().then(function (title) {
  37. console.log('Title was: ' + title);
  38. }).catch(console.log)
  39. .end();