Skip to content

Instantly share code, notes, and snippets.

@hdavidzhu
hdavidzhu / 20160926-implementation.coffee
Created Sep 26, 2016
20160926-implementation.coffee
View 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 Sep 26, 2016
20160926-usage.coffee
View 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()
...
View 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.
View 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 Aug 5, 2016
Chrome Extension Setup
View 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.
View arrayToList.js
var arrayToList = function(array) {
// Base case.
if (array.length == 0) {
return null;
}
// Trasversal.
var _value = array[0];
array.shift();
View newCard.js
// 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: [],
View oldCard.js
{
cardID: 'asdf1234',
parentCardID: 'qwer3534',
childrenCardIDs: ['asdvasv', 'asvvasdv'],
speaker: 'ai',
message: 'Red or blue?'
}
@hdavidzhu
hdavidzhu / jsonExample.js
Created Mar 7, 2015
Quirk in retrieving data from JSON object.
View jsonExample.js
// This does not work.
this.getParams().roomId;
// This does work.
this.getParams()["roomId"];
You can’t perform that action at this time.