Created
May 15, 2018 20:31
-
-
Save spectrox/8d3535b401eed55f24bdea86e2c7f427 to your computer and use it in GitHub Desktop.
Selenium Hub + Selenium Chrome + Selenium Firefox + Node WebDriver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hub: | |
image: selenium/hub | |
ports: | |
- 4444:4444 | |
chrome: | |
image: selenium/node-chrome-debug | |
links: | |
- hub:hub | |
ports: | |
- 5900:5900 | |
volumes: | |
- /dev/shm:/dev/shm | |
firefox: | |
image: selenium/node-firefox | |
environment: | |
HUB_PORT_4444_TCP_ADDR: hub | |
links: | |
- hub:hub | |
selenium: | |
image: "node:10.1" | |
user: "node" | |
working_dir: /home/node/app | |
links: | |
- hub:hub | |
environment: | |
- NODE_ENV=production | |
- NODE_PATH=/home/node/app/node_modules/ | |
volumes: | |
- ./:/home/node/app:rw | |
expose: | |
- "8081" | |
command: "npm start" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "foo", | |
"dependencies": { | |
"selenium-webdriver": "3.6" | |
}, | |
"scripts": { | |
"start": "npm i && sleep infinity" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var webdriver = require("selenium-webdriver"); | |
var driver = new webdriver.Builder() | |
.usingServer("http://hub:4444/wd/hub") | |
.forBrowser('chrome') | |
.build(); | |
function checkTitle() { | |
driver | |
.getTitle() | |
.then(function (title) { | |
console.log("The title is: " + title); | |
}); | |
return webdriver.until.titleIs('Google'); | |
} | |
function handleFailure(err) { | |
console.error('Something went wrong!\n', err.stack, '\n'); | |
quitDriver(); | |
} | |
function quitDriver() { | |
console.log("WebDriver is about to close."); | |
driver.close(); | |
} | |
driver.get('https://google.com'); | |
driver.wait(checkTitle, 1000).then(quitDriver, handleFailure); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment