Skip to content

Instantly share code, notes, and snippets.

@hugs
Last active October 4, 2018 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugs/9156094 to your computer and use it in GitHub Desktop.
Save hugs/9156094 to your computer and use it in GitHub Desktop.
A simple Node.js script that uses synchronous APIs for automated testing with Selenium WebDriver. Yes, I said "synchronous". Deal with it -- 'cause it's awesome.
var WebDriver = require('webdriver-http-sync');
var sleep = require('teddybear');
driver = new WebDriver('http://localhost:4444/wd/hub', {browserName:"firefox"});
// Look, no callbacks!
driver.navigateTo('http://pinthing.com');
// Oh my, I need a break. I can't handle the awesome.
sleep(5000);
driver.close();
// It's time to bring some sanity back to the world. Stop the async madness!
// Here's a simple Node.js script that uses synchronous APIs to
// do some notoriously asynchronous things -- like opening a web page or sleeping.
// Props to Sean Massa (@endangeredmassa) and Groupon for making webdriver-http-sync and
// Andreas Madsen (@andreas_madsen) for making teddybear.
// This assumes you're running Selenium Server in a separate window:
// In terminal 1:
// $ java -jar bin/selenium-server-standalone-2.39.0.jar
// To run this script:
// In terminal 2:
// $ node sync-is-great-for-testing.js
// License: MIT
// Links:
// teddybear:
// https://github.com/AndreasMadsen/teddybear
// (MIT License)
// webdriver-http-sync:
// https://github.com/groupon/webdriver-http-sync/
// (BSD license)
@mattfysh
Copy link

@hugs how does this play out when you then need to wait asynchronously for some condition (e.g. ajax content to be rendered)

@SriSatyaKalyan
Copy link

How to use this when we want to wait for an alert where we are using JavaScriptExecutor to get the text on the alert?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment