Skip to content

Instantly share code, notes, and snippets.

@hdavidzhu
hdavidzhu / 20160926-implementation.coffee
Created September 26, 2016 22:07
20160926-implementation.coffee
class Extension
# In this example, we have two iframes. The one built into our extension directly,
# and the one that renders our actual content.
# We would need to jump through two frames to get to our extension code, and we
# can also jump out to interact with the main webpage.
enterInnerFrame: ->
# Enter our extension-provided iframe.
@driver.wait(webdriver.until.elementLocated(css: @selectors.extensionFrame), 5000)
@hdavidzhu
hdavidzhu / 20160926-usage.coffee
Last active September 26, 2016 22:07
20160926-usage.coffee
extension = new Extension(@driver)
...
...
it 'can do some extension stuff ...', ->
extension.enterInnerFrame()
# Now we are inside of the extension! Do your assertions here.
...
# If you need to get back to your main page, just jump out.
extension.enterRootFrame()
...
@hdavidzhu
hdavidzhu / 20160926-setup.coffee
Created September 26, 2016 21:48
20160926-setup.coffee
# Load the Chrome extension and convert to base64 format.
# This is specific to how the node-selenium webdriver sets up its capabilities.
# Refer to http://stackoverflow.com/a/27278322/2204868 for more info.
data = fs.readFileSync '/tmp/location/of/extension.crx'
encodedExtension = data.toString 'base64'
capabilities =
browserName: 'chrome'
chromeOptions:
extensions: [encodedExtension] # This needs to be a base64 String array of our extensions.
@hdavidzhu
hdavidzhu / 20160926-download.coffee
Created September 26, 2016 21:48
20160926-download.coffee
child_process = require 'child_process'
# Get the Chrome Extension download path.
# A great explanation of how this works can be found here:
# http://chrome-extension-downloader.com/how-does-it-work.php
chromeExtensionId = 'lpcaedmchfhocbbapmcbpinfpgnhiddi'
downloadUrl = "https://clients2.google.com/service/update2/crx?response=redirect&prodversion=49.0&x=id%3D#{chromeExtensionId}%26installsource%3Dondemand%26uc"
# Download your extension through curl.
# You can choose where you want your extension to be. This path will be used later when building your driver.
@hdavidzhu
hdavidzhu / download.coffee
Last active August 5, 2016 17:37
Chrome Extension Setup
child_process = require 'child_process'
# Get the Chrome Extension download path.
# A great explanation of how this works can be found here:
# http://chrome-extension-downloader.com/how-does-it-work.php
chromeExtensionId = 'lpcaedmchfhocbbapmcbpinfpgnhiddi'
downloadUrl = "https://clients2.google.com/service/update2/crx?response=redirect&prodversion=49.0&x=id%3D#{chromeExtensionId}%26installsource%3Dondemand%26uc"
# Download your extension through curl.
# You can choose where you want your extension to be. This path will be used later when building your driver.
// This is the key as well as the cardID.
"id_31f6e7046976d442": {
cardID: "id_31f6e7046976d442",
// These are antiquated terms that are relics of the tree design.
// Since we are now using a directed graph, these should be called
// lastCardIDs and nextCardIDs in the future.
parentCardIDs: [],
childrenCardIDs: [],
{
cardID: 'asdf1234',
parentCardID: 'qwer3534',
childrenCardIDs: ['asdvasv', 'asvvasdv'],
speaker: 'ai',
message: 'Red or blue?'
}