Last active
September 5, 2019 12:31
-
-
Save savagematt/005efb23a11328af261026ff3791bdcf to your computer and use it in GitHub Desktop.
Automate 3D secure when testing strong customer authentication flows with Stripe
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
const { Builder, By, until } = require("selenium-webdriver"); | |
const tcpPortUsed = require("tcp-port-used"); | |
const { exec } = require("child_process"); | |
process.env.SELENIUM_BROWSER = "chrome:75:LINUX"; | |
process.env.SELENIUM_REMOTE_URL = "http://localhost:4444/wd/hub"; | |
let driver = () => { | |
const result = new Builder().forBrowser("chrome").build(); | |
driver = () => result; | |
return result; | |
}; | |
module.exports.hack3dSecure = async threeDSecureUrl => { | |
const seleniumRunning = await tcpPortUsed.check(4444, "127.0.0.1"); | |
if (!seleniumRunning) { | |
await new Promise((resolve, reject) => | |
exec( | |
"docker run -d -p 4444:4444 selenium/standalone-chrome", | |
(err, stdout, stderr) => { | |
console.log(stdout); | |
console.error(stderr); | |
if (err) { | |
reject(err); | |
} else resolve(); | |
} | |
) | |
); | |
} | |
await tcpPortUsed.waitUntilUsed(4444); | |
const d = driver(); | |
await d.get(threeDSecureUrl); | |
await d.wait( | |
until.elementLocated(By.id("test-source-authorize-3ds")), | |
5 * 1000 | |
); | |
await d.findElement(By.id("test-source-authorize-3ds")).click(); | |
await d.wait(until.elementLocated(By.id("message")), 5 * 1000); | |
}; |
Author
savagematt
commented
Sep 5, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment